From 3c46e51b664d7b06f8bb994c173b7c1ab5f7f8aa Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 25 Oct 2022 21:24:35 +0200 Subject: [PATCH 001/207] Updated to Java 11, converted API to module. --- de.haumacher.msgbuf.generator/.classpath | 2 +- .../org.eclipse.core.resources.prefs | 5 ++-- .../.settings/org.eclipse.jdt.core.prefs | 6 ++--- de.haumacher.msgbuf.generator/pom.xml | 6 +---- de.haumacher.msgbuf/.classpath | 8 ++++-- .../org.eclipse.core.resources.prefs | 5 ++-- .../.settings/org.eclipse.jdt.core.prefs | 8 +++--- de.haumacher.msgbuf/pom.xml | 2 +- .../src/main/java/module-info.java | 27 +++++++++++++++++++ .../src/test/java/module-info.test | 11 ++++++++ pom.xml | 18 ++++++++----- 11 files changed, 71 insertions(+), 27 deletions(-) create mode 100644 de.haumacher.msgbuf/src/main/java/module-info.java create mode 100644 de.haumacher.msgbuf/src/test/java/module-info.test diff --git a/de.haumacher.msgbuf.generator/.classpath b/de.haumacher.msgbuf.generator/.classpath index dc135e9b..22b120f8 100644 --- a/de.haumacher.msgbuf.generator/.classpath +++ b/de.haumacher.msgbuf.generator/.classpath @@ -13,7 +13,7 @@ - + diff --git a/de.haumacher.msgbuf.generator/.settings/org.eclipse.core.resources.prefs b/de.haumacher.msgbuf.generator/.settings/org.eclipse.core.resources.prefs index 5b781ec6..a05fb4b5 100644 --- a/de.haumacher.msgbuf.generator/.settings/org.eclipse.core.resources.prefs +++ b/de.haumacher.msgbuf.generator/.settings/org.eclipse.core.resources.prefs @@ -1,3 +1,4 @@ eclipse.preferences.version=1 -encoding//src/main/java=UTF-8 -encoding//src/test/java=UTF-8 +encoding//src/main/java=utf-8 +encoding//src/test/java=utf-8 +encoding/=utf-8 diff --git a/de.haumacher.msgbuf.generator/.settings/org.eclipse.jdt.core.prefs b/de.haumacher.msgbuf.generator/.settings/org.eclipse.jdt.core.prefs index 3a0745fd..2bd4e773 100644 --- a/de.haumacher.msgbuf.generator/.settings/org.eclipse.jdt.core.prefs +++ b/de.haumacher.msgbuf.generator/.settings/org.eclipse.jdt.core.prefs @@ -1,9 +1,9 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.compliance=11 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -13,4 +13,4 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=1.8 +org.eclipse.jdt.core.compiler.source=11 diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 629f3a7b..fca289a9 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -40,7 +40,7 @@ junit junit - 3.8.2 + 4.13.2 test @@ -50,10 +50,6 @@ maven-compiler-plugin 3.8.1 - - 1.8 - 1.8 - diff --git a/de.haumacher.msgbuf/.classpath b/de.haumacher.msgbuf/.classpath index a3c10cb6..e2008929 100644 --- a/de.haumacher.msgbuf/.classpath +++ b/de.haumacher.msgbuf/.classpath @@ -1,11 +1,15 @@ - + - + + + + + diff --git a/de.haumacher.msgbuf/.settings/org.eclipse.core.resources.prefs b/de.haumacher.msgbuf/.settings/org.eclipse.core.resources.prefs index ba7daf0d..a4d19936 100644 --- a/de.haumacher.msgbuf/.settings/org.eclipse.core.resources.prefs +++ b/de.haumacher.msgbuf/.settings/org.eclipse.core.resources.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 -encoding//src/main/java=UTF-8 +encoding//src/main/java=utf-8 encoding//src/main/resources=UTF-8 -encoding//src/test/java=UTF-8 +encoding//src/test/java=utf-8 +encoding/=utf-8 diff --git a/de.haumacher.msgbuf/.settings/org.eclipse.jdt.core.prefs b/de.haumacher.msgbuf/.settings/org.eclipse.jdt.core.prefs index db24ee78..ec554411 100644 --- a/de.haumacher.msgbuf/.settings/org.eclipse.jdt.core.prefs +++ b/de.haumacher.msgbuf/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,8 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.compliance=11 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -10,6 +10,6 @@ org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=1.8 +org.eclipse.jdt.core.compiler.source=11 diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index ed8a0232..1d73d8f9 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -35,7 +35,7 @@ junit junit - 3.8.2 + 4.13.2 test diff --git a/de.haumacher.msgbuf/src/main/java/module-info.java b/de.haumacher.msgbuf/src/main/java/module-info.java new file mode 100644 index 00000000..baa27070 --- /dev/null +++ b/de.haumacher.msgbuf/src/main/java/module-info.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 Bernhard Haumacher et al. All Rights Reserved. + */ +/** + * MsgBuf API module. + */ +module de.haumacher.msgbuf { + exports de.haumacher.msgbuf.data; + + exports de.haumacher.msgbuf.server.io; + + exports de.haumacher.msgbuf.util; + + exports de.haumacher.msgbuf.coder; + + exports de.haumacher.msgbuf.binary; + + exports de.haumacher.msgbuf.graph; + + exports de.haumacher.msgbuf.observer; + + exports de.haumacher.msgbuf.io; + + exports de.haumacher.msgbuf.graph.cmd; + + exports de.haumacher.msgbuf.json; +} \ No newline at end of file diff --git a/de.haumacher.msgbuf/src/test/java/module-info.test b/de.haumacher.msgbuf/src/test/java/module-info.test new file mode 100644 index 00000000..67e0a025 --- /dev/null +++ b/de.haumacher.msgbuf/src/test/java/module-info.test @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2022 Bernhard Haumacher et al. All Rights Reserved. + */ +/** + * MsgBuf API module. + */ +open module test.de.haumacher.msgbuf { + requires de.haumacher.msgbuf; + + requires junit; +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index a104cdf8..a2cbd0ab 100644 --- a/pom.xml +++ b/pom.xml @@ -48,17 +48,17 @@ + + 11 + 11 + utf-8 + + - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - UTF-8 - + 3.10.1 @@ -149,6 +149,10 @@ false + + \ No newline at end of file From 1f09864c16cfb8d3ffbde7ea2deb6dfd4f6c8105 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 25 Oct 2022 21:27:13 +0200 Subject: [PATCH 002/207] Updated version to 1.1.0-SNAPSHOT. --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index fca289a9..9eed341e 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf - 1.0.4-SNAPSHOT + 1.1.0-SNAPSHOT msgbuf-parent @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.0.4-SNAPSHOT + 1.1.0-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 1d73d8f9..73a8a3fb 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf - 1.0.4-SNAPSHOT + 1.1.0-SNAPSHOT msgbuf-parent diff --git a/pom.xml b/pom.xml index a2cbd0ab..47df9709 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.0.4-SNAPSHOT + 1.1.0-SNAPSHOT pom From 4a9412a2987c19b4ab505d9284a6e4ff13878f72 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 25 Oct 2022 21:33:38 +0200 Subject: [PATCH 003/207] Added dependency checker. --- pom.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pom.xml b/pom.xml index 47df9709..f680da32 100644 --- a/pom.xml +++ b/pom.xml @@ -150,6 +150,18 @@ + + + + org.owasp + dependency-check-maven + 7.3.0 + + ALL + true + + + From 45b340f755f7a5b8072c265b5546b6638e83d18e Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 26 Oct 2022 21:15:21 +0200 Subject: [PATCH 004/207] Fixed name of outer types in qualified names of nested types. --- .../haumacher/msgbuf/generator/CodeConvention.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java index def6867d..15041c8c 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java @@ -76,11 +76,7 @@ public static String qName(QName qName, Function localNameConven result.append('.'); } String part = names.get(n); - if (n < cnt - 1) { - result.append(part); - } else { - result.append(localNameConvention.apply(part)); - } + result.append(localNameConvention.apply(part)); } return result.toString(); } @@ -110,7 +106,7 @@ public static String binaryConstant(Field field) { } public static String constant(Field field) { - return allUpperCase(field.getName()); + return allUpperCase(field.getName()) + "__PROP"; } /** @@ -252,4 +248,9 @@ public static String classifierName(Constant constant) { return CodeUtil.allUpperCase(constant.getName()); } + /** + * Enum method that resolves an enum value from a protocol string. + */ + public static final String ENUM_VALUE_OF_PROTOCOL = "valueOfProtocol"; + } From 40798799fb2b906146d6fd44d230cf9fad9233c0 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 26 Oct 2022 21:19:29 +0200 Subject: [PATCH 005/207] Fixed type lookup. Wrong type was resolved, if multiple messages have inner types with the same name. --- .../haumacher/msgbuf/generator/NameTable.java | 46 +++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java index 11876928..3ec75c93 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; import de.haumacher.msgbuf.generator.ast.Constant; import de.haumacher.msgbuf.generator.ast.Definition; @@ -13,7 +14,6 @@ import de.haumacher.msgbuf.generator.ast.Field; import de.haumacher.msgbuf.generator.ast.MessageDef; import de.haumacher.msgbuf.generator.ast.QName; -import de.haumacher.msgbuf.generator.common.Util; /** * TODO @@ -55,7 +55,9 @@ public Void visit(MessageDef self, Void arg) { } private void enterDef(Definition def) { - _definitionByName.put(def.getName(), def); + if (def.getOuter() == null) { + _definitionByName.put(def.getName(), def); + } } private Package mkPackage(QName qName) { @@ -114,6 +116,44 @@ public void error(String message) { * TODO */ public Definition lookup(MessageDef context, QName name) { - return _definitionByName.get(Util.last(name)); + String baseName = name.getNames().get(0); + + Definition base = lookupBase(context, baseName); + for (int n = 1; n < name.getNames().size(); n++) { + String nextName = name.getNames().get(n); + Definition inner = lookupInner(base, nextName); + if (inner == null) { + System.out.println("ERROR: Name cannot be resolved in '" + base.getName() + "': " + nextName); + return null; + } + base = inner; + } + + return base; + } + + private Definition lookupInner(Definition base, String nextName) { + if (base instanceof MessageDef) { + Optional match = ((MessageDef) base).getDefinitions().stream().filter(d -> nextName.equals(d.getName())).findFirst(); + if (match.isPresent()) { + return match.get(); + } else { + return null; + } + } else { + return null; + } + } + + private Definition lookupBase(MessageDef context, String baseName) { + while (context != null) { + Definition inner = lookupInner(context, baseName); + if (inner != null) { + return inner; + } + context = context.getOuter(); + } + + return _definitionByName.get(baseName); } } From de15a09c1a6a30d1fa4792a110f0df6f23f47e33 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 26 Oct 2022 21:21:04 +0200 Subject: [PATCH 006/207] Fixed missing XML serialization of enum-typed properties. Allow to disable name conversion to XML names. --- .../msgbuf/generator/EnumGenerator.java | 6 +- .../haumacher/msgbuf/generator/Generator.java | 3 +- .../msgbuf/generator/GeneratorPlugin.java | 15 +++++ .../generator/plugins/XmlStreamingPlugin.java | 63 ++++++++++++++----- 4 files changed, 69 insertions(+), 18 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/EnumGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/EnumGenerator.java index 08f9c5eb..6dd60e36 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/EnumGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/EnumGenerator.java @@ -63,7 +63,7 @@ protected void generate() { line("/**"); line(" * The protocol name of a {@link " + typeName(_def) + "} constant."); line(" *"); - line(" * @see #valueOfProtocol(String)"); + line(" * @see #" + CodeConvention.ENUM_VALUE_OF_PROTOCOL + "(String)"); line(" */"); line("@Override"); line("public String protocolName() {"); @@ -74,7 +74,7 @@ protected void generate() { nl(); line("/** Looks up a {@link " + typeName(_def) + "} constant by it's protocol name. */"); - line("public static " + typeName(_def) + " valueOfProtocol(String protocolName) {"); + line("public static " + typeName(_def) + " " + CodeConvention.ENUM_VALUE_OF_PROTOCOL + "(String protocolName) {"); List constants = _def.getConstants(); { line("if (protocolName == null) { return null; }"); @@ -99,7 +99,7 @@ protected void generate() { line("/** Reads a new instance from the given reader. */"); line("public static " + typeName(_def) + " " + CodeConvention.readerName(_def) + "(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException {"); { - line("return valueOfProtocol(in.nextString());"); + line("return " + CodeConvention.ENUM_VALUE_OF_PROTOCOL + "(in.nextString());"); } line("}"); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java index 39b6195f..46367bee 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java @@ -97,6 +97,8 @@ public void generate(GeneratorPlugin plugin) { } for (DefinitionFile file : _files) { + plugin.init(file.getOptions()); + File dir = mkdir(file.getPackage()); PackageGenerator packageGenerator = new PackageGenerator(dir, file.getOptions(), plugin); @@ -249,7 +251,6 @@ public static void main(String[] args) throws ParseException, IOException, Insta return; } else if (arg.equals("-p")) { plugin = plugin.andThen((GeneratorPlugin) Class.forName(args[n++]).newInstance()); - return; } else { File file = new File(arg); DefinitionFile content = generator.load(file); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java index 672fbf33..41f4bc2b 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java @@ -14,6 +14,15 @@ */ public interface GeneratorPlugin { + /** + * Initializes the plug-in with file options. + * + * @param options The options of the current file to translate. + */ + default void init(Map options) { + // Ignore. + } + /** * Creates a {@link FileGenerator} that is expanded within the interface class. * @@ -53,6 +62,12 @@ default GeneratorPlugin andThen(GeneratorPlugin next) { GeneratorPlugin self = this; return new GeneratorPlugin() { + @Override + public void init(Map options) { + self.init(options); + next.init(options); + } + @Override public FileGenerator messageImplContents(Map options, MessageDef def) { return (out, indent) -> { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java index aacef230..c7f5f18d 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java @@ -13,9 +13,11 @@ import java.util.Set; import de.haumacher.msgbuf.generator.AbstractMessageGenerator; +import de.haumacher.msgbuf.generator.CodeConvention; import de.haumacher.msgbuf.generator.GeneratorPlugin; import de.haumacher.msgbuf.generator.ast.CustomType; import de.haumacher.msgbuf.generator.ast.Definition; +import de.haumacher.msgbuf.generator.ast.EnumDef; import de.haumacher.msgbuf.generator.ast.Field; import de.haumacher.msgbuf.generator.ast.MessageDef; import de.haumacher.msgbuf.generator.ast.Option; @@ -31,6 +33,13 @@ */ public class XmlStreamingPlugin implements GeneratorPlugin { + private boolean _noXmlNames; + + @Override + public void init(Map options) { + _noXmlNames = noXmlNames(options); + } + @Override public FileGenerator messageInterfaceContents(Map options, MessageDef def) { if (noXml(options)) { @@ -147,7 +156,7 @@ protected void generate() { line("switch (name) {"); { for (Field field : def.getFields()) { - if (field.getType().kind() == Type.TypeKind.PRIMITIVE_TYPE) { + if (field.getType().kind() == Type.TypeKind.PRIMITIVE_TYPE || isEnum(field.getType())) { line("case " + xmlFieldNameConstant(field) + ": {"); { line(setterName(field) + "(" + fromString(field, "value") + ");"); @@ -194,17 +203,17 @@ protected void generate() { switch (type.kind()) { case PRIMITIVE_TYPE: { - line("case " + xmlFieldNameConstant(field) + ": {"); - { - line(setterName(field) + "(" + fromString(field, "in.getElementText()") + ");"); - line("break;"); - } - line("}"); + readPrimitiveXmlElement(field); break; } case CUSTOM_TYPE: { Definition typeDefinition = ((CustomType) type).getDefinition(); + if (typeDefinition instanceof EnumDef) { + readPrimitiveXmlElement(field); + break; + } + if (field.getOptions().get("Embedded") != null) { if (!(typeDefinition instanceof MessageDef)) { System.err.println("ERROR: Only other messages can be embedded from '" + field.getName() + "'."); @@ -311,6 +320,15 @@ protected void generate() { } } + private void readPrimitiveXmlElement(Field field) { + line("case " + xmlFieldNameConstant(field) + ": {"); + { + line(setterName(field) + "(" + fromString(field, "in.getElementText()") + ");"); + line("break;"); + } + line("}"); + } + String xmlTypeNameRef(MessageDef def) { return implName(def) + "." + xmlTypeNameConstant(def); } @@ -321,6 +339,10 @@ private boolean noXml(Map options) { return options.get("NoXml") != null; } + private boolean noXmlNames(Map options) { + return options.get("NoXmlNames") != null; + } + String readerMethod(MessageDef def) { return "read" + CodeUtil.firstUpperCase(def.getName()); } @@ -334,7 +356,7 @@ String xmlTypeName(MessageDef def) { if (fieldName.isPresent()) { return ((StringOption) fieldName.get()).getValue(); } - return CodeUtil.xmlName(def.getName()); + return xmlName(def.getName()); } String xmlFieldName(Field def) { @@ -346,11 +368,15 @@ String xmlFieldName(Field def) { if (fieldName.isPresent()) { return ((StringOption) fieldName.get()).getValue(); } - return CodeUtil.xmlName(def.getName()); + return xmlName(def.getName()); + } + + private String xmlName(String name) { + return _noXmlNames ? name : CodeUtil.xmlName(name); } String fromString(Field field, String value) { - PrimitiveType type = (PrimitiveType) field.getType(); + Type type = field.getType(); if (field.isRepeated()) { return fromStringList(type, value); } else { @@ -358,13 +384,18 @@ String fromString(Field field, String value) { } } - String fromStringList(de.haumacher.msgbuf.generator.ast.PrimitiveType type, String value) { + String fromStringList(de.haumacher.msgbuf.generator.ast.Type type, String value) { return "java.util.Arrays.stream(" + value + ".split(\"\\\\s*,\\\\s*\")).map(x -> " + fromStringSingle(type, "x") + ").collect(java.util.stream.Collectors.toList())"; } - String fromStringSingle(de.haumacher.msgbuf.generator.ast.PrimitiveType type, String value) { - switch (type.getKind()) { + String fromStringSingle(de.haumacher.msgbuf.generator.ast.Type type, String value) { + if (isEnum(type)) { + return CodeConvention.qTypeName(((CustomType) type).getDefinition()) + "." + CodeConvention.ENUM_VALUE_OF_PROTOCOL + "(" + value + ")"; + } + + PrimitiveType primitiveType = (PrimitiveType) type; + switch (primitiveType.getKind()) { case BOOL: return "Boolean.parseBoolean(" + value + ")"; @@ -397,7 +428,11 @@ String fromStringSingle(de.haumacher.msgbuf.generator.ast.PrimitiveType type, St return "java.util.Base64.getDecoder().decode(" + value + ");"; } - throw new UnsupportedOperationException("Cannot read values of type: " + type); + throw new UnsupportedOperationException("Cannot read values of type: " + primitiveType); + } + + boolean isEnum(Type type) { + return type instanceof CustomType && ((CustomType) type).getDefinition() instanceof EnumDef; } String xmlFieldNameConstant(Field field) { From c530900221a36066941662ccc966c55c960ce577 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 26 Oct 2022 21:21:40 +0200 Subject: [PATCH 007/207] Enabled XML serialization plug-in. --- de.haumacher.msgbuf.generator/bin/Generate MsgBuf.launch | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/de.haumacher.msgbuf.generator/bin/Generate MsgBuf.launch b/de.haumacher.msgbuf.generator/bin/Generate MsgBuf.launch index c9b395e0..13967097 100644 --- a/de.haumacher.msgbuf.generator/bin/Generate MsgBuf.launch +++ b/de.haumacher.msgbuf.generator/bin/Generate MsgBuf.launch @@ -1,17 +1,20 @@ + + + - + From 31938b0b7dc3c6b4ae80b587349fe967328bca14 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 26 Oct 2022 21:22:15 +0200 Subject: [PATCH 008/207] Updated test protocols. --- .../test/comments/data/SearchRequest.java | 6 +- .../comments/data/SearchRequest_Impl.java | 36 +- .../test/enumeration/data/SearchRequest.java | 8 +- .../enumeration/data/SearchRequest_Impl.java | 56 +- .../src/test/java/test/graph/data/Car.java | 6 +- .../test/java/test/graph/data/Car_Impl.java | 42 +- .../src/test/java/test/graph/data/Circle.java | 2 +- .../java/test/graph/data/Circle_Impl.java | 14 +- .../src/test/java/test/graph/data/Group.java | 2 +- .../test/java/test/graph/data/Group_Impl.java | 20 +- .../test/java/test/graph/data/Rectangle.java | 4 +- .../java/test/graph/data/Rectangle_Impl.java | 28 +- .../src/test/java/test/graph/data/Shape.java | 4 +- .../test/java/test/graph/data/Shape_Impl.java | 28 +- .../java/test/hierarchy/TestHierarchy.java | 6 +- .../java/test/hierarchy/data/AtomicShape.java | 3 + .../test/hierarchy/data/AtomicShape_Impl.java | 6 + .../test/java/test/hierarchy/data/Car.java | 15 +- .../java/test/hierarchy/data/Car_Impl.java | 42 +- .../test/java/test/hierarchy/data/Circle.java | 7 +- .../java/test/hierarchy/data/Circle_Impl.java | 18 +- .../test/java/test/hierarchy/data/Color.java | 82 +++ .../test/java/test/hierarchy/data/Group.java | 7 +- .../java/test/hierarchy/data/Group_Impl.java | 20 +- .../java/test/hierarchy/data/Optional.java | 11 +- .../test/hierarchy/data/Optional_Impl.java | 30 +- .../java/test/hierarchy/data/Rectangle.java | 11 +- .../test/hierarchy/data/Rectangle_Impl.java | 30 +- .../test/java/test/hierarchy/data/Shape.java | 20 +- .../java/test/hierarchy/data/Shape_Impl.java | 64 ++- .../java/test/hierarchy/data/hierarchy.proto | 16 + .../src/test/java/test/innertypeclash/A.java | 138 +++++ .../test/java/test/innertypeclash/A_Impl.java | 450 +++++++++++++++ .../src/test/java/test/innertypeclash/B.java | 138 +++++ .../test/java/test/innertypeclash/B_Impl.java | 450 +++++++++++++++ .../test/innertypeclash/innertypeclash.proto | 19 + .../test/java/test/lowercasemessage/A.java | 156 ++++++ .../java/test/lowercasemessage/A_Impl.java | 526 ++++++++++++++++++ .../lowercasemessage/lowercasemessage.proto | 14 + .../java/test/maptype/data/MyMessage.java | 4 +- .../test/maptype/data/MyMessage_Impl.java | 20 +- .../test/java/test/maptype/data/Project.java | 4 +- .../java/test/maptype/data/Project_Impl.java | 24 +- .../java/test/nested/data/SearchResponse.java | 8 +- .../test/nested/data/SearchResponse_Impl.java | 52 +- .../src/test/java/test/nointerfaces/Car.java | 42 +- .../test/java/test/nointerfaces/Circle.java | 14 +- .../test/java/test/nointerfaces/Group.java | 16 +- .../java/test/nointerfaces/Rectangle.java | 28 +- .../test/java/test/nointerfaces/Shape.java | 28 +- .../src/test/java/test/nojson/Car.java | 6 +- .../src/test/java/test/nojson/Car_Impl.java | 24 +- .../src/test/java/test/nojson/Circle.java | 2 +- .../test/java/test/nojson/Circle_Impl.java | 8 +- .../src/test/java/test/nojson/Group.java | 2 +- .../src/test/java/test/nojson/Group_Impl.java | 10 +- .../src/test/java/test/nojson/Rectangle.java | 4 +- .../test/java/test/nojson/Rectangle_Impl.java | 16 +- .../src/test/java/test/nojson/Shape.java | 4 +- .../src/test/java/test/nojson/Shape_Impl.java | 16 +- .../src/test/java/test/nolistener/Car.java | 6 +- .../test/java/test/nolistener/Car_Impl.java | 30 +- .../src/test/java/test/nolistener/Circle.java | 2 +- .../java/test/nolistener/Circle_Impl.java | 10 +- .../src/test/java/test/nolistener/Group.java | 2 +- .../test/java/test/nolistener/Group_Impl.java | 10 +- .../test/java/test/nolistener/Rectangle.java | 4 +- .../java/test/nolistener/Rectangle_Impl.java | 20 +- .../src/test/java/test/nolistener/Shape.java | 4 +- .../test/java/test/nolistener/Shape_Impl.java | 20 +- .../test/java/test/noreflection/Car_Impl.java | 18 +- .../java/test/noreflection/Circle_Impl.java | 6 +- .../java/test/noreflection/Group_Impl.java | 6 +- .../test/noreflection/Rectangle_Impl.java | 12 +- .../java/test/noreflection/Shape_Impl.java | 12 +- .../src/test/java/test/notypekind/Car.java | 6 +- .../test/java/test/notypekind/Car_Impl.java | 36 +- .../src/test/java/test/notypekind/Circle.java | 2 +- .../java/test/notypekind/Circle_Impl.java | 12 +- .../src/test/java/test/notypekind/Group.java | 2 +- .../test/java/test/notypekind/Group_Impl.java | 14 +- .../test/java/test/notypekind/Rectangle.java | 4 +- .../java/test/notypekind/Rectangle_Impl.java | 24 +- .../src/test/java/test/notypekind/Shape.java | 4 +- .../test/java/test/notypekind/Shape_Impl.java | 24 +- .../src/test/java/test/novisit/Car.java | 6 +- .../src/test/java/test/novisit/Car_Impl.java | 36 +- .../src/test/java/test/novisit/Circle.java | 2 +- .../test/java/test/novisit/Circle_Impl.java | 12 +- .../src/test/java/test/novisit/Group.java | 2 +- .../test/java/test/novisit/Group_Impl.java | 14 +- .../src/test/java/test/novisit/Rectangle.java | 4 +- .../java/test/novisit/Rectangle_Impl.java | 24 +- .../src/test/java/test/novisit/Shape.java | 4 +- .../test/java/test/novisit/Shape_Impl.java | 24 +- .../test/java/test/novisitexceptions/Car.java | 6 +- .../java/test/novisitexceptions/Car_Impl.java | 36 +- .../java/test/novisitexceptions/Circle.java | 2 +- .../test/novisitexceptions/Circle_Impl.java | 12 +- .../java/test/novisitexceptions/Group.java | 2 +- .../test/novisitexceptions/Group_Impl.java | 14 +- .../test/novisitexceptions/Rectangle.java | 4 +- .../novisitexceptions/Rectangle_Impl.java | 24 +- .../java/test/novisitexceptions/Shape.java | 4 +- .../test/novisitexceptions/Shape_Impl.java | 24 +- .../test/nullable/data/NullableValues.java | 16 +- .../nullable/data/NullableValues_Impl.java | 88 +-- .../references/TestReverseReferences.java | 12 +- .../src/test/java/test/references/data/A.java | 18 +- .../java/test/references/data/A_Impl.java | 106 ++-- .../src/test/java/test/references/data/B.java | 6 +- .../java/test/references/data/B_Impl.java | 28 +- .../java/test/types/data/SearchRequest.java | 6 +- .../test/types/data/SearchRequest_Impl.java | 36 +- .../test/underscorename/AnnotatedMessage.java | 2 +- .../underscorename/AnnotatedMessage_Impl.java | 12 +- .../java/test/underscorename/SomeName.java | 2 +- .../test/underscorename/SomeName_Impl.java | 12 +- 118 files changed, 2937 insertions(+), 820 deletions(-) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Color.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/innertypeclash.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/lowercasemessage.proto diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java index 53c929aa..7294cb10 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java @@ -17,13 +17,13 @@ static SearchRequest create() { static final String SEARCH_REQUEST__TYPE = "SearchRequest"; /** @see #getQuery() */ - static final String QUERY = "query"; + static final String QUERY__PROP = "query"; /** @see #getPageNumber() */ - static final String PAGE_NUMBER = "page_number"; + static final String PAGE_NUMBER__PROP = "page_number"; /** @see #getResultPerPage() */ - static final String RESULT_PER_PAGE = "result_per_page"; + static final String RESULT_PER_PAGE__PROP = "result_per_page"; /** Identifier for the property {@link #getQuery()} in binary format. */ static final int QUERY__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest_Impl.java index ddea9023..41d1f8d8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest_Impl.java @@ -34,7 +34,7 @@ public SearchRequest setQuery(String value) { /** Internal setter for {@link #getQuery()} without chain call utility. */ protected final void internalSetQuery(String value) { - _listener.beforeSet(this, QUERY, value); + _listener.beforeSet(this, QUERY__PROP, value); _query = value; } @@ -51,7 +51,7 @@ public SearchRequest setPageNumber(int value) { /** Internal setter for {@link #getPageNumber()} without chain call utility. */ protected final void internalSetPageNumber(int value) { - _listener.beforeSet(this, PAGE_NUMBER, value); + _listener.beforeSet(this, PAGE_NUMBER__PROP, value); _pageNumber = value; } @@ -68,7 +68,7 @@ public SearchRequest setResultPerPage(int value) { /** Internal setter for {@link #getResultPerPage()} without chain call utility. */ protected final void internalSetResultPerPage(int value) { - _listener.beforeSet(this, RESULT_PER_PAGE, value); + _listener.beforeSet(this, RESULT_PER_PAGE__PROP, value); _resultPerPage = value; } @@ -101,9 +101,9 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - QUERY, - PAGE_NUMBER, - RESULT_PER_PAGE)); + QUERY__PROP, + PAGE_NUMBER__PROP, + RESULT_PER_PAGE__PROP)); @Override public java.util.List properties() { @@ -113,9 +113,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case QUERY: return getQuery(); - case PAGE_NUMBER: return getPageNumber(); - case RESULT_PER_PAGE: return getResultPerPage(); + case QUERY__PROP: return getQuery(); + case PAGE_NUMBER__PROP: return getPageNumber(); + case RESULT_PER_PAGE__PROP: return getResultPerPage(); default: return SearchRequest.super.get(field); } } @@ -123,9 +123,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case QUERY: internalSetQuery((String) value); break; - case PAGE_NUMBER: internalSetPageNumber((int) value); break; - case RESULT_PER_PAGE: internalSetResultPerPage((int) value); break; + case QUERY__PROP: internalSetQuery((String) value); break; + case PAGE_NUMBER__PROP: internalSetPageNumber((int) value); break; + case RESULT_PER_PAGE__PROP: internalSetResultPerPage((int) value); break; } } @@ -137,20 +137,20 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(QUERY); + out.name(QUERY__PROP); out.value(getQuery()); - out.name(PAGE_NUMBER); + out.name(PAGE_NUMBER__PROP); out.value(getPageNumber()); - out.name(RESULT_PER_PAGE); + out.name(RESULT_PER_PAGE__PROP); out.value(getResultPerPage()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case QUERY: setQuery(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; - case PAGE_NUMBER: setPageNumber(in.nextInt()); break; - case RESULT_PER_PAGE: setResultPerPage(in.nextInt()); break; + case QUERY__PROP: setQuery(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case PAGE_NUMBER__PROP: setPageNumber(in.nextInt()); break; + case RESULT_PER_PAGE__PROP: setResultPerPage(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java index d2f56aa0..47d3f23e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java @@ -101,16 +101,16 @@ static SearchRequest create() { static final String SEARCH_REQUEST__TYPE = "SearchRequest"; /** @see #getQuery() */ - static final String QUERY = "query"; + static final String QUERY__PROP = "query"; /** @see #getPageNumber() */ - static final String PAGE_NUMBER = "page_number"; + static final String PAGE_NUMBER__PROP = "page_number"; /** @see #getResultPerPage() */ - static final String RESULT_PER_PAGE = "result_per_page"; + static final String RESULT_PER_PAGE__PROP = "result_per_page"; /** @see #getCorpus() */ - static final String CORPUS = "corpus"; + static final String CORPUS__PROP = "corpus"; /** Identifier for the property {@link #getQuery()} in binary format. */ static final int QUERY__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest_Impl.java index 60d61427..58b5feca 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest_Impl.java @@ -32,7 +32,7 @@ public SearchRequest setQuery(String value) { /** Internal setter for {@link #getQuery()} without chain call utility. */ protected final void internalSetQuery(String value) { - _listener.beforeSet(this, QUERY, value); + _listener.beforeSet(this, QUERY__PROP, value); _query = value; } @@ -49,7 +49,7 @@ public SearchRequest setPageNumber(int value) { /** Internal setter for {@link #getPageNumber()} without chain call utility. */ protected final void internalSetPageNumber(int value) { - _listener.beforeSet(this, PAGE_NUMBER, value); + _listener.beforeSet(this, PAGE_NUMBER__PROP, value); _pageNumber = value; } @@ -66,7 +66,7 @@ public SearchRequest setResultPerPage(int value) { /** Internal setter for {@link #getResultPerPage()} without chain call utility. */ protected final void internalSetResultPerPage(int value) { - _listener.beforeSet(this, RESULT_PER_PAGE, value); + _listener.beforeSet(this, RESULT_PER_PAGE__PROP, value); _resultPerPage = value; } @@ -84,7 +84,7 @@ public SearchRequest setCorpus(Corpus value) { /** Internal setter for {@link #getCorpus()} without chain call utility. */ protected final void internalSetCorpus(Corpus value) { if (value == null) throw new IllegalArgumentException("Property 'corpus' cannot be null."); - _listener.beforeSet(this, CORPUS, value); + _listener.beforeSet(this, CORPUS__PROP, value); _corpus = value; } @@ -117,10 +117,10 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - QUERY, - PAGE_NUMBER, - RESULT_PER_PAGE, - CORPUS)); + QUERY__PROP, + PAGE_NUMBER__PROP, + RESULT_PER_PAGE__PROP, + CORPUS__PROP)); @Override public java.util.List properties() { @@ -130,10 +130,10 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case QUERY: return getQuery(); - case PAGE_NUMBER: return getPageNumber(); - case RESULT_PER_PAGE: return getResultPerPage(); - case CORPUS: return getCorpus(); + case QUERY__PROP: return getQuery(); + case PAGE_NUMBER__PROP: return getPageNumber(); + case RESULT_PER_PAGE__PROP: return getResultPerPage(); + case CORPUS__PROP: return getCorpus(); default: return SearchRequest.super.get(field); } } @@ -141,10 +141,10 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case QUERY: internalSetQuery((String) value); break; - case PAGE_NUMBER: internalSetPageNumber((int) value); break; - case RESULT_PER_PAGE: internalSetResultPerPage((int) value); break; - case CORPUS: internalSetCorpus((Corpus) value); break; + case QUERY__PROP: internalSetQuery((String) value); break; + case PAGE_NUMBER__PROP: internalSetPageNumber((int) value); break; + case RESULT_PER_PAGE__PROP: internalSetResultPerPage((int) value); break; + case CORPUS__PROP: internalSetCorpus((Corpus) value); break; } } @@ -156,23 +156,23 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(QUERY); + out.name(QUERY__PROP); out.value(getQuery()); - out.name(PAGE_NUMBER); + out.name(PAGE_NUMBER__PROP); out.value(getPageNumber()); - out.name(RESULT_PER_PAGE); + out.name(RESULT_PER_PAGE__PROP); out.value(getResultPerPage()); - out.name(CORPUS); + out.name(CORPUS__PROP); getCorpus().writeTo(out); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case QUERY: setQuery(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; - case PAGE_NUMBER: setPageNumber(in.nextInt()); break; - case RESULT_PER_PAGE: setResultPerPage(in.nextInt()); break; - case CORPUS: setCorpus(test.enumeration.data.SearchRequest.Corpus.readCorpus(in)); break; + case QUERY__PROP: setQuery(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case PAGE_NUMBER__PROP: setPageNumber(in.nextInt()); break; + case RESULT_PER_PAGE__PROP: setResultPerPage(in.nextInt()); break; + case CORPUS__PROP: setCorpus(test.enumeration.data.SearchRequest.Corpus.readCorpus(in)); break; default: super.readField(in, field); } } @@ -285,6 +285,10 @@ protected void readFieldXmlAttribute(String name, String value) { setResultPerPage(Integer.parseInt(value)); break; } + case CORPUS__XML_ATTR: { + setCorpus(test.enumeration.data.SearchRequest.Corpus.valueOfProtocol(value)); + break; + } default: { // Skip unknown attribute. } @@ -306,6 +310,10 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l setResultPerPage(Integer.parseInt(in.getElementText())); break; } + case CORPUS__XML_ATTR: { + setCorpus(test.enumeration.data.SearchRequest.Corpus.valueOfProtocol(in.getElementText())); + break; + } default: { internalSkipUntilMatchingEndElement(in); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java index 559591eb..b74cc835 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java @@ -16,13 +16,13 @@ static Car create() { static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ - static final String WHEEL_1 = "wheel1"; + static final String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - static final String WHEEL_2 = "wheel2"; + static final String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - static final String BODY = "body"; + static final String BODY__PROP = "body"; /** * The front wheel. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car_Impl.java index dae91ab9..6dd4dcc8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car_Impl.java @@ -38,7 +38,7 @@ public Car setWheel1(Circle value) { /** Internal setter for {@link #getWheel1()} without chain call utility. */ protected final void internalSetWheel1(Circle value) { - _listener.beforeSet(this, WHEEL_1, value); + _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; } @@ -60,7 +60,7 @@ public Car setWheel2(Circle value) { /** Internal setter for {@link #getWheel2()} without chain call utility. */ protected final void internalSetWheel2(Circle value) { - _listener.beforeSet(this, WHEEL_2, value); + _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; } @@ -82,7 +82,7 @@ public Car setBody(Rectangle value) { /** Internal setter for {@link #getBody()} without chain call utility. */ protected final void internalSetBody(Rectangle value) { - _listener.beforeSet(this, BODY, value); + _listener.beforeSet(this, BODY__PROP, value); _body = value; } @@ -110,9 +110,9 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WHEEL_1, - WHEEL_2, - BODY)); + WHEEL_1__PROP, + WHEEL_2__PROP, + BODY__PROP)); @Override public java.util.List properties() { @@ -122,9 +122,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WHEEL_1: return getWheel1(); - case WHEEL_2: return getWheel2(); - case BODY: return getBody(); + case WHEEL_1__PROP: return getWheel1(); + case WHEEL_2__PROP: return getWheel2(); + case BODY__PROP: return getBody(); default: return super.get(field); } } @@ -132,9 +132,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1: internalSetWheel1((Circle) value); break; - case WHEEL_2: internalSetWheel2((Circle) value); break; - case BODY: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; + case BODY__PROP: internalSetBody((Rectangle) value); break; default: super.set(field, value); break; } } @@ -143,15 +143,15 @@ public void set(String field, Object value) { protected void writeFields(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(scope, out); if (hasWheel1()) { - out.name(WHEEL_1); + out.name(WHEEL_1__PROP); getWheel1().writeTo(scope, out); } if (hasWheel2()) { - out.name(WHEEL_2); + out.name(WHEEL_2__PROP); getWheel2().writeTo(scope, out); } if (hasBody()) { - out.name(BODY); + out.name(BODY__PROP); getBody().writeTo(scope, out); } } @@ -159,7 +159,7 @@ protected void writeFields(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.m @Override public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out, String field) throws java.io.IOException { switch (field) { - case WHEEL_1: { + case WHEEL_1__PROP: { if (hasWheel1()) { getWheel1().writeTo(scope, out); } else { @@ -167,7 +167,7 @@ public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher. } break; } - case WHEEL_2: { + case WHEEL_2__PROP: { if (hasWheel2()) { getWheel2().writeTo(scope, out); } else { @@ -175,7 +175,7 @@ public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher. } break; } - case BODY: { + case BODY__PROP: { if (hasBody()) { getBody().writeTo(scope, out); } else { @@ -190,9 +190,9 @@ public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher. @Override public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WHEEL_1: setWheel1(test.graph.data.Circle.readCircle(scope, in)); break; - case WHEEL_2: setWheel2(test.graph.data.Circle.readCircle(scope, in)); break; - case BODY: setBody(test.graph.data.Rectangle.readRectangle(scope, in)); break; + case WHEEL_1__PROP: setWheel1(test.graph.data.Circle.readCircle(scope, in)); break; + case WHEEL_2__PROP: setWheel2(test.graph.data.Circle.readCircle(scope, in)); break; + case BODY__PROP: setBody(test.graph.data.Rectangle.readRectangle(scope, in)); break; default: super.readField(scope, in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java index 8a622202..53e94157 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java @@ -16,7 +16,7 @@ static Circle create() { static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ - static final String RADIUS = "r"; + static final String RADIUS__PROP = "r"; /** * The radius of this {@link Circle} around its coordinate origin at ({@link #getXCoordinate()}, {@link #getYCoordinate()}). diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle_Impl.java index 34fe74b9..8555965c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle_Impl.java @@ -34,7 +34,7 @@ public Circle setRadius(int value) { /** Internal setter for {@link #getRadius()} without chain call utility. */ protected final void internalSetRadius(int value) { - _listener.beforeSet(this, RADIUS, value); + _listener.beforeSet(this, RADIUS__PROP, value); _radius = value; } @@ -57,7 +57,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - RADIUS)); + RADIUS__PROP)); @Override public java.util.List properties() { @@ -67,7 +67,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case RADIUS: return getRadius(); + case RADIUS__PROP: return getRadius(); default: return super.get(field); } } @@ -75,7 +75,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case RADIUS: internalSetRadius((int) value); break; + case RADIUS__PROP: internalSetRadius((int) value); break; default: super.set(field, value); break; } } @@ -83,14 +83,14 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(scope, out); - out.name(RADIUS); + out.name(RADIUS__PROP); out.value(getRadius()); } @Override public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out, String field) throws java.io.IOException { switch (field) { - case RADIUS: { + case RADIUS__PROP: { out.value(getRadius()); break; } @@ -101,7 +101,7 @@ public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher. @Override public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case RADIUS: setRadius(in.nextInt()); break; + case RADIUS__PROP: setRadius(in.nextInt()); break; default: super.readField(scope, in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java index 42ef5713..771b518d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java @@ -16,7 +16,7 @@ static Group create() { static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ - static final String SHAPES = "shapes"; + static final String SHAPES__PROP = "shapes"; /** * All {@link Shape}s in this {@link Group}. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group_Impl.java index 62cfbdf7..dd222633 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group_Impl.java @@ -8,12 +8,12 @@ class Group_Impl extends Shape_Impl implements Group { private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, Shape element) { - _listener.beforeAdd(Group_Impl.this, SHAPES, index, element); + _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); } @Override protected void afterRemove(int index, Shape element) { - _listener.afterRemove(Group_Impl.this, SHAPES, index, element); + _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } }; @@ -84,7 +84,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - SHAPES)); + SHAPES__PROP)); @Override public java.util.List properties() { @@ -94,7 +94,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case SHAPES: return getShapes(); + case SHAPES__PROP: return getShapes(); default: return super.get(field); } } @@ -102,7 +102,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; default: super.set(field, value); break; } } @@ -110,7 +110,7 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(scope, out); - out.name(SHAPES); + out.name(SHAPES__PROP); out.beginArray(); for (Shape x : getShapes()) { x.writeTo(scope, out); @@ -121,7 +121,7 @@ protected void writeFields(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.m @Override public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out, String field) throws java.io.IOException { switch (field) { - case SHAPES: { + case SHAPES__PROP: { out.beginArray(); for (Shape x : getShapes()) { x.writeTo(scope, out); @@ -136,7 +136,7 @@ public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher. @Override public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case SHAPES: { + case SHAPES__PROP: { in.beginArray(); while (in.hasNext()) { addShape(test.graph.data.Shape.readShape(scope, in)); @@ -151,7 +151,7 @@ public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf @Override public void writeElement(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out, String field, Object element) throws java.io.IOException { switch (field) { - case SHAPES: { + case SHAPES__PROP: { ((Shape) element).writeTo(scope, out); break; } @@ -162,7 +162,7 @@ public void writeElement(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msg @Override public Object readElement(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case SHAPES: { + case SHAPES__PROP: { return test.graph.data.Shape.readShape(scope, in); } default: return super.readElement(scope, in, field); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java index 8385a0f5..698345f5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java @@ -16,10 +16,10 @@ static Rectangle create() { static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ - static final String WIDTH = "w"; + static final String WIDTH__PROP = "w"; /** @see #getHeight() */ - static final String HEIGHT = "h"; + static final String HEIGHT__PROP = "h"; /** * The width of this {@link Rectangle}. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle_Impl.java index 41967b79..21d76dd7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle_Impl.java @@ -36,7 +36,7 @@ public Rectangle setWidth(int value) { /** Internal setter for {@link #getWidth()} without chain call utility. */ protected final void internalSetWidth(int value) { - _listener.beforeSet(this, WIDTH, value); + _listener.beforeSet(this, WIDTH__PROP, value); _width = value; } @@ -53,7 +53,7 @@ public Rectangle setHeight(int value) { /** Internal setter for {@link #getHeight()} without chain call utility. */ protected final void internalSetHeight(int value) { - _listener.beforeSet(this, HEIGHT, value); + _listener.beforeSet(this, HEIGHT__PROP, value); _height = value; } @@ -76,8 +76,8 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WIDTH, - HEIGHT)); + WIDTH__PROP, + HEIGHT__PROP)); @Override public java.util.List properties() { @@ -87,8 +87,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WIDTH: return getWidth(); - case HEIGHT: return getHeight(); + case WIDTH__PROP: return getWidth(); + case HEIGHT__PROP: return getHeight(); default: return super.get(field); } } @@ -96,8 +96,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WIDTH: internalSetWidth((int) value); break; - case HEIGHT: internalSetHeight((int) value); break; + case WIDTH__PROP: internalSetWidth((int) value); break; + case HEIGHT__PROP: internalSetHeight((int) value); break; default: super.set(field, value); break; } } @@ -105,20 +105,20 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(scope, out); - out.name(WIDTH); + out.name(WIDTH__PROP); out.value(getWidth()); - out.name(HEIGHT); + out.name(HEIGHT__PROP); out.value(getHeight()); } @Override public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out, String field) throws java.io.IOException { switch (field) { - case WIDTH: { + case WIDTH__PROP: { out.value(getWidth()); break; } - case HEIGHT: { + case HEIGHT__PROP: { out.value(getHeight()); break; } @@ -129,8 +129,8 @@ public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher. @Override public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WIDTH: setWidth(in.nextInt()); break; - case HEIGHT: setHeight(in.nextInt()); break; + case WIDTH__PROP: setWidth(in.nextInt()); break; + case HEIGHT__PROP: setHeight(in.nextInt()); break; default: super.readField(scope, in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java index e14299ee..e9a6fd39 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java @@ -35,10 +35,10 @@ public interface Visitor extends AtomicShape.Visitor PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - X_COORDINATE, - Y_COORDINATE)); + X_COORDINATE__PROP, + Y_COORDINATE__PROP)); @Override public java.util.List properties() { @@ -66,8 +66,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case X_COORDINATE: return getXCoordinate(); - case Y_COORDINATE: return getYCoordinate(); + case X_COORDINATE__PROP: return getXCoordinate(); + case Y_COORDINATE__PROP: return getYCoordinate(); default: return super.get(field); } } @@ -75,28 +75,28 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case X_COORDINATE: internalSetXCoordinate((int) value); break; - case Y_COORDINATE: internalSetYCoordinate((int) value); break; + case X_COORDINATE__PROP: internalSetXCoordinate((int) value); break; + case Y_COORDINATE__PROP: internalSetYCoordinate((int) value); break; } } @Override protected void writeFields(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(scope, out); - out.name(X_COORDINATE); + out.name(X_COORDINATE__PROP); out.value(getXCoordinate()); - out.name(Y_COORDINATE); + out.name(Y_COORDINATE__PROP); out.value(getYCoordinate()); } @Override public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out, String field) throws java.io.IOException { switch (field) { - case X_COORDINATE: { + case X_COORDINATE__PROP: { out.value(getXCoordinate()); break; } - case Y_COORDINATE: { + case Y_COORDINATE__PROP: { out.value(getYCoordinate()); break; } @@ -107,8 +107,8 @@ public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher. @Override public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case X_COORDINATE: setXCoordinate(in.nextInt()); break; - case Y_COORDINATE: setYCoordinate(in.nextInt()); break; + case X_COORDINATE__PROP: setXCoordinate(in.nextInt()); break; + case Y_COORDINATE__PROP: setYCoordinate(in.nextInt()); break; default: super.readField(scope, in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/TestHierarchy.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/TestHierarchy.java index 20b8af74..6ed027d4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/TestHierarchy.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/TestHierarchy.java @@ -22,6 +22,7 @@ import junit.framework.TestCase; import test.hierarchy.data.Car; import test.hierarchy.data.Circle; +import test.hierarchy.data.Color; import test.hierarchy.data.Group; import test.hierarchy.data.Optional; import test.hierarchy.data.Rectangle; @@ -86,8 +87,8 @@ private Shape writeAndReadBackBinary(Shape shape) throws IOException { } public void testXmlRead() throws XMLStreamException, FactoryConfigurationError { - checkShape(""); - checkShape(" 10 20 50 true 75 "); + checkShape(""); + checkShape(" 10 20 50blue true 75 "); } private void checkShape(String xml) throws XMLStreamException, FactoryConfigurationError { @@ -104,6 +105,7 @@ private void checkShape(String xml) throws XMLStreamException, FactoryConfigurat assertNotNull(first); assertTrue(first.toString(), first instanceof Circle); assertEquals(50, ((Circle) first).getRadius()); + assertEquals(Color.BLUE, first.getColor()); Shape second = group.getShapes().get(1); assertNotNull(second); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape.java index d9d3a093..dc8060e1 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape.java @@ -22,6 +22,9 @@ public interface Visitor { @Override AtomicShape setYCoordinate(int value); + @Override + AtomicShape setColor(Color value); + /** Reads a new instance from the given reader. */ static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { AtomicShape result; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape_Impl.java index f5d8f63c..ef23d11f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape_Impl.java @@ -24,6 +24,12 @@ public AtomicShape setYCoordinate(int value) { return this; } + @Override + public AtomicShape setColor(Color value) { + internalSetColor(value); + return this; + } + /** XML element name representing a {@link AtomicShape} type. */ public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java index 8b493ce5..2ceba747 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java @@ -16,25 +16,25 @@ static Car create() { static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ - static final String WHEEL_1 = "wheel1"; + static final String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - static final String WHEEL_2 = "wheel2"; + static final String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - static final String BODY = "body"; + static final String BODY__PROP = "body"; /** Identifier for the {@link Car} type in binary format. */ static final int CAR__TYPE_ID = 5; /** Identifier for the property {@link #getWheel1()} in binary format. */ - static final int WHEEL_1__ID = 3; + static final int WHEEL_1__ID = 4; /** Identifier for the property {@link #getWheel2()} in binary format. */ - static final int WHEEL_2__ID = 4; + static final int WHEEL_2__ID = 5; /** Identifier for the property {@link #getBody()} in binary format. */ - static final int BODY__ID = 5; + static final int BODY__ID = 6; /** * The front wheel. @@ -87,6 +87,9 @@ static Car create() { @Override Car setYCoordinate(int value); + @Override + Car setColor(Color value); + /** Reads a new instance from the given reader. */ static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car_Impl.java index 676b433f..09611376 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car_Impl.java @@ -38,7 +38,7 @@ public Car setWheel1(Circle value) { /** Internal setter for {@link #getWheel1()} without chain call utility. */ protected final void internalSetWheel1(Circle value) { - _listener.beforeSet(this, WHEEL_1, value); + _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; } @@ -60,7 +60,7 @@ public Car setWheel2(Circle value) { /** Internal setter for {@link #getWheel2()} without chain call utility. */ protected final void internalSetWheel2(Circle value) { - _listener.beforeSet(this, WHEEL_2, value); + _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; } @@ -82,7 +82,7 @@ public Car setBody(Rectangle value) { /** Internal setter for {@link #getBody()} without chain call utility. */ protected final void internalSetBody(Rectangle value) { - _listener.beforeSet(this, BODY, value); + _listener.beforeSet(this, BODY__PROP, value); _body = value; } @@ -103,6 +103,12 @@ public Car setYCoordinate(int value) { return this; } + @Override + public Car setColor(Color value) { + internalSetColor(value); + return this; + } + @Override public String jsonType() { return CAR__TYPE; @@ -110,9 +116,9 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WHEEL_1, - WHEEL_2, - BODY)); + WHEEL_1__PROP, + WHEEL_2__PROP, + BODY__PROP)); @Override public java.util.List properties() { @@ -122,9 +128,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WHEEL_1: return getWheel1(); - case WHEEL_2: return getWheel2(); - case BODY: return getBody(); + case WHEEL_1__PROP: return getWheel1(); + case WHEEL_2__PROP: return getWheel2(); + case BODY__PROP: return getBody(); default: return super.get(field); } } @@ -132,9 +138,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1: internalSetWheel1((Circle) value); break; - case WHEEL_2: internalSetWheel2((Circle) value); break; - case BODY: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; + case BODY__PROP: internalSetBody((Rectangle) value); break; default: super.set(field, value); break; } } @@ -143,15 +149,15 @@ public void set(String field, Object value) { protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); if (hasWheel1()) { - out.name(WHEEL_1); + out.name(WHEEL_1__PROP); getWheel1().writeContent(out); } if (hasWheel2()) { - out.name(WHEEL_2); + out.name(WHEEL_2__PROP); getWheel2().writeContent(out); } if (hasBody()) { - out.name(BODY); + out.name(BODY__PROP); getBody().writeContent(out); } } @@ -159,9 +165,9 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WHEEL_1: setWheel1(test.hierarchy.data.Circle.readCircle(in)); break; - case WHEEL_2: setWheel2(test.hierarchy.data.Circle.readCircle(in)); break; - case BODY: setBody(test.hierarchy.data.Rectangle.readRectangle(in)); break; + case WHEEL_1__PROP: setWheel1(test.hierarchy.data.Circle.readCircle(in)); break; + case WHEEL_2__PROP: setWheel2(test.hierarchy.data.Circle.readCircle(in)); break; + case BODY__PROP: setBody(test.hierarchy.data.Rectangle.readRectangle(in)); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java index 4b2ff313..f407b09d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java @@ -16,13 +16,13 @@ static Circle create() { static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ - static final String RADIUS = "r"; + static final String RADIUS__PROP = "r"; /** Identifier for the {@link Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; /** Identifier for the property {@link #getRadius()} in binary format. */ - static final int RADIUS__ID = 3; + static final int RADIUS__ID = 4; /** * The radius of this {@link Circle} around its coordinate origin at ({@link #getXCoordinate()}, {@link #getYCoordinate()}). @@ -40,6 +40,9 @@ static Circle create() { @Override Circle setYCoordinate(int value); + @Override + Circle setColor(Color value); + /** Reads a new instance from the given reader. */ static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle_Impl.java index 15f8f88f..0e935e2b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle_Impl.java @@ -34,7 +34,7 @@ public Circle setRadius(int value) { /** Internal setter for {@link #getRadius()} without chain call utility. */ protected final void internalSetRadius(int value) { - _listener.beforeSet(this, RADIUS, value); + _listener.beforeSet(this, RADIUS__PROP, value); _radius = value; } @@ -50,6 +50,12 @@ public Circle setYCoordinate(int value) { return this; } + @Override + public Circle setColor(Color value) { + internalSetColor(value); + return this; + } + @Override public String jsonType() { return CIRCLE__TYPE; @@ -57,7 +63,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - RADIUS)); + RADIUS__PROP)); @Override public java.util.List properties() { @@ -67,7 +73,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case RADIUS: return getRadius(); + case RADIUS__PROP: return getRadius(); default: return super.get(field); } } @@ -75,7 +81,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case RADIUS: internalSetRadius((int) value); break; + case RADIUS__PROP: internalSetRadius((int) value); break; default: super.set(field, value); break; } } @@ -83,14 +89,14 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(RADIUS); + out.name(RADIUS__PROP); out.value(getRadius()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case RADIUS: setRadius(in.nextInt()); break; + case RADIUS__PROP: setRadius(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Color.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Color.java new file mode 100644 index 00000000..1d1709ec --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Color.java @@ -0,0 +1,82 @@ +package test.hierarchy.data; + +/** + * {@link Shape} colors. + */ +public enum Color implements de.haumacher.msgbuf.data.ProtocolEnum { + + RED("red"), + + GREEN("green"), + + BLUE("blue"), + + YELLOW("yellow"), + + MAGENTA("magenta"), + + ; + + private final String _protocolName; + + private Color(String protocolName) { + _protocolName = protocolName; + } + + /** + * The protocol name of a {@link Color} constant. + * + * @see #valueOfProtocol(String) + */ + @Override + public String protocolName() { + return _protocolName; + } + + /** Looks up a {@link Color} constant by it's protocol name. */ + public static Color valueOfProtocol(String protocolName) { + if (protocolName == null) { return null; } + switch (protocolName) { + case "red": return RED; + case "green": return GREEN; + case "blue": return BLUE; + case "yellow": return YELLOW; + case "magenta": return MAGENTA; + } + return RED; + } + + /** Writes this instance to the given output. */ + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.value(protocolName()); + } + + /** Reads a new instance from the given reader. */ + public static Color readColor(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + return valueOfProtocol(in.nextString()); + } + + /** Writes this instance to the given binary output. */ + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + switch (this) { + case RED: out.value(1); break; + case GREEN: out.value(2); break; + case BLUE: out.value(3); break; + case YELLOW: out.value(4); break; + case MAGENTA: out.value(5); break; + default: out.value(0); + } + } + + /** Reads a new instance from the given binary reader. */ + public static Color readColor(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + switch (in.nextInt()) { + case 1: return RED; + case 2: return GREEN; + case 3: return BLUE; + case 4: return YELLOW; + case 5: return MAGENTA; + default: return RED; + } + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java index 84ec1819..e49c343b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java @@ -16,13 +16,13 @@ static Group create() { static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ - static final String SHAPES = "shapes"; + static final String SHAPES__PROP = "shapes"; /** Identifier for the {@link Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; /** Identifier for the property {@link #getShapes()} in binary format. */ - static final int SHAPES__ID = 3; + static final int SHAPES__ID = 4; /** * All {@link Shape}s in this {@link Group}. @@ -54,6 +54,9 @@ static Group create() { @Override Group setYCoordinate(int value); + @Override + Group setColor(Color value); + /** Reads a new instance from the given reader. */ static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group_Impl.java index b4b63f32..5f012203 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group_Impl.java @@ -8,12 +8,12 @@ class Group_Impl extends Shape_Impl implements Group { private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, Shape element) { - _listener.beforeAdd(Group_Impl.this, SHAPES, index, element); + _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); } @Override protected void afterRemove(int index, Shape element) { - _listener.afterRemove(Group_Impl.this, SHAPES, index, element); + _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } }; @@ -77,6 +77,12 @@ public Group setYCoordinate(int value) { return this; } + @Override + public Group setColor(Color value) { + internalSetColor(value); + return this; + } + @Override public String jsonType() { return GROUP__TYPE; @@ -84,7 +90,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - SHAPES)); + SHAPES__PROP)); @Override public java.util.List properties() { @@ -94,7 +100,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case SHAPES: return getShapes(); + case SHAPES__PROP: return getShapes(); default: return super.get(field); } } @@ -102,7 +108,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; default: super.set(field, value); break; } } @@ -110,7 +116,7 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(SHAPES); + out.name(SHAPES__PROP); out.beginArray(); for (Shape x : getShapes()) { x.writeTo(out); @@ -121,7 +127,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case SHAPES: { + case SHAPES__PROP: { in.beginArray(); while (in.hasNext()) { addShape(test.hierarchy.data.Shape.readShape(in)); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java index ba48e00a..933ccb67 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java @@ -16,19 +16,19 @@ static Optional create() { static final String OPTIONAL__TYPE = "Optional"; /** @see #isHidden() */ - static final String HIDDEN = "hidden"; + static final String HIDDEN__PROP = "hidden"; /** @see #getShape() */ - static final String SHAPE = "shape"; + static final String SHAPE__PROP = "shape"; /** Identifier for the {@link Optional} type in binary format. */ static final int OPTIONAL__TYPE_ID = 4; /** Identifier for the property {@link #isHidden()} in binary format. */ - static final int HIDDEN__ID = 3; + static final int HIDDEN__ID = 4; /** Identifier for the property {@link #getShape()} in binary format. */ - static final int SHAPE__ID = 4; + static final int SHAPE__ID = 5; /** * Whether {@link #getShape()} is hidden. @@ -61,6 +61,9 @@ static Optional create() { @Override Optional setYCoordinate(int value); + @Override + Optional setColor(Color value); + /** Reads a new instance from the given reader. */ static Optional readOptional(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional_Impl.java index 57c83b87..a830c8b8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional_Impl.java @@ -36,7 +36,7 @@ public Optional setHidden(boolean value) { /** Internal setter for {@link #isHidden()} without chain call utility. */ protected final void internalSetHidden(boolean value) { - _listener.beforeSet(this, HIDDEN, value); + _listener.beforeSet(this, HIDDEN__PROP, value); _hidden = value; } @@ -53,7 +53,7 @@ public Optional setShape(Shape value) { /** Internal setter for {@link #getShape()} without chain call utility. */ protected final void internalSetShape(Shape value) { - _listener.beforeSet(this, SHAPE, value); + _listener.beforeSet(this, SHAPE__PROP, value); _shape = value; } @@ -74,6 +74,12 @@ public Optional setYCoordinate(int value) { return this; } + @Override + public Optional setColor(Color value) { + internalSetColor(value); + return this; + } + @Override public String jsonType() { return OPTIONAL__TYPE; @@ -81,8 +87,8 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - HIDDEN, - SHAPE)); + HIDDEN__PROP, + SHAPE__PROP)); @Override public java.util.List properties() { @@ -92,8 +98,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case HIDDEN: return isHidden(); - case SHAPE: return getShape(); + case HIDDEN__PROP: return isHidden(); + case SHAPE__PROP: return getShape(); default: return super.get(field); } } @@ -101,8 +107,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case HIDDEN: internalSetHidden((boolean) value); break; - case SHAPE: internalSetShape((Shape) value); break; + case HIDDEN__PROP: internalSetHidden((boolean) value); break; + case SHAPE__PROP: internalSetShape((Shape) value); break; default: super.set(field, value); break; } } @@ -110,10 +116,10 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(HIDDEN); + out.name(HIDDEN__PROP); out.value(isHidden()); if (hasShape()) { - out.name(SHAPE); + out.name(SHAPE__PROP); getShape().writeTo(out); } } @@ -121,8 +127,8 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case HIDDEN: setHidden(in.nextBoolean()); break; - case SHAPE: setShape(test.hierarchy.data.Shape.readShape(in)); break; + case HIDDEN__PROP: setHidden(in.nextBoolean()); break; + case SHAPE__PROP: setShape(test.hierarchy.data.Shape.readShape(in)); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java index 5b5c475e..937d1f8f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java @@ -16,19 +16,19 @@ static Rectangle create() { static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ - static final String WIDTH = "w"; + static final String WIDTH__PROP = "w"; /** @see #getHeight() */ - static final String HEIGHT = "h"; + static final String HEIGHT__PROP = "h"; /** Identifier for the {@link Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; /** Identifier for the property {@link #getWidth()} in binary format. */ - static final int WIDTH__ID = 3; + static final int WIDTH__ID = 4; /** Identifier for the property {@link #getHeight()} in binary format. */ - static final int HEIGHT__ID = 4; + static final int HEIGHT__ID = 5; /** * The width of this {@link Rectangle}. @@ -64,6 +64,9 @@ static Rectangle create() { @Override Rectangle setYCoordinate(int value); + @Override + Rectangle setColor(Color value); + /** Reads a new instance from the given reader. */ static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle_Impl.java index 475744c5..5be10d7e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle_Impl.java @@ -36,7 +36,7 @@ public Rectangle setWidth(int value) { /** Internal setter for {@link #getWidth()} without chain call utility. */ protected final void internalSetWidth(int value) { - _listener.beforeSet(this, WIDTH, value); + _listener.beforeSet(this, WIDTH__PROP, value); _width = value; } @@ -53,7 +53,7 @@ public Rectangle setHeight(int value) { /** Internal setter for {@link #getHeight()} without chain call utility. */ protected final void internalSetHeight(int value) { - _listener.beforeSet(this, HEIGHT, value); + _listener.beforeSet(this, HEIGHT__PROP, value); _height = value; } @@ -69,6 +69,12 @@ public Rectangle setYCoordinate(int value) { return this; } + @Override + public Rectangle setColor(Color value) { + internalSetColor(value); + return this; + } + @Override public String jsonType() { return RECTANGLE__TYPE; @@ -76,8 +82,8 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WIDTH, - HEIGHT)); + WIDTH__PROP, + HEIGHT__PROP)); @Override public java.util.List properties() { @@ -87,8 +93,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WIDTH: return getWidth(); - case HEIGHT: return getHeight(); + case WIDTH__PROP: return getWidth(); + case HEIGHT__PROP: return getHeight(); default: return super.get(field); } } @@ -96,8 +102,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WIDTH: internalSetWidth((int) value); break; - case HEIGHT: internalSetHeight((int) value); break; + case WIDTH__PROP: internalSetWidth((int) value); break; + case HEIGHT__PROP: internalSetHeight((int) value); break; default: super.set(field, value); break; } } @@ -105,17 +111,17 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(WIDTH); + out.name(WIDTH__PROP); out.value(getWidth()); - out.name(HEIGHT); + out.name(HEIGHT__PROP); out.value(getHeight()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WIDTH: setWidth(in.nextInt()); break; - case HEIGHT: setHeight(in.nextInt()); break; + case WIDTH__PROP: setWidth(in.nextInt()); break; + case HEIGHT__PROP: setHeight(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java index a62571f5..1e47b993 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java @@ -41,10 +41,13 @@ public interface Visitor extends AtomicShape.Visitor extends AtomicShape.Visitor extends AtomicShape.Visitor PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - X_COORDINATE, - Y_COORDINATE)); + X_COORDINATE__PROP, + Y_COORDINATE__PROP, + COLOR__PROP)); @Override public java.util.List properties() { @@ -88,8 +109,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case X_COORDINATE: return getXCoordinate(); - case Y_COORDINATE: return getYCoordinate(); + case X_COORDINATE__PROP: return getXCoordinate(); + case Y_COORDINATE__PROP: return getYCoordinate(); + case COLOR__PROP: return getColor(); default: return Shape.super.get(field); } } @@ -97,8 +119,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case X_COORDINATE: internalSetXCoordinate((int) value); break; - case Y_COORDINATE: internalSetYCoordinate((int) value); break; + case X_COORDINATE__PROP: internalSetXCoordinate((int) value); break; + case Y_COORDINATE__PROP: internalSetYCoordinate((int) value); break; + case COLOR__PROP: internalSetColor((Color) value); break; } } @@ -113,17 +136,20 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(X_COORDINATE); + out.name(X_COORDINATE__PROP); out.value(getXCoordinate()); - out.name(Y_COORDINATE); + out.name(Y_COORDINATE__PROP); out.value(getYCoordinate()); + out.name(COLOR__PROP); + getColor().writeTo(out); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case X_COORDINATE: setXCoordinate(in.nextInt()); break; - case Y_COORDINATE: setYCoordinate(in.nextInt()); break; + case X_COORDINATE__PROP: setXCoordinate(in.nextInt()); break; + case Y_COORDINATE__PROP: setYCoordinate(in.nextInt()); break; + case COLOR__PROP: setColor(test.hierarchy.data.Color.readColor(in)); break; default: super.readField(in, field); } } @@ -149,6 +175,8 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getXCoordinate()); out.name(Y_COORDINATE__ID); out.value(getYCoordinate()); + out.name(COLOR__ID); + getColor().writeTo(out); } /** Helper for reading all fields of this instance. */ @@ -164,6 +192,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th switch (field) { case X_COORDINATE__ID: setXCoordinate(in.nextInt()); break; case Y_COORDINATE__ID: setYCoordinate(in.nextInt()); break; + case COLOR__ID: setColor(test.hierarchy.data.Color.readColor(in)); break; default: in.skipValue(); } } @@ -177,6 +206,9 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getYCoordinate} property. */ private static final String Y_COORDINATE__XML_ATTR = "y"; + /** XML attribute or element name of a {@link #getColor} property. */ + private static final String COLOR__XML_ATTR = "color"; + /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { @@ -238,6 +270,10 @@ protected void readFieldXmlAttribute(String name, String value) { setYCoordinate(Integer.parseInt(value)); break; } + case COLOR__XML_ATTR: { + setColor(test.hierarchy.data.Color.valueOfProtocol(value)); + break; + } default: { // Skip unknown attribute. } @@ -255,6 +291,10 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l setYCoordinate(Integer.parseInt(in.getElementText())); break; } + case COLOR__XML_ATTR: { + setColor(test.hierarchy.data.Color.valueOfProtocol(in.getElementText())); + break; + } default: { internalSkipUntilMatchingEndElement(in); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/hierarchy.proto b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/hierarchy.proto index 234f3d5d..bbe067b7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/hierarchy.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/hierarchy.proto @@ -2,6 +2,17 @@ syntax = "msgbuf"; package test.hierarchy.data; +/** + * {@link Shape} colors. + */ +enum Color { + `red`; + `green`; + `blue`; + `yellow`; + `magenta`; +} + /** * An abstract base class for all shapes */ @@ -17,6 +28,11 @@ abstract message Shape { */ @Name("y") int32 yCoordinate; + + /** + * The shape's color. + */ + Color color; } /** A {@link Shape} that has no sub-shapes. */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java new file mode 100644 index 00000000..a3616ea6 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java @@ -0,0 +1,138 @@ +package test.innertypeclash; + +public interface A extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { + public interface C extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { + + /** + * Creates a {@link C} instance. + */ + static C create() { + return new test.innertypeclash.A_Impl.C_Impl(); + } + + /** Identifier for the {@link C} type in JSON format. */ + static final String C__TYPE = "C"; + + @Override + public C registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public C unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + + /** Reads a new instance from the given reader. */ + static C readC(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.innertypeclash.A_Impl.C_Impl result = new test.innertypeclash.A_Impl.C_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static C readC(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + C result = test.innertypeclash.A_Impl.C_Impl.readC_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link C} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static C readC(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.innertypeclash.A_Impl.C_Impl.readC_XmlContent(in); + } + + } + + /** + * Creates a {@link A} instance. + */ + static A create() { + return new test.innertypeclash.A_Impl(); + } + + /** Identifier for the {@link A} type in JSON format. */ + static final String A__TYPE = "A"; + + /** @see #getAc() */ + static final String AC__PROP = "ac"; + + /** @see #getBc() */ + static final String BC__PROP = "bc"; + + /** @see #getC() */ + static final String C__PROP = "c"; + + /** Identifier for the property {@link #getAc()} in binary format. */ + static final int AC__ID = 1; + + /** Identifier for the property {@link #getBc()} in binary format. */ + static final int BC__ID = 2; + + /** Identifier for the property {@link #getC()} in binary format. */ + static final int C__ID = 3; + + A.C getAc(); + + /** + * @see #getAc() + */ + A setAc(A.C value); + + /** + * Checks, whether {@link #getAc()} has a value. + */ + boolean hasAc(); + + B.C getBc(); + + /** + * @see #getBc() + */ + A setBc(B.C value); + + /** + * Checks, whether {@link #getBc()} has a value. + */ + boolean hasBc(); + + C getC(); + + /** + * @see #getC() + */ + A setC(C value); + + /** + * Checks, whether {@link #getC()} has a value. + */ + boolean hasC(); + + @Override + public A registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public A unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + + /** Reads a new instance from the given reader. */ + static A readA(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.innertypeclash.A_Impl result = new test.innertypeclash.A_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static A readA(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + A result = test.innertypeclash.A_Impl.readA_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static A readA(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.innertypeclash.A_Impl.readA_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A_Impl.java new file mode 100644 index 00000000..6abd7a81 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A_Impl.java @@ -0,0 +1,450 @@ +package test.innertypeclash; + +class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements A { + static class C_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements C { + + /** + * Creates a {@link C_Impl} instance. + * + * @see C#create() + */ + protected C_Impl() { + super(); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public C registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public C unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return C__TYPE; + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + // No fields to write, hook for subclasses. + } + + /** Helper for creating an object of type {@link C} from a polymorphic composition. */ + public static C readC_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.innertypeclash.A_Impl.C_Impl result = new C_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + default: in.skipValue(); + } + } + + /** XML element name representing a {@link C} type. */ + public static final String C__XML_ELEMENT = "c"; + + /** Creates a new {@link C} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static C_Impl readC_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + C_Impl result = new C_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + } + + private A.C _ac = null; + + private B.C _bc = null; + + private C _c = null; + + /** + * Creates a {@link A_Impl} instance. + * + * @see A#create() + */ + protected A_Impl() { + super(); + } + + @Override + public final A.C getAc() { + return _ac; + } + + @Override + public A setAc(A.C value) { + internalSetAc(value); + return this; + } + + /** Internal setter for {@link #getAc()} without chain call utility. */ + protected final void internalSetAc(A.C value) { + _listener.beforeSet(this, AC__PROP, value); + _ac = value; + } + + @Override + public final boolean hasAc() { + return _ac != null; + } + + @Override + public final B.C getBc() { + return _bc; + } + + @Override + public A setBc(B.C value) { + internalSetBc(value); + return this; + } + + /** Internal setter for {@link #getBc()} without chain call utility. */ + protected final void internalSetBc(B.C value) { + _listener.beforeSet(this, BC__PROP, value); + _bc = value; + } + + @Override + public final boolean hasBc() { + return _bc != null; + } + + @Override + public final C getC() { + return _c; + } + + @Override + public A setC(C value) { + internalSetC(value); + return this; + } + + /** Internal setter for {@link #getC()} without chain call utility. */ + protected final void internalSetC(C value) { + _listener.beforeSet(this, C__PROP, value); + _c = value; + } + + @Override + public final boolean hasC() { + return _c != null; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public A registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public A unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return A__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + AC__PROP, + BC__PROP, + C__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case AC__PROP: return getAc(); + case BC__PROP: return getBc(); + case C__PROP: return getC(); + default: return A.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case AC__PROP: internalSetAc((A.C) value); break; + case BC__PROP: internalSetBc((B.C) value); break; + case C__PROP: internalSetC((C) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + if (hasAc()) { + out.name(AC__PROP); + getAc().writeTo(out); + } + if (hasBc()) { + out.name(BC__PROP); + getBc().writeTo(out); + } + if (hasC()) { + out.name(C__PROP); + getC().writeTo(out); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case AC__PROP: setAc(test.innertypeclash.A.C.readC(in)); break; + case BC__PROP: setBc(test.innertypeclash.B.C.readC(in)); break; + case C__PROP: setC(test.innertypeclash.A.C.readC(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + if (hasAc()) { + out.name(AC__ID); + getAc().writeTo(out); + } + if (hasBc()) { + out.name(BC__ID); + getBc().writeTo(out); + } + if (hasC()) { + out.name(C__ID); + getC().writeTo(out); + } + } + + /** Helper for creating an object of type {@link A} from a polymorphic composition. */ + public static A readA_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.innertypeclash.A_Impl result = new A_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case AC__ID: setAc(test.innertypeclash.A.C.readC(in)); break; + case BC__ID: setBc(test.innertypeclash.B.C.readC(in)); break; + case C__ID: setC(test.innertypeclash.A.C.readC(in)); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link A} type. */ + public static final String A__XML_ELEMENT = "a"; + + /** XML attribute or element name of a {@link #getAc} property. */ + private static final String AC__XML_ATTR = "ac"; + + /** XML attribute or element name of a {@link #getBc} property. */ + private static final String BC__XML_ATTR = "bc"; + + /** XML attribute or element name of a {@link #getC} property. */ + private static final String C__XML_ATTR = "c"; + + /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static A_Impl readA_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + A_Impl result = new A_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case AC__XML_ATTR: { + setAc(test.innertypeclash.A_Impl.C_Impl.readC_XmlContent(in)); + break; + } + case BC__XML_ATTR: { + setBc(test.innertypeclash.B_Impl.C_Impl.readC_XmlContent(in)); + break; + } + case C__XML_ATTR: { + setC(test.innertypeclash.A_Impl.C_Impl.readC_XmlContent(in)); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java new file mode 100644 index 00000000..2f5c249d --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java @@ -0,0 +1,138 @@ +package test.innertypeclash; + +public interface B extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { + public interface C extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { + + /** + * Creates a {@link C} instance. + */ + static C create() { + return new test.innertypeclash.B_Impl.C_Impl(); + } + + /** Identifier for the {@link C} type in JSON format. */ + static final String C__TYPE = "C"; + + @Override + public C registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public C unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + + /** Reads a new instance from the given reader. */ + static C readC(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.innertypeclash.B_Impl.C_Impl result = new test.innertypeclash.B_Impl.C_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static C readC(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + C result = test.innertypeclash.B_Impl.C_Impl.readC_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link C} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static C readC(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.innertypeclash.B_Impl.C_Impl.readC_XmlContent(in); + } + + } + + /** + * Creates a {@link B} instance. + */ + static B create() { + return new test.innertypeclash.B_Impl(); + } + + /** Identifier for the {@link B} type in JSON format. */ + static final String B__TYPE = "B"; + + /** @see #getAc() */ + static final String AC__PROP = "ac"; + + /** @see #getBc() */ + static final String BC__PROP = "bc"; + + /** @see #getC() */ + static final String C__PROP = "c"; + + /** Identifier for the property {@link #getAc()} in binary format. */ + static final int AC__ID = 1; + + /** Identifier for the property {@link #getBc()} in binary format. */ + static final int BC__ID = 2; + + /** Identifier for the property {@link #getC()} in binary format. */ + static final int C__ID = 3; + + A.C getAc(); + + /** + * @see #getAc() + */ + B setAc(A.C value); + + /** + * Checks, whether {@link #getAc()} has a value. + */ + boolean hasAc(); + + B.C getBc(); + + /** + * @see #getBc() + */ + B setBc(B.C value); + + /** + * Checks, whether {@link #getBc()} has a value. + */ + boolean hasBc(); + + C getC(); + + /** + * @see #getC() + */ + B setC(C value); + + /** + * Checks, whether {@link #getC()} has a value. + */ + boolean hasC(); + + @Override + public B registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public B unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + + /** Reads a new instance from the given reader. */ + static B readB(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.innertypeclash.B_Impl result = new test.innertypeclash.B_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static B readB(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + B result = test.innertypeclash.B_Impl.readB_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static B readB(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.innertypeclash.B_Impl.readB_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B_Impl.java new file mode 100644 index 00000000..bf8291e7 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B_Impl.java @@ -0,0 +1,450 @@ +package test.innertypeclash; + +class B_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements B { + static class C_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements C { + + /** + * Creates a {@link C_Impl} instance. + * + * @see C#create() + */ + protected C_Impl() { + super(); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public C registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public C unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return C__TYPE; + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + // No fields to write, hook for subclasses. + } + + /** Helper for creating an object of type {@link C} from a polymorphic composition. */ + public static C readC_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.innertypeclash.B_Impl.C_Impl result = new C_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + default: in.skipValue(); + } + } + + /** XML element name representing a {@link C} type. */ + public static final String C__XML_ELEMENT = "c"; + + /** Creates a new {@link C} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static C_Impl readC_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + C_Impl result = new C_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + } + + private A.C _ac = null; + + private B.C _bc = null; + + private C _c = null; + + /** + * Creates a {@link B_Impl} instance. + * + * @see B#create() + */ + protected B_Impl() { + super(); + } + + @Override + public final A.C getAc() { + return _ac; + } + + @Override + public B setAc(A.C value) { + internalSetAc(value); + return this; + } + + /** Internal setter for {@link #getAc()} without chain call utility. */ + protected final void internalSetAc(A.C value) { + _listener.beforeSet(this, AC__PROP, value); + _ac = value; + } + + @Override + public final boolean hasAc() { + return _ac != null; + } + + @Override + public final B.C getBc() { + return _bc; + } + + @Override + public B setBc(B.C value) { + internalSetBc(value); + return this; + } + + /** Internal setter for {@link #getBc()} without chain call utility. */ + protected final void internalSetBc(B.C value) { + _listener.beforeSet(this, BC__PROP, value); + _bc = value; + } + + @Override + public final boolean hasBc() { + return _bc != null; + } + + @Override + public final C getC() { + return _c; + } + + @Override + public B setC(C value) { + internalSetC(value); + return this; + } + + /** Internal setter for {@link #getC()} without chain call utility. */ + protected final void internalSetC(C value) { + _listener.beforeSet(this, C__PROP, value); + _c = value; + } + + @Override + public final boolean hasC() { + return _c != null; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public B registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public B unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return B__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + AC__PROP, + BC__PROP, + C__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case AC__PROP: return getAc(); + case BC__PROP: return getBc(); + case C__PROP: return getC(); + default: return B.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case AC__PROP: internalSetAc((A.C) value); break; + case BC__PROP: internalSetBc((B.C) value); break; + case C__PROP: internalSetC((C) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + if (hasAc()) { + out.name(AC__PROP); + getAc().writeTo(out); + } + if (hasBc()) { + out.name(BC__PROP); + getBc().writeTo(out); + } + if (hasC()) { + out.name(C__PROP); + getC().writeTo(out); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case AC__PROP: setAc(test.innertypeclash.A.C.readC(in)); break; + case BC__PROP: setBc(test.innertypeclash.B.C.readC(in)); break; + case C__PROP: setC(test.innertypeclash.B.C.readC(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + if (hasAc()) { + out.name(AC__ID); + getAc().writeTo(out); + } + if (hasBc()) { + out.name(BC__ID); + getBc().writeTo(out); + } + if (hasC()) { + out.name(C__ID); + getC().writeTo(out); + } + } + + /** Helper for creating an object of type {@link B} from a polymorphic composition. */ + public static B readB_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.innertypeclash.B_Impl result = new B_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case AC__ID: setAc(test.innertypeclash.A.C.readC(in)); break; + case BC__ID: setBc(test.innertypeclash.B.C.readC(in)); break; + case C__ID: setC(test.innertypeclash.B.C.readC(in)); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link B} type. */ + public static final String B__XML_ELEMENT = "b"; + + /** XML attribute or element name of a {@link #getAc} property. */ + private static final String AC__XML_ATTR = "ac"; + + /** XML attribute or element name of a {@link #getBc} property. */ + private static final String BC__XML_ATTR = "bc"; + + /** XML attribute or element name of a {@link #getC} property. */ + private static final String C__XML_ATTR = "c"; + + /** Creates a new {@link B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static B_Impl readB_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + B_Impl result = new B_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case AC__XML_ATTR: { + setAc(test.innertypeclash.A_Impl.C_Impl.readC_XmlContent(in)); + break; + } + case BC__XML_ATTR: { + setBc(test.innertypeclash.B_Impl.C_Impl.readC_XmlContent(in)); + break; + } + case C__XML_ATTR: { + setC(test.innertypeclash.B_Impl.C_Impl.readC_XmlContent(in)); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/innertypeclash.proto b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/innertypeclash.proto new file mode 100644 index 00000000..d126531c --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/innertypeclash.proto @@ -0,0 +1,19 @@ +package test.innertypeclash; + +message A { + message C { + } + + A.C ac; + B.C bc; + C c; +} + +message B { + message C { + } + + A.C ac; + B.C bc; + C c; +} \ No newline at end of file diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java new file mode 100644 index 00000000..6d8816ef --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java @@ -0,0 +1,156 @@ +package test.lowercasemessage; + +public interface A extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { + public interface B extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { + + /** + * Creates a {@link B} instance. + */ + static B create() { + return new test.lowercasemessage.A_Impl.B_Impl(); + } + + /** Identifier for the {@link B} type in JSON format. */ + static final String B__TYPE = "b"; + + /** @see #getA1() */ + static final String A_1__PROP = "a1"; + + /** @see #getB1() */ + static final String B_1__PROP = "b1"; + + /** Identifier for the property {@link #getA1()} in binary format. */ + static final int A_1__ID = 1; + + /** Identifier for the property {@link #getB1()} in binary format. */ + static final int B_1__ID = 2; + + A getA1(); + + /** + * @see #getA1() + */ + B setA1(A value); + + /** + * Checks, whether {@link #getA1()} has a value. + */ + boolean hasA1(); + + A.B getB1(); + + /** + * @see #getB1() + */ + B setB1(A.B value); + + /** + * Checks, whether {@link #getB1()} has a value. + */ + boolean hasB1(); + + @Override + public B registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public B unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + + /** Reads a new instance from the given reader. */ + static B readb(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.lowercasemessage.A_Impl.B_Impl result = new test.lowercasemessage.A_Impl.B_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static B readb(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + B result = test.lowercasemessage.A_Impl.B_Impl.readb_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static B readB(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.lowercasemessage.A_Impl.B_Impl.readB_XmlContent(in); + } + + } + + /** + * Creates a {@link A} instance. + */ + static A create() { + return new test.lowercasemessage.A_Impl(); + } + + /** Identifier for the {@link A} type in JSON format. */ + static final String A__TYPE = "a"; + + /** @see #getA1() */ + static final String A_1__PROP = "a1"; + + /** @see #getB1() */ + static final String B_1__PROP = "b1"; + + /** Identifier for the property {@link #getA1()} in binary format. */ + static final int A_1__ID = 1; + + /** Identifier for the property {@link #getB1()} in binary format. */ + static final int B_1__ID = 2; + + A getA1(); + + /** + * @see #getA1() + */ + A setA1(A value); + + /** + * Checks, whether {@link #getA1()} has a value. + */ + boolean hasA1(); + + A.B getB1(); + + /** + * @see #getB1() + */ + A setB1(A.B value); + + /** + * Checks, whether {@link #getB1()} has a value. + */ + boolean hasB1(); + + @Override + public A registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public A unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + + /** Reads a new instance from the given reader. */ + static A reada(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.lowercasemessage.A_Impl result = new test.lowercasemessage.A_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static A reada(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + A result = test.lowercasemessage.A_Impl.reada_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static A readA(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.lowercasemessage.A_Impl.readA_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A_Impl.java new file mode 100644 index 00000000..8735554d --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A_Impl.java @@ -0,0 +1,526 @@ +package test.lowercasemessage; + +class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements A { + static class B_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements B { + + private A _a1 = null; + + private A.B _b1 = null; + + /** + * Creates a {@link B_Impl} instance. + * + * @see B#create() + */ + protected B_Impl() { + super(); + } + + @Override + public final A getA1() { + return _a1; + } + + @Override + public B setA1(A value) { + internalSetA1(value); + return this; + } + + /** Internal setter for {@link #getA1()} without chain call utility. */ + protected final void internalSetA1(A value) { + _listener.beforeSet(this, A_1__PROP, value); + _a1 = value; + } + + @Override + public final boolean hasA1() { + return _a1 != null; + } + + @Override + public final A.B getB1() { + return _b1; + } + + @Override + public B setB1(A.B value) { + internalSetB1(value); + return this; + } + + /** Internal setter for {@link #getB1()} without chain call utility. */ + protected final void internalSetB1(A.B value) { + _listener.beforeSet(this, B_1__PROP, value); + _b1 = value; + } + + @Override + public final boolean hasB1() { + return _b1 != null; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public B registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public B unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return B__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + A_1__PROP, + B_1__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case A_1__PROP: return getA1(); + case B_1__PROP: return getB1(); + default: return B.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case A_1__PROP: internalSetA1((A) value); break; + case B_1__PROP: internalSetB1((A.B) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + if (hasA1()) { + out.name(A_1__PROP); + getA1().writeTo(out); + } + if (hasB1()) { + out.name(B_1__PROP); + getB1().writeTo(out); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case A_1__PROP: setA1(test.lowercasemessage.A.reada(in)); break; + case B_1__PROP: setB1(test.lowercasemessage.A.B.readb(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + if (hasA1()) { + out.name(A_1__ID); + getA1().writeTo(out); + } + if (hasB1()) { + out.name(B_1__ID); + getB1().writeTo(out); + } + } + + /** Helper for creating an object of type {@link B} from a polymorphic composition. */ + public static B readb_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.lowercasemessage.A_Impl.B_Impl result = new B_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case A_1__ID: setA1(test.lowercasemessage.A.reada(in)); break; + case B_1__ID: setB1(test.lowercasemessage.A.B.readb(in)); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link B} type. */ + public static final String B__XML_ELEMENT = "b"; + + /** XML attribute or element name of a {@link #getA1} property. */ + private static final String A_1__XML_ATTR = "a-1"; + + /** XML attribute or element name of a {@link #getB1} property. */ + private static final String B_1__XML_ATTR = "b-1"; + + /** Creates a new {@link B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static B_Impl readB_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + B_Impl result = new B_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case A_1__XML_ATTR: { + setA1(test.lowercasemessage.A_Impl.readA_XmlContent(in)); + break; + } + case B_1__XML_ATTR: { + setB1(test.lowercasemessage.A_Impl.B_Impl.readB_XmlContent(in)); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + } + + private A _a1 = null; + + private A.B _b1 = null; + + /** + * Creates a {@link A_Impl} instance. + * + * @see A#create() + */ + protected A_Impl() { + super(); + } + + @Override + public final A getA1() { + return _a1; + } + + @Override + public A setA1(A value) { + internalSetA1(value); + return this; + } + + /** Internal setter for {@link #getA1()} without chain call utility. */ + protected final void internalSetA1(A value) { + _listener.beforeSet(this, A_1__PROP, value); + _a1 = value; + } + + @Override + public final boolean hasA1() { + return _a1 != null; + } + + @Override + public final A.B getB1() { + return _b1; + } + + @Override + public A setB1(A.B value) { + internalSetB1(value); + return this; + } + + /** Internal setter for {@link #getB1()} without chain call utility. */ + protected final void internalSetB1(A.B value) { + _listener.beforeSet(this, B_1__PROP, value); + _b1 = value; + } + + @Override + public final boolean hasB1() { + return _b1 != null; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public A registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public A unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return A__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + A_1__PROP, + B_1__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case A_1__PROP: return getA1(); + case B_1__PROP: return getB1(); + default: return A.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case A_1__PROP: internalSetA1((A) value); break; + case B_1__PROP: internalSetB1((A.B) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + if (hasA1()) { + out.name(A_1__PROP); + getA1().writeTo(out); + } + if (hasB1()) { + out.name(B_1__PROP); + getB1().writeTo(out); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case A_1__PROP: setA1(test.lowercasemessage.A.reada(in)); break; + case B_1__PROP: setB1(test.lowercasemessage.A.B.readb(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + if (hasA1()) { + out.name(A_1__ID); + getA1().writeTo(out); + } + if (hasB1()) { + out.name(B_1__ID); + getB1().writeTo(out); + } + } + + /** Helper for creating an object of type {@link A} from a polymorphic composition. */ + public static A reada_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.lowercasemessage.A_Impl result = new A_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case A_1__ID: setA1(test.lowercasemessage.A.reada(in)); break; + case B_1__ID: setB1(test.lowercasemessage.A.B.readb(in)); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link A} type. */ + public static final String A__XML_ELEMENT = "a"; + + /** XML attribute or element name of a {@link #getA1} property. */ + private static final String A_1__XML_ATTR = "a-1"; + + /** XML attribute or element name of a {@link #getB1} property. */ + private static final String B_1__XML_ATTR = "b-1"; + + /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static A_Impl readA_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + A_Impl result = new A_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case A_1__XML_ATTR: { + setA1(test.lowercasemessage.A_Impl.readA_XmlContent(in)); + break; + } + case B_1__XML_ATTR: { + setB1(test.lowercasemessage.A_Impl.B_Impl.readB_XmlContent(in)); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/lowercasemessage.proto b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/lowercasemessage.proto new file mode 100644 index 00000000..8404eae5 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/lowercasemessage.proto @@ -0,0 +1,14 @@ +package test.lowercasemessage; + +@TagName("x") +message a { + + @TagName("y") + message b { + a a1; + a.b b1; + } + + a a1; + a.b b1; +} \ No newline at end of file diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java index bb0c1156..4c417506 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java @@ -13,10 +13,10 @@ static MyMessage create() { static final String MY_MESSAGE__TYPE = "MyMessage"; /** @see #getProjects() */ - static final String PROJECTS = "projects"; + static final String PROJECTS__PROP = "projects"; /** @see #getRating() */ - static final String RATING = "rating"; + static final String RATING__PROP = "rating"; /** Identifier for the property {@link #getProjects()} in binary format. */ static final int PROJECTS__ID = 3; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage_Impl.java index 3914a858..39529606 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage_Impl.java @@ -118,8 +118,8 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - PROJECTS, - RATING)); + PROJECTS__PROP, + RATING__PROP)); @Override public java.util.List properties() { @@ -129,8 +129,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case PROJECTS: return getProjects(); - case RATING: return getRating(); + case PROJECTS__PROP: return getProjects(); + case RATING__PROP: return getRating(); default: return MyMessage.super.get(field); } } @@ -138,8 +138,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case PROJECTS: internalSetProjects((java.util.Map) value); break; - case RATING: internalSetRating((java.util.Map) value); break; + case PROJECTS__PROP: internalSetProjects((java.util.Map) value); break; + case RATING__PROP: internalSetRating((java.util.Map) value); break; } } @@ -151,14 +151,14 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(PROJECTS); + out.name(PROJECTS__PROP); out.beginObject(); for (java.util.Map.Entry entry : getProjects().entrySet()) { out.name(entry.getKey()); entry.getValue().writeTo(out); } out.endObject(); - out.name(RATING); + out.name(RATING__PROP); out.beginArray(); for (java.util.Map.Entry entry : getRating().entrySet()) { out.beginObject(); @@ -174,7 +174,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case PROJECTS: { + case PROJECTS__PROP: { in.beginObject(); while (in.hasNext()) { putProject(in.nextName(), test.maptype.data.Project.readProject(in)); @@ -182,7 +182,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t in.endObject(); break; } - case RATING: { + case RATING__PROP: { in.beginArray(); while (in.hasNext()) { in.beginObject(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java index 8951216c..795d5bba 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java @@ -13,10 +13,10 @@ static Project create() { static final String PROJECT__TYPE = "Project"; /** @see #getName() */ - static final String NAME = "name"; + static final String NAME__PROP = "name"; /** @see #getCost() */ - static final String COST = "cost"; + static final String COST__PROP = "cost"; /** Identifier for the property {@link #getName()} in binary format. */ static final int NAME__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project_Impl.java index f2555f01..44bc6e69 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project_Impl.java @@ -28,7 +28,7 @@ public Project setName(String value) { /** Internal setter for {@link #getName()} without chain call utility. */ protected final void internalSetName(String value) { - _listener.beforeSet(this, NAME, value); + _listener.beforeSet(this, NAME__PROP, value); _name = value; } @@ -45,7 +45,7 @@ public Project setCost(double value) { /** Internal setter for {@link #getCost()} without chain call utility. */ protected final void internalSetCost(double value) { - _listener.beforeSet(this, COST, value); + _listener.beforeSet(this, COST__PROP, value); _cost = value; } @@ -78,8 +78,8 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - NAME, - COST)); + NAME__PROP, + COST__PROP)); @Override public java.util.List properties() { @@ -89,8 +89,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case NAME: return getName(); - case COST: return getCost(); + case NAME__PROP: return getName(); + case COST__PROP: return getCost(); default: return Project.super.get(field); } } @@ -98,8 +98,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case NAME: internalSetName((String) value); break; - case COST: internalSetCost((double) value); break; + case NAME__PROP: internalSetName((String) value); break; + case COST__PROP: internalSetCost((double) value); break; } } @@ -111,17 +111,17 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(NAME); + out.name(NAME__PROP); out.value(getName()); - out.name(COST); + out.name(COST__PROP); out.value(getCost()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case NAME: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; - case COST: setCost(in.nextDouble()); break; + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case COST__PROP: setCost(in.nextDouble()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java index a90e464e..155047fc 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java @@ -14,13 +14,13 @@ static Result create() { static final String RESULT__TYPE = "Result"; /** @see #getUrl() */ - static final String URL = "url"; + static final String URL__PROP = "url"; /** @see #getTitle() */ - static final String TITLE = "title"; + static final String TITLE__PROP = "title"; /** @see #getSnippets() */ - static final String SNIPPETS = "snippets"; + static final String SNIPPETS__PROP = "snippets"; /** Identifier for the property {@link #getUrl()} in binary format. */ static final int URL__ID = 1; @@ -103,7 +103,7 @@ static SearchResponse create() { static final String SEARCH_RESPONSE__TYPE = "SearchResponse"; /** @see #getResults() */ - static final String RESULTS = "results"; + static final String RESULTS__PROP = "results"; /** Identifier for the property {@link #getResults()} in binary format. */ static final int RESULTS__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse_Impl.java index 9da74ac1..33f26f52 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse_Impl.java @@ -10,12 +10,12 @@ static class Result_Impl extends de.haumacher.msgbuf.data.AbstractDataObject imp private final java.util.List _snippets = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, String element) { - _listener.beforeAdd(Result_Impl.this, SNIPPETS, index, element); + _listener.beforeAdd(Result_Impl.this, SNIPPETS__PROP, index, element); } @Override protected void afterRemove(int index, String element) { - _listener.afterRemove(Result_Impl.this, SNIPPETS, index, element); + _listener.afterRemove(Result_Impl.this, SNIPPETS__PROP, index, element); } }; @@ -41,7 +41,7 @@ public Result setUrl(String value) { /** Internal setter for {@link #getUrl()} without chain call utility. */ protected final void internalSetUrl(String value) { - _listener.beforeSet(this, URL, value); + _listener.beforeSet(this, URL__PROP, value); _url = value; } @@ -58,7 +58,7 @@ public Result setTitle(String value) { /** Internal setter for {@link #getTitle()} without chain call utility. */ protected final void internalSetTitle(String value) { - _listener.beforeSet(this, TITLE, value); + _listener.beforeSet(this, TITLE__PROP, value); _title = value; } @@ -124,9 +124,9 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - URL, - TITLE, - SNIPPETS)); + URL__PROP, + TITLE__PROP, + SNIPPETS__PROP)); @Override public java.util.List properties() { @@ -136,9 +136,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case URL: return getUrl(); - case TITLE: return getTitle(); - case SNIPPETS: return getSnippets(); + case URL__PROP: return getUrl(); + case TITLE__PROP: return getTitle(); + case SNIPPETS__PROP: return getSnippets(); default: return Result.super.get(field); } } @@ -146,9 +146,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case URL: internalSetUrl((String) value); break; - case TITLE: internalSetTitle((String) value); break; - case SNIPPETS: internalSetSnippets(de.haumacher.msgbuf.util.Conversions.asList(String.class, value)); break; + case URL__PROP: internalSetUrl((String) value); break; + case TITLE__PROP: internalSetTitle((String) value); break; + case SNIPPETS__PROP: internalSetSnippets(de.haumacher.msgbuf.util.Conversions.asList(String.class, value)); break; } } @@ -160,11 +160,11 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(URL); + out.name(URL__PROP); out.value(getUrl()); - out.name(TITLE); + out.name(TITLE__PROP); out.value(getTitle()); - out.name(SNIPPETS); + out.name(SNIPPETS__PROP); out.beginArray(); for (String x : getSnippets()) { out.value(x); @@ -175,9 +175,9 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case URL: setUrl(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; - case TITLE: setTitle(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; - case SNIPPETS: { + case URL__PROP: setUrl(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case TITLE__PROP: setTitle(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case SNIPPETS__PROP: { in.beginArray(); while (in.hasNext()) { addSnippet(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); @@ -347,12 +347,12 @@ protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream private final java.util.List _results = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, Result element) { - _listener.beforeAdd(SearchResponse_Impl.this, RESULTS, index, element); + _listener.beforeAdd(SearchResponse_Impl.this, RESULTS__PROP, index, element); } @Override protected void afterRemove(int index, Result element) { - _listener.afterRemove(SearchResponse_Impl.this, RESULTS, index, element); + _listener.afterRemove(SearchResponse_Impl.this, RESULTS__PROP, index, element); } }; @@ -428,7 +428,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - RESULTS)); + RESULTS__PROP)); @Override public java.util.List properties() { @@ -438,7 +438,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case RESULTS: return getResults(); + case RESULTS__PROP: return getResults(); default: return SearchResponse.super.get(field); } } @@ -446,7 +446,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case RESULTS: internalSetResults(de.haumacher.msgbuf.util.Conversions.asList(Result.class, value)); break; + case RESULTS__PROP: internalSetResults(de.haumacher.msgbuf.util.Conversions.asList(Result.class, value)); break; } } @@ -458,7 +458,7 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(RESULTS); + out.name(RESULTS__PROP); out.beginArray(); for (Result x : getResults()) { x.writeTo(out); @@ -469,7 +469,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case RESULTS: { + case RESULTS__PROP: { in.beginArray(); while (in.hasNext()) { addResult(test.nested.data.SearchResponse.Result.readResult(in)); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java index dc100bc6..4e4e8a58 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java @@ -16,13 +16,13 @@ public static Car create() { public static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ - public static final String WHEEL_1 = "wheel1"; + public static final String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - public static final String WHEEL_2 = "wheel2"; + public static final String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - public static final String BODY = "body"; + public static final String BODY__PROP = "body"; /** Identifier for the {@link Car} type in binary format. */ static final int CAR__TYPE_ID = 4; @@ -73,7 +73,7 @@ public Car setWheel1(Circle value) { /** Internal setter for {@link #getWheel1()} without chain call utility. */ protected final void internalSetWheel1(Circle value) { - _listener.beforeSet(this, WHEEL_1, value); + _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; } @@ -101,7 +101,7 @@ public Car setWheel2(Circle value) { /** Internal setter for {@link #getWheel2()} without chain call utility. */ protected final void internalSetWheel2(Circle value) { - _listener.beforeSet(this, WHEEL_2, value); + _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; } @@ -129,7 +129,7 @@ public Car setBody(Rectangle value) { /** Internal setter for {@link #getBody()} without chain call utility. */ protected final void internalSetBody(Rectangle value) { - _listener.beforeSet(this, BODY, value); + _listener.beforeSet(this, BODY__PROP, value); _body = value; } @@ -159,9 +159,9 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WHEEL_1, - WHEEL_2, - BODY)); + WHEEL_1__PROP, + WHEEL_2__PROP, + BODY__PROP)); @Override public java.util.List properties() { @@ -171,9 +171,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WHEEL_1: return getWheel1(); - case WHEEL_2: return getWheel2(); - case BODY: return getBody(); + case WHEEL_1__PROP: return getWheel1(); + case WHEEL_2__PROP: return getWheel2(); + case BODY__PROP: return getBody(); default: return super.get(field); } } @@ -181,9 +181,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1: internalSetWheel1((Circle) value); break; - case WHEEL_2: internalSetWheel2((Circle) value); break; - case BODY: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; + case BODY__PROP: internalSetBody((Rectangle) value); break; default: super.set(field, value); break; } } @@ -199,15 +199,15 @@ public static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); if (hasWheel1()) { - out.name(WHEEL_1); + out.name(WHEEL_1__PROP); getWheel1().writeContent(out); } if (hasWheel2()) { - out.name(WHEEL_2); + out.name(WHEEL_2__PROP); getWheel2().writeContent(out); } if (hasBody()) { - out.name(BODY); + out.name(BODY__PROP); getBody().writeContent(out); } } @@ -215,9 +215,9 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WHEEL_1: setWheel1(test.nointerfaces.Circle.readCircle(in)); break; - case WHEEL_2: setWheel2(test.nointerfaces.Circle.readCircle(in)); break; - case BODY: setBody(test.nointerfaces.Rectangle.readRectangle(in)); break; + case WHEEL_1__PROP: setWheel1(test.nointerfaces.Circle.readCircle(in)); break; + case WHEEL_2__PROP: setWheel2(test.nointerfaces.Circle.readCircle(in)); break; + case BODY__PROP: setBody(test.nointerfaces.Rectangle.readRectangle(in)); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java index a49114f5..960f74e5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java @@ -16,7 +16,7 @@ public static Circle create() { public static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ - public static final String RADIUS = "r"; + public static final String RADIUS__PROP = "r"; /** Identifier for the {@link Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; @@ -57,7 +57,7 @@ public Circle setRadius(int value) { /** Internal setter for {@link #getRadius()} without chain call utility. */ protected final void internalSetRadius(int value) { - _listener.beforeSet(this, RADIUS, value); + _listener.beforeSet(this, RADIUS__PROP, value); _radius = value; } @@ -80,7 +80,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - RADIUS)); + RADIUS__PROP)); @Override public java.util.List properties() { @@ -90,7 +90,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case RADIUS: return getRadius(); + case RADIUS__PROP: return getRadius(); default: return super.get(field); } } @@ -98,7 +98,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case RADIUS: internalSetRadius((int) value); break; + case RADIUS__PROP: internalSetRadius((int) value); break; default: super.set(field, value); break; } } @@ -113,14 +113,14 @@ public static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws j @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(RADIUS); + out.name(RADIUS__PROP); out.value(getRadius()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case RADIUS: setRadius(in.nextInt()); break; + case RADIUS__PROP: setRadius(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java index a45b9e0b..dba2df73 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java @@ -16,7 +16,7 @@ public static Group create() { public static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ - public static final String SHAPES = "shapes"; + public static final String SHAPES__PROP = "shapes"; /** Identifier for the {@link Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; @@ -27,12 +27,12 @@ public static Group create() { private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, Shape element) { - _listener.beforeAdd(Group.this, SHAPES, index, element); + _listener.beforeAdd(Group.this, SHAPES__PROP, index, element); } @Override protected void afterRemove(int index, Shape element) { - _listener.afterRemove(Group.this, SHAPES, index, element); + _listener.afterRemove(Group.this, SHAPES__PROP, index, element); } }; @@ -115,7 +115,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - SHAPES)); + SHAPES__PROP)); @Override public java.util.List properties() { @@ -125,7 +125,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case SHAPES: return getShapes(); + case SHAPES__PROP: return getShapes(); default: return super.get(field); } } @@ -133,7 +133,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; default: super.set(field, value); break; } } @@ -148,7 +148,7 @@ public static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws jav @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(SHAPES); + out.name(SHAPES__PROP); out.beginArray(); for (Shape x : getShapes()) { x.writeTo(out); @@ -159,7 +159,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case SHAPES: { + case SHAPES__PROP: { in.beginArray(); while (in.hasNext()) { addShape(test.nointerfaces.Shape.readShape(in)); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java index 4f8da1e4..0c740792 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java @@ -16,10 +16,10 @@ public static Rectangle create() { public static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ - public static final String WIDTH = "w"; + public static final String WIDTH__PROP = "w"; /** @see #getHeight() */ - public static final String HEIGHT = "h"; + public static final String HEIGHT__PROP = "h"; /** Identifier for the {@link Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; @@ -71,7 +71,7 @@ public Rectangle setWidth(int value) { /** Internal setter for {@link #getWidth()} without chain call utility. */ protected final void internalSetWidth(int value) { - _listener.beforeSet(this, WIDTH, value); + _listener.beforeSet(this, WIDTH__PROP, value); _width = value; } @@ -94,7 +94,7 @@ public Rectangle setHeight(int value) { /** Internal setter for {@link #getHeight()} without chain call utility. */ protected final void internalSetHeight(int value) { - _listener.beforeSet(this, HEIGHT, value); + _listener.beforeSet(this, HEIGHT__PROP, value); _height = value; } @@ -117,8 +117,8 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WIDTH, - HEIGHT)); + WIDTH__PROP, + HEIGHT__PROP)); @Override public java.util.List properties() { @@ -128,8 +128,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WIDTH: return getWidth(); - case HEIGHT: return getHeight(); + case WIDTH__PROP: return getWidth(); + case HEIGHT__PROP: return getHeight(); default: return super.get(field); } } @@ -137,8 +137,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WIDTH: internalSetWidth((int) value); break; - case HEIGHT: internalSetHeight((int) value); break; + case WIDTH__PROP: internalSetWidth((int) value); break; + case HEIGHT__PROP: internalSetHeight((int) value); break; default: super.set(field, value); break; } } @@ -153,17 +153,17 @@ public static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) th @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(WIDTH); + out.name(WIDTH__PROP); out.value(getWidth()); - out.name(HEIGHT); + out.name(HEIGHT__PROP); out.value(getHeight()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WIDTH: setWidth(in.nextInt()); break; - case HEIGHT: setHeight(in.nextInt()); break; + case WIDTH__PROP: setWidth(in.nextInt()); break; + case HEIGHT__PROP: setHeight(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java index 05ac46cc..bfa6eb74 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java @@ -35,10 +35,10 @@ public interface Visitor extends AtomicShape.Visitor PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - X_COORDINATE, - Y_COORDINATE)); + X_COORDINATE__PROP, + Y_COORDINATE__PROP)); @Override public java.util.List properties() { @@ -137,8 +137,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case X_COORDINATE: return getXCoordinate(); - case Y_COORDINATE: return getYCoordinate(); + case X_COORDINATE__PROP: return getXCoordinate(); + case Y_COORDINATE__PROP: return getYCoordinate(); default: return null; } } @@ -146,8 +146,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case X_COORDINATE: internalSetXCoordinate((int) value); break; - case Y_COORDINATE: internalSetYCoordinate((int) value); break; + case X_COORDINATE__PROP: internalSetXCoordinate((int) value); break; + case Y_COORDINATE__PROP: internalSetYCoordinate((int) value); break; } } @@ -178,17 +178,17 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(X_COORDINATE); + out.name(X_COORDINATE__PROP); out.value(getXCoordinate()); - out.name(Y_COORDINATE); + out.name(Y_COORDINATE__PROP); out.value(getYCoordinate()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case X_COORDINATE: setXCoordinate(in.nextInt()); break; - case Y_COORDINATE: setYCoordinate(in.nextInt()); break; + case X_COORDINATE__PROP: setXCoordinate(in.nextInt()); break; + case Y_COORDINATE__PROP: setYCoordinate(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java index 9e101afd..c553cb8d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java @@ -16,13 +16,13 @@ static Car create() { static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ - static final String WHEEL_1 = "wheel1"; + static final String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - static final String WHEEL_2 = "wheel2"; + static final String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - static final String BODY = "body"; + static final String BODY__PROP = "body"; /** Identifier for the {@link Car} type in binary format. */ static final int CAR__TYPE_ID = 4; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car_Impl.java index 081c4eba..8f150fb4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car_Impl.java @@ -38,7 +38,7 @@ public Car setWheel1(Circle value) { /** Internal setter for {@link #getWheel1()} without chain call utility. */ protected final void internalSetWheel1(Circle value) { - _listener.beforeSet(this, WHEEL_1, value); + _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; } @@ -60,7 +60,7 @@ public Car setWheel2(Circle value) { /** Internal setter for {@link #getWheel2()} without chain call utility. */ protected final void internalSetWheel2(Circle value) { - _listener.beforeSet(this, WHEEL_2, value); + _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; } @@ -82,7 +82,7 @@ public Car setBody(Rectangle value) { /** Internal setter for {@link #getBody()} without chain call utility. */ protected final void internalSetBody(Rectangle value) { - _listener.beforeSet(this, BODY, value); + _listener.beforeSet(this, BODY__PROP, value); _body = value; } @@ -110,9 +110,9 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WHEEL_1, - WHEEL_2, - BODY)); + WHEEL_1__PROP, + WHEEL_2__PROP, + BODY__PROP)); @Override public java.util.List properties() { @@ -122,9 +122,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WHEEL_1: return getWheel1(); - case WHEEL_2: return getWheel2(); - case BODY: return getBody(); + case WHEEL_1__PROP: return getWheel1(); + case WHEEL_2__PROP: return getWheel2(); + case BODY__PROP: return getBody(); default: return super.get(field); } } @@ -132,9 +132,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1: internalSetWheel1((Circle) value); break; - case WHEEL_2: internalSetWheel2((Circle) value); break; - case BODY: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; + case BODY__PROP: internalSetBody((Rectangle) value); break; default: super.set(field, value); break; } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java index 854f0982..1e262fdc 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java @@ -16,7 +16,7 @@ static Circle create() { static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ - static final String RADIUS = "r"; + static final String RADIUS__PROP = "r"; /** Identifier for the {@link Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle_Impl.java index d03c017d..a1e16e63 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle_Impl.java @@ -34,7 +34,7 @@ public Circle setRadius(int value) { /** Internal setter for {@link #getRadius()} without chain call utility. */ protected final void internalSetRadius(int value) { - _listener.beforeSet(this, RADIUS, value); + _listener.beforeSet(this, RADIUS__PROP, value); _radius = value; } @@ -57,7 +57,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - RADIUS)); + RADIUS__PROP)); @Override public java.util.List properties() { @@ -67,7 +67,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case RADIUS: return getRadius(); + case RADIUS__PROP: return getRadius(); default: return super.get(field); } } @@ -75,7 +75,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case RADIUS: internalSetRadius((int) value); break; + case RADIUS__PROP: internalSetRadius((int) value); break; default: super.set(field, value); break; } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java index 204c4477..bc6b7b44 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java @@ -16,7 +16,7 @@ static Group create() { static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ - static final String SHAPES = "shapes"; + static final String SHAPES__PROP = "shapes"; /** Identifier for the {@link Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group_Impl.java index 298c51e8..3897d1c7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group_Impl.java @@ -8,12 +8,12 @@ class Group_Impl extends Shape_Impl implements Group { private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, Shape element) { - _listener.beforeAdd(Group_Impl.this, SHAPES, index, element); + _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); } @Override protected void afterRemove(int index, Shape element) { - _listener.afterRemove(Group_Impl.this, SHAPES, index, element); + _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } }; @@ -84,7 +84,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - SHAPES)); + SHAPES__PROP)); @Override public java.util.List properties() { @@ -94,7 +94,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case SHAPES: return getShapes(); + case SHAPES__PROP: return getShapes(); default: return super.get(field); } } @@ -102,7 +102,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; default: super.set(field, value); break; } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java index c67ac52f..9f19a9f5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java @@ -16,10 +16,10 @@ static Rectangle create() { static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ - static final String WIDTH = "w"; + static final String WIDTH__PROP = "w"; /** @see #getHeight() */ - static final String HEIGHT = "h"; + static final String HEIGHT__PROP = "h"; /** Identifier for the {@link Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle_Impl.java index 3dd19bfb..26ce9756 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle_Impl.java @@ -36,7 +36,7 @@ public Rectangle setWidth(int value) { /** Internal setter for {@link #getWidth()} without chain call utility. */ protected final void internalSetWidth(int value) { - _listener.beforeSet(this, WIDTH, value); + _listener.beforeSet(this, WIDTH__PROP, value); _width = value; } @@ -53,7 +53,7 @@ public Rectangle setHeight(int value) { /** Internal setter for {@link #getHeight()} without chain call utility. */ protected final void internalSetHeight(int value) { - _listener.beforeSet(this, HEIGHT, value); + _listener.beforeSet(this, HEIGHT__PROP, value); _height = value; } @@ -76,8 +76,8 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WIDTH, - HEIGHT)); + WIDTH__PROP, + HEIGHT__PROP)); @Override public java.util.List properties() { @@ -87,8 +87,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WIDTH: return getWidth(); - case HEIGHT: return getHeight(); + case WIDTH__PROP: return getWidth(); + case HEIGHT__PROP: return getHeight(); default: return super.get(field); } } @@ -96,8 +96,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WIDTH: internalSetWidth((int) value); break; - case HEIGHT: internalSetHeight((int) value); break; + case WIDTH__PROP: internalSetWidth((int) value); break; + case HEIGHT__PROP: internalSetHeight((int) value); break; default: super.set(field, value); break; } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java index 909b049c..48a3591f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java @@ -35,10 +35,10 @@ public interface Visitor extends AtomicShape.Visitor PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - X_COORDINATE, - Y_COORDINATE)); + X_COORDINATE__PROP, + Y_COORDINATE__PROP)); @Override public java.util.List properties() { @@ -88,8 +88,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case X_COORDINATE: return getXCoordinate(); - case Y_COORDINATE: return getYCoordinate(); + case X_COORDINATE__PROP: return getXCoordinate(); + case Y_COORDINATE__PROP: return getYCoordinate(); default: return Shape.super.get(field); } } @@ -97,8 +97,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case X_COORDINATE: internalSetXCoordinate((int) value); break; - case Y_COORDINATE: internalSetYCoordinate((int) value); break; + case X_COORDINATE__PROP: internalSetXCoordinate((int) value); break; + case Y_COORDINATE__PROP: internalSetYCoordinate((int) value); break; } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java index 8e41cd9c..4adff9e9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java @@ -16,13 +16,13 @@ static Car create() { static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ - static final String WHEEL_1 = "wheel1"; + static final String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - static final String WHEEL_2 = "wheel2"; + static final String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - static final String BODY = "body"; + static final String BODY__PROP = "body"; /** Identifier for the {@link Car} type in binary format. */ static final int CAR__TYPE_ID = 4; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car_Impl.java index 8dd2c51a..d9f2d67e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car_Impl.java @@ -107,9 +107,9 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WHEEL_1, - WHEEL_2, - BODY)); + WHEEL_1__PROP, + WHEEL_2__PROP, + BODY__PROP)); @Override public java.util.List properties() { @@ -119,9 +119,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WHEEL_1: return getWheel1(); - case WHEEL_2: return getWheel2(); - case BODY: return getBody(); + case WHEEL_1__PROP: return getWheel1(); + case WHEEL_2__PROP: return getWheel2(); + case BODY__PROP: return getBody(); default: return super.get(field); } } @@ -129,9 +129,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1: internalSetWheel1((Circle) value); break; - case WHEEL_2: internalSetWheel2((Circle) value); break; - case BODY: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; + case BODY__PROP: internalSetBody((Rectangle) value); break; default: super.set(field, value); break; } } @@ -140,15 +140,15 @@ public void set(String field, Object value) { protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); if (hasWheel1()) { - out.name(WHEEL_1); + out.name(WHEEL_1__PROP); getWheel1().writeContent(out); } if (hasWheel2()) { - out.name(WHEEL_2); + out.name(WHEEL_2__PROP); getWheel2().writeContent(out); } if (hasBody()) { - out.name(BODY); + out.name(BODY__PROP); getBody().writeContent(out); } } @@ -156,9 +156,9 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WHEEL_1: setWheel1(test.nolistener.Circle.readCircle(in)); break; - case WHEEL_2: setWheel2(test.nolistener.Circle.readCircle(in)); break; - case BODY: setBody(test.nolistener.Rectangle.readRectangle(in)); break; + case WHEEL_1__PROP: setWheel1(test.nolistener.Circle.readCircle(in)); break; + case WHEEL_2__PROP: setWheel2(test.nolistener.Circle.readCircle(in)); break; + case BODY__PROP: setBody(test.nolistener.Rectangle.readRectangle(in)); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java index cda30118..0a55e0a8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java @@ -16,7 +16,7 @@ static Circle create() { static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ - static final String RADIUS = "r"; + static final String RADIUS__PROP = "r"; /** Identifier for the {@link Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle_Impl.java index d94e0574..0bfb222a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle_Impl.java @@ -56,7 +56,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - RADIUS)); + RADIUS__PROP)); @Override public java.util.List properties() { @@ -66,7 +66,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case RADIUS: return getRadius(); + case RADIUS__PROP: return getRadius(); default: return super.get(field); } } @@ -74,7 +74,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case RADIUS: internalSetRadius((int) value); break; + case RADIUS__PROP: internalSetRadius((int) value); break; default: super.set(field, value); break; } } @@ -82,14 +82,14 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(RADIUS); + out.name(RADIUS__PROP); out.value(getRadius()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case RADIUS: setRadius(in.nextInt()); break; + case RADIUS__PROP: setRadius(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java index 65e44b0f..cf875e91 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java @@ -16,7 +16,7 @@ static Group create() { static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ - static final String SHAPES = "shapes"; + static final String SHAPES__PROP = "shapes"; /** Identifier for the {@link Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group_Impl.java index dfeb258a..f7b27caa 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group_Impl.java @@ -74,7 +74,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - SHAPES)); + SHAPES__PROP)); @Override public java.util.List properties() { @@ -84,7 +84,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case SHAPES: return getShapes(); + case SHAPES__PROP: return getShapes(); default: return super.get(field); } } @@ -92,7 +92,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; default: super.set(field, value); break; } } @@ -100,7 +100,7 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(SHAPES); + out.name(SHAPES__PROP); out.beginArray(); for (Shape x : getShapes()) { x.writeTo(out); @@ -111,7 +111,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case SHAPES: { + case SHAPES__PROP: { in.beginArray(); while (in.hasNext()) { addShape(test.nolistener.Shape.readShape(in)); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java index 11c212d3..a64424ba 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java @@ -16,10 +16,10 @@ static Rectangle create() { static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ - static final String WIDTH = "w"; + static final String WIDTH__PROP = "w"; /** @see #getHeight() */ - static final String HEIGHT = "h"; + static final String HEIGHT__PROP = "h"; /** Identifier for the {@link Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle_Impl.java index 59144a96..125b06ff 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle_Impl.java @@ -74,8 +74,8 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WIDTH, - HEIGHT)); + WIDTH__PROP, + HEIGHT__PROP)); @Override public java.util.List properties() { @@ -85,8 +85,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WIDTH: return getWidth(); - case HEIGHT: return getHeight(); + case WIDTH__PROP: return getWidth(); + case HEIGHT__PROP: return getHeight(); default: return super.get(field); } } @@ -94,8 +94,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WIDTH: internalSetWidth((int) value); break; - case HEIGHT: internalSetHeight((int) value); break; + case WIDTH__PROP: internalSetWidth((int) value); break; + case HEIGHT__PROP: internalSetHeight((int) value); break; default: super.set(field, value); break; } } @@ -103,17 +103,17 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(WIDTH); + out.name(WIDTH__PROP); out.value(getWidth()); - out.name(HEIGHT); + out.name(HEIGHT__PROP); out.value(getHeight()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WIDTH: setWidth(in.nextInt()); break; - case HEIGHT: setHeight(in.nextInt()); break; + case WIDTH__PROP: setWidth(in.nextInt()); break; + case HEIGHT__PROP: setHeight(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java index fddfab4f..ecd016f5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java @@ -35,10 +35,10 @@ public interface Visitor extends AtomicShape.Visitor PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - X_COORDINATE, - Y_COORDINATE)); + X_COORDINATE__PROP, + Y_COORDINATE__PROP)); @Override public java.util.List properties() { @@ -64,8 +64,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case X_COORDINATE: return getXCoordinate(); - case Y_COORDINATE: return getYCoordinate(); + case X_COORDINATE__PROP: return getXCoordinate(); + case Y_COORDINATE__PROP: return getYCoordinate(); default: return Shape.super.get(field); } } @@ -73,8 +73,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case X_COORDINATE: internalSetXCoordinate((int) value); break; - case Y_COORDINATE: internalSetYCoordinate((int) value); break; + case X_COORDINATE__PROP: internalSetXCoordinate((int) value); break; + case Y_COORDINATE__PROP: internalSetYCoordinate((int) value); break; } } @@ -89,17 +89,17 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(X_COORDINATE); + out.name(X_COORDINATE__PROP); out.value(getXCoordinate()); - out.name(Y_COORDINATE); + out.name(Y_COORDINATE__PROP); out.value(getYCoordinate()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case X_COORDINATE: setXCoordinate(in.nextInt()); break; - case Y_COORDINATE: setYCoordinate(in.nextInt()); break; + case X_COORDINATE__PROP: setXCoordinate(in.nextInt()); break; + case Y_COORDINATE__PROP: setYCoordinate(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car_Impl.java index 4d37b9cd..ce3fab45 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car_Impl.java @@ -6,13 +6,13 @@ class Car_Impl extends Shape_Impl implements Car { /** @see #getWheel1() */ - private static final String WHEEL_1 = "wheel1"; + private static final String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - private static final String WHEEL_2 = "wheel2"; + private static final String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - private static final String BODY = "body"; + private static final String BODY__PROP = "body"; private Circle _wheel1 = null; @@ -118,15 +118,15 @@ public String jsonType() { protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); if (hasWheel1()) { - out.name(WHEEL_1); + out.name(WHEEL_1__PROP); getWheel1().writeContent(out); } if (hasWheel2()) { - out.name(WHEEL_2); + out.name(WHEEL_2__PROP); getWheel2().writeContent(out); } if (hasBody()) { - out.name(BODY); + out.name(BODY__PROP); getBody().writeContent(out); } } @@ -134,9 +134,9 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WHEEL_1: setWheel1(test.noreflection.Circle.readCircle(in)); break; - case WHEEL_2: setWheel2(test.noreflection.Circle.readCircle(in)); break; - case BODY: setBody(test.noreflection.Rectangle.readRectangle(in)); break; + case WHEEL_1__PROP: setWheel1(test.noreflection.Circle.readCircle(in)); break; + case WHEEL_2__PROP: setWheel2(test.noreflection.Circle.readCircle(in)); break; + case BODY__PROP: setBody(test.noreflection.Rectangle.readRectangle(in)); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle_Impl.java index 4234f670..ab81d5a6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle_Impl.java @@ -6,7 +6,7 @@ class Circle_Impl extends AtomicShape_Impl implements Circle { /** @see #getRadius() */ - private static final String RADIUS = "r"; + private static final String RADIUS__PROP = "r"; private int _radius = 0; @@ -60,14 +60,14 @@ public String jsonType() { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(RADIUS); + out.name(RADIUS__PROP); out.value(getRadius()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case RADIUS: setRadius(in.nextInt()); break; + case RADIUS__PROP: setRadius(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group_Impl.java index 2d45e191..5a813553 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group_Impl.java @@ -6,7 +6,7 @@ class Group_Impl extends Shape_Impl implements Group { /** @see #getShapes() */ - private static final String SHAPES = "shapes"; + private static final String SHAPES__PROP = "shapes"; private final java.util.List _shapes = new java.util.ArrayList<>(); @@ -78,7 +78,7 @@ public String jsonType() { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(SHAPES); + out.name(SHAPES__PROP); out.beginArray(); for (Shape x : getShapes()) { x.writeTo(out); @@ -89,7 +89,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case SHAPES: { + case SHAPES__PROP: { in.beginArray(); while (in.hasNext()) { addShape(test.noreflection.Shape.readShape(in)); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle_Impl.java index 936ffcc9..4f92b541 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle_Impl.java @@ -6,10 +6,10 @@ class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { /** @see #getWidth() */ - private static final String WIDTH = "w"; + private static final String WIDTH__PROP = "w"; /** @see #getHeight() */ - private static final String HEIGHT = "h"; + private static final String HEIGHT__PROP = "h"; private int _width = 0; @@ -81,17 +81,17 @@ public String jsonType() { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(WIDTH); + out.name(WIDTH__PROP); out.value(getWidth()); - out.name(HEIGHT); + out.name(HEIGHT__PROP); out.value(getHeight()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WIDTH: setWidth(in.nextInt()); break; - case HEIGHT: setHeight(in.nextInt()); break; + case WIDTH__PROP: setWidth(in.nextInt()); break; + case HEIGHT__PROP: setHeight(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape_Impl.java index 41ad7acf..9430cccb 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape_Impl.java @@ -6,10 +6,10 @@ abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements Shape { /** @see #getXCoordinate() */ - private static final String X_COORDINATE = "x"; + private static final String X_COORDINATE__PROP = "x"; /** @see #getYCoordinate() */ - private static final String Y_COORDINATE = "y"; + private static final String Y_COORDINATE__PROP = "y"; private int _xCoordinate = 0; @@ -69,17 +69,17 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(X_COORDINATE); + out.name(X_COORDINATE__PROP); out.value(getXCoordinate()); - out.name(Y_COORDINATE); + out.name(Y_COORDINATE__PROP); out.value(getYCoordinate()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case X_COORDINATE: setXCoordinate(in.nextInt()); break; - case Y_COORDINATE: setYCoordinate(in.nextInt()); break; + case X_COORDINATE__PROP: setXCoordinate(in.nextInt()); break; + case Y_COORDINATE__PROP: setYCoordinate(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java index d2a47cc7..925d8c33 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java @@ -16,13 +16,13 @@ static Car create() { static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ - static final String WHEEL_1 = "wheel1"; + static final String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - static final String WHEEL_2 = "wheel2"; + static final String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - static final String BODY = "body"; + static final String BODY__PROP = "body"; /** Identifier for the {@link Car} type in binary format. */ static final int CAR__TYPE_ID = 4; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car_Impl.java index 9c25f049..1101f1e8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car_Impl.java @@ -33,7 +33,7 @@ public Car setWheel1(Circle value) { /** Internal setter for {@link #getWheel1()} without chain call utility. */ protected final void internalSetWheel1(Circle value) { - _listener.beforeSet(this, WHEEL_1, value); + _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; } @@ -55,7 +55,7 @@ public Car setWheel2(Circle value) { /** Internal setter for {@link #getWheel2()} without chain call utility. */ protected final void internalSetWheel2(Circle value) { - _listener.beforeSet(this, WHEEL_2, value); + _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; } @@ -77,7 +77,7 @@ public Car setBody(Rectangle value) { /** Internal setter for {@link #getBody()} without chain call utility. */ protected final void internalSetBody(Rectangle value) { - _listener.beforeSet(this, BODY, value); + _listener.beforeSet(this, BODY__PROP, value); _body = value; } @@ -105,9 +105,9 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WHEEL_1, - WHEEL_2, - BODY)); + WHEEL_1__PROP, + WHEEL_2__PROP, + BODY__PROP)); @Override public java.util.List properties() { @@ -117,9 +117,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WHEEL_1: return getWheel1(); - case WHEEL_2: return getWheel2(); - case BODY: return getBody(); + case WHEEL_1__PROP: return getWheel1(); + case WHEEL_2__PROP: return getWheel2(); + case BODY__PROP: return getBody(); default: return super.get(field); } } @@ -127,9 +127,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1: internalSetWheel1((Circle) value); break; - case WHEEL_2: internalSetWheel2((Circle) value); break; - case BODY: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; + case BODY__PROP: internalSetBody((Rectangle) value); break; default: super.set(field, value); break; } } @@ -138,15 +138,15 @@ public void set(String field, Object value) { protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); if (hasWheel1()) { - out.name(WHEEL_1); + out.name(WHEEL_1__PROP); getWheel1().writeContent(out); } if (hasWheel2()) { - out.name(WHEEL_2); + out.name(WHEEL_2__PROP); getWheel2().writeContent(out); } if (hasBody()) { - out.name(BODY); + out.name(BODY__PROP); getBody().writeContent(out); } } @@ -154,9 +154,9 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WHEEL_1: setWheel1(test.notypekind.Circle.readCircle(in)); break; - case WHEEL_2: setWheel2(test.notypekind.Circle.readCircle(in)); break; - case BODY: setBody(test.notypekind.Rectangle.readRectangle(in)); break; + case WHEEL_1__PROP: setWheel1(test.notypekind.Circle.readCircle(in)); break; + case WHEEL_2__PROP: setWheel2(test.notypekind.Circle.readCircle(in)); break; + case BODY__PROP: setBody(test.notypekind.Rectangle.readRectangle(in)); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java index ad75d389..8d254baf 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java @@ -16,7 +16,7 @@ static Circle create() { static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ - static final String RADIUS = "r"; + static final String RADIUS__PROP = "r"; /** Identifier for the {@link Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle_Impl.java index f6b2ac71..1eb33511 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle_Impl.java @@ -29,7 +29,7 @@ public Circle setRadius(int value) { /** Internal setter for {@link #getRadius()} without chain call utility. */ protected final void internalSetRadius(int value) { - _listener.beforeSet(this, RADIUS, value); + _listener.beforeSet(this, RADIUS__PROP, value); _radius = value; } @@ -52,7 +52,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - RADIUS)); + RADIUS__PROP)); @Override public java.util.List properties() { @@ -62,7 +62,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case RADIUS: return getRadius(); + case RADIUS__PROP: return getRadius(); default: return super.get(field); } } @@ -70,7 +70,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case RADIUS: internalSetRadius((int) value); break; + case RADIUS__PROP: internalSetRadius((int) value); break; default: super.set(field, value); break; } } @@ -78,14 +78,14 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(RADIUS); + out.name(RADIUS__PROP); out.value(getRadius()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case RADIUS: setRadius(in.nextInt()); break; + case RADIUS__PROP: setRadius(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java index 5a0fa4f1..e1121bfa 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java @@ -16,7 +16,7 @@ static Group create() { static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ - static final String SHAPES = "shapes"; + static final String SHAPES__PROP = "shapes"; /** Identifier for the {@link Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group_Impl.java index c0d14249..400d398f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group_Impl.java @@ -8,12 +8,12 @@ class Group_Impl extends Shape_Impl implements Group { private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, Shape element) { - _listener.beforeAdd(Group_Impl.this, SHAPES, index, element); + _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); } @Override protected void afterRemove(int index, Shape element) { - _listener.afterRemove(Group_Impl.this, SHAPES, index, element); + _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } }; @@ -79,7 +79,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - SHAPES)); + SHAPES__PROP)); @Override public java.util.List properties() { @@ -89,7 +89,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case SHAPES: return getShapes(); + case SHAPES__PROP: return getShapes(); default: return super.get(field); } } @@ -97,7 +97,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; default: super.set(field, value); break; } } @@ -105,7 +105,7 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(SHAPES); + out.name(SHAPES__PROP); out.beginArray(); for (Shape x : getShapes()) { x.writeTo(out); @@ -116,7 +116,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case SHAPES: { + case SHAPES__PROP: { in.beginArray(); while (in.hasNext()) { addShape(test.notypekind.Shape.readShape(in)); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java index 5447ab1d..273e9265 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java @@ -16,10 +16,10 @@ static Rectangle create() { static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ - static final String WIDTH = "w"; + static final String WIDTH__PROP = "w"; /** @see #getHeight() */ - static final String HEIGHT = "h"; + static final String HEIGHT__PROP = "h"; /** Identifier for the {@link Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle_Impl.java index 5b1f3396..e0983168 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle_Impl.java @@ -31,7 +31,7 @@ public Rectangle setWidth(int value) { /** Internal setter for {@link #getWidth()} without chain call utility. */ protected final void internalSetWidth(int value) { - _listener.beforeSet(this, WIDTH, value); + _listener.beforeSet(this, WIDTH__PROP, value); _width = value; } @@ -48,7 +48,7 @@ public Rectangle setHeight(int value) { /** Internal setter for {@link #getHeight()} without chain call utility. */ protected final void internalSetHeight(int value) { - _listener.beforeSet(this, HEIGHT, value); + _listener.beforeSet(this, HEIGHT__PROP, value); _height = value; } @@ -71,8 +71,8 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WIDTH, - HEIGHT)); + WIDTH__PROP, + HEIGHT__PROP)); @Override public java.util.List properties() { @@ -82,8 +82,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WIDTH: return getWidth(); - case HEIGHT: return getHeight(); + case WIDTH__PROP: return getWidth(); + case HEIGHT__PROP: return getHeight(); default: return super.get(field); } } @@ -91,8 +91,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WIDTH: internalSetWidth((int) value); break; - case HEIGHT: internalSetHeight((int) value); break; + case WIDTH__PROP: internalSetWidth((int) value); break; + case HEIGHT__PROP: internalSetHeight((int) value); break; default: super.set(field, value); break; } } @@ -100,17 +100,17 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(WIDTH); + out.name(WIDTH__PROP); out.value(getWidth()); - out.name(HEIGHT); + out.name(HEIGHT__PROP); out.value(getHeight()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WIDTH: setWidth(in.nextInt()); break; - case HEIGHT: setHeight(in.nextInt()); break; + case WIDTH__PROP: setWidth(in.nextInt()); break; + case HEIGHT__PROP: setHeight(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java index 47d01f5e..33649bfb 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java @@ -17,10 +17,10 @@ public interface Visitor extends AtomicShape.Visitor PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - X_COORDINATE, - Y_COORDINATE)); + X_COORDINATE__PROP, + Y_COORDINATE__PROP)); @Override public java.util.List properties() { @@ -85,8 +85,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case X_COORDINATE: return getXCoordinate(); - case Y_COORDINATE: return getYCoordinate(); + case X_COORDINATE__PROP: return getXCoordinate(); + case Y_COORDINATE__PROP: return getYCoordinate(); default: return Shape.super.get(field); } } @@ -94,8 +94,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case X_COORDINATE: internalSetXCoordinate((int) value); break; - case Y_COORDINATE: internalSetYCoordinate((int) value); break; + case X_COORDINATE__PROP: internalSetXCoordinate((int) value); break; + case Y_COORDINATE__PROP: internalSetYCoordinate((int) value); break; } } @@ -110,17 +110,17 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(X_COORDINATE); + out.name(X_COORDINATE__PROP); out.value(getXCoordinate()); - out.name(Y_COORDINATE); + out.name(Y_COORDINATE__PROP); out.value(getYCoordinate()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case X_COORDINATE: setXCoordinate(in.nextInt()); break; - case Y_COORDINATE: setYCoordinate(in.nextInt()); break; + case X_COORDINATE__PROP: setXCoordinate(in.nextInt()); break; + case Y_COORDINATE__PROP: setYCoordinate(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java index 84163d30..7a70ad7c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java @@ -16,13 +16,13 @@ static Car create() { static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ - static final String WHEEL_1 = "wheel1"; + static final String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - static final String WHEEL_2 = "wheel2"; + static final String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - static final String BODY = "body"; + static final String BODY__PROP = "body"; /** Identifier for the {@link Car} type in binary format. */ static final int CAR__TYPE_ID = 4; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car_Impl.java index e52ff9ae..40d259ae 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car_Impl.java @@ -38,7 +38,7 @@ public Car setWheel1(Circle value) { /** Internal setter for {@link #getWheel1()} without chain call utility. */ protected final void internalSetWheel1(Circle value) { - _listener.beforeSet(this, WHEEL_1, value); + _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; } @@ -60,7 +60,7 @@ public Car setWheel2(Circle value) { /** Internal setter for {@link #getWheel2()} without chain call utility. */ protected final void internalSetWheel2(Circle value) { - _listener.beforeSet(this, WHEEL_2, value); + _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; } @@ -82,7 +82,7 @@ public Car setBody(Rectangle value) { /** Internal setter for {@link #getBody()} without chain call utility. */ protected final void internalSetBody(Rectangle value) { - _listener.beforeSet(this, BODY, value); + _listener.beforeSet(this, BODY__PROP, value); _body = value; } @@ -110,9 +110,9 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WHEEL_1, - WHEEL_2, - BODY)); + WHEEL_1__PROP, + WHEEL_2__PROP, + BODY__PROP)); @Override public java.util.List properties() { @@ -122,9 +122,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WHEEL_1: return getWheel1(); - case WHEEL_2: return getWheel2(); - case BODY: return getBody(); + case WHEEL_1__PROP: return getWheel1(); + case WHEEL_2__PROP: return getWheel2(); + case BODY__PROP: return getBody(); default: return super.get(field); } } @@ -132,9 +132,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1: internalSetWheel1((Circle) value); break; - case WHEEL_2: internalSetWheel2((Circle) value); break; - case BODY: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; + case BODY__PROP: internalSetBody((Rectangle) value); break; default: super.set(field, value); break; } } @@ -143,15 +143,15 @@ public void set(String field, Object value) { protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); if (hasWheel1()) { - out.name(WHEEL_1); + out.name(WHEEL_1__PROP); getWheel1().writeContent(out); } if (hasWheel2()) { - out.name(WHEEL_2); + out.name(WHEEL_2__PROP); getWheel2().writeContent(out); } if (hasBody()) { - out.name(BODY); + out.name(BODY__PROP); getBody().writeContent(out); } } @@ -159,9 +159,9 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WHEEL_1: setWheel1(test.novisit.Circle.readCircle(in)); break; - case WHEEL_2: setWheel2(test.novisit.Circle.readCircle(in)); break; - case BODY: setBody(test.novisit.Rectangle.readRectangle(in)); break; + case WHEEL_1__PROP: setWheel1(test.novisit.Circle.readCircle(in)); break; + case WHEEL_2__PROP: setWheel2(test.novisit.Circle.readCircle(in)); break; + case BODY__PROP: setBody(test.novisit.Rectangle.readRectangle(in)); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java index e8509ec3..aaab3e92 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java @@ -16,7 +16,7 @@ static Circle create() { static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ - static final String RADIUS = "r"; + static final String RADIUS__PROP = "r"; /** Identifier for the {@link Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle_Impl.java index 7850cae1..a9b34001 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle_Impl.java @@ -34,7 +34,7 @@ public Circle setRadius(int value) { /** Internal setter for {@link #getRadius()} without chain call utility. */ protected final void internalSetRadius(int value) { - _listener.beforeSet(this, RADIUS, value); + _listener.beforeSet(this, RADIUS__PROP, value); _radius = value; } @@ -57,7 +57,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - RADIUS)); + RADIUS__PROP)); @Override public java.util.List properties() { @@ -67,7 +67,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case RADIUS: return getRadius(); + case RADIUS__PROP: return getRadius(); default: return super.get(field); } } @@ -75,7 +75,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case RADIUS: internalSetRadius((int) value); break; + case RADIUS__PROP: internalSetRadius((int) value); break; default: super.set(field, value); break; } } @@ -83,14 +83,14 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(RADIUS); + out.name(RADIUS__PROP); out.value(getRadius()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case RADIUS: setRadius(in.nextInt()); break; + case RADIUS__PROP: setRadius(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java index 172dd4e6..1ce6e729 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java @@ -16,7 +16,7 @@ static Group create() { static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ - static final String SHAPES = "shapes"; + static final String SHAPES__PROP = "shapes"; /** Identifier for the {@link Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group_Impl.java index 553f7c24..f30e403a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group_Impl.java @@ -8,12 +8,12 @@ class Group_Impl extends Shape_Impl implements Group { private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, Shape element) { - _listener.beforeAdd(Group_Impl.this, SHAPES, index, element); + _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); } @Override protected void afterRemove(int index, Shape element) { - _listener.afterRemove(Group_Impl.this, SHAPES, index, element); + _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } }; @@ -84,7 +84,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - SHAPES)); + SHAPES__PROP)); @Override public java.util.List properties() { @@ -94,7 +94,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case SHAPES: return getShapes(); + case SHAPES__PROP: return getShapes(); default: return super.get(field); } } @@ -102,7 +102,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; default: super.set(field, value); break; } } @@ -110,7 +110,7 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(SHAPES); + out.name(SHAPES__PROP); out.beginArray(); for (Shape x : getShapes()) { x.writeTo(out); @@ -121,7 +121,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case SHAPES: { + case SHAPES__PROP: { in.beginArray(); while (in.hasNext()) { addShape(test.novisit.Shape.readShape(in)); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java index 24d323f6..5aa86761 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java @@ -16,10 +16,10 @@ static Rectangle create() { static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ - static final String WIDTH = "w"; + static final String WIDTH__PROP = "w"; /** @see #getHeight() */ - static final String HEIGHT = "h"; + static final String HEIGHT__PROP = "h"; /** Identifier for the {@link Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle_Impl.java index 3546ee96..1d732ff5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle_Impl.java @@ -36,7 +36,7 @@ public Rectangle setWidth(int value) { /** Internal setter for {@link #getWidth()} without chain call utility. */ protected final void internalSetWidth(int value) { - _listener.beforeSet(this, WIDTH, value); + _listener.beforeSet(this, WIDTH__PROP, value); _width = value; } @@ -53,7 +53,7 @@ public Rectangle setHeight(int value) { /** Internal setter for {@link #getHeight()} without chain call utility. */ protected final void internalSetHeight(int value) { - _listener.beforeSet(this, HEIGHT, value); + _listener.beforeSet(this, HEIGHT__PROP, value); _height = value; } @@ -76,8 +76,8 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WIDTH, - HEIGHT)); + WIDTH__PROP, + HEIGHT__PROP)); @Override public java.util.List properties() { @@ -87,8 +87,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WIDTH: return getWidth(); - case HEIGHT: return getHeight(); + case WIDTH__PROP: return getWidth(); + case HEIGHT__PROP: return getHeight(); default: return super.get(field); } } @@ -96,8 +96,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WIDTH: internalSetWidth((int) value); break; - case HEIGHT: internalSetHeight((int) value); break; + case WIDTH__PROP: internalSetWidth((int) value); break; + case HEIGHT__PROP: internalSetHeight((int) value); break; default: super.set(field, value); break; } } @@ -105,17 +105,17 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(WIDTH); + out.name(WIDTH__PROP); out.value(getWidth()); - out.name(HEIGHT); + out.name(HEIGHT__PROP); out.value(getHeight()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WIDTH: setWidth(in.nextInt()); break; - case HEIGHT: setHeight(in.nextInt()); break; + case WIDTH__PROP: setWidth(in.nextInt()); break; + case HEIGHT__PROP: setHeight(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java index 4937eb41..9a5ef03a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java @@ -24,10 +24,10 @@ public enum TypeKind { } /** @see #getXCoordinate() */ - static final String X_COORDINATE = "x"; + static final String X_COORDINATE__PROP = "x"; /** @see #getYCoordinate() */ - static final String Y_COORDINATE = "y"; + static final String Y_COORDINATE__PROP = "y"; /** Identifier for the property {@link #getXCoordinate()} in binary format. */ static final int X_COORDINATE__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape_Impl.java index 16be97a8..1c908a13 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape_Impl.java @@ -32,7 +32,7 @@ public Shape setXCoordinate(int value) { /** Internal setter for {@link #getXCoordinate()} without chain call utility. */ protected final void internalSetXCoordinate(int value) { - _listener.beforeSet(this, X_COORDINATE, value); + _listener.beforeSet(this, X_COORDINATE__PROP, value); _xCoordinate = value; } @@ -49,7 +49,7 @@ public Shape setYCoordinate(int value) { /** Internal setter for {@link #getYCoordinate()} without chain call utility. */ protected final void internalSetYCoordinate(int value) { - _listener.beforeSet(this, Y_COORDINATE, value); + _listener.beforeSet(this, Y_COORDINATE__PROP, value); _yCoordinate = value; } @@ -77,8 +77,8 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - X_COORDINATE, - Y_COORDINATE)); + X_COORDINATE__PROP, + Y_COORDINATE__PROP)); @Override public java.util.List properties() { @@ -88,8 +88,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case X_COORDINATE: return getXCoordinate(); - case Y_COORDINATE: return getYCoordinate(); + case X_COORDINATE__PROP: return getXCoordinate(); + case Y_COORDINATE__PROP: return getYCoordinate(); default: return Shape.super.get(field); } } @@ -97,8 +97,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case X_COORDINATE: internalSetXCoordinate((int) value); break; - case Y_COORDINATE: internalSetYCoordinate((int) value); break; + case X_COORDINATE__PROP: internalSetXCoordinate((int) value); break; + case Y_COORDINATE__PROP: internalSetYCoordinate((int) value); break; } } @@ -113,17 +113,17 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(X_COORDINATE); + out.name(X_COORDINATE__PROP); out.value(getXCoordinate()); - out.name(Y_COORDINATE); + out.name(Y_COORDINATE__PROP); out.value(getYCoordinate()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case X_COORDINATE: setXCoordinate(in.nextInt()); break; - case Y_COORDINATE: setYCoordinate(in.nextInt()); break; + case X_COORDINATE__PROP: setXCoordinate(in.nextInt()); break; + case Y_COORDINATE__PROP: setYCoordinate(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java index be6ca1bb..1b338ee4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java @@ -16,13 +16,13 @@ static Car create() { static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ - static final String WHEEL_1 = "wheel1"; + static final String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - static final String WHEEL_2 = "wheel2"; + static final String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - static final String BODY = "body"; + static final String BODY__PROP = "body"; /** Identifier for the {@link Car} type in binary format. */ static final int CAR__TYPE_ID = 4; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car_Impl.java index 3ca53cc6..2334b67c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car_Impl.java @@ -38,7 +38,7 @@ public Car setWheel1(Circle value) { /** Internal setter for {@link #getWheel1()} without chain call utility. */ protected final void internalSetWheel1(Circle value) { - _listener.beforeSet(this, WHEEL_1, value); + _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; } @@ -60,7 +60,7 @@ public Car setWheel2(Circle value) { /** Internal setter for {@link #getWheel2()} without chain call utility. */ protected final void internalSetWheel2(Circle value) { - _listener.beforeSet(this, WHEEL_2, value); + _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; } @@ -82,7 +82,7 @@ public Car setBody(Rectangle value) { /** Internal setter for {@link #getBody()} without chain call utility. */ protected final void internalSetBody(Rectangle value) { - _listener.beforeSet(this, BODY, value); + _listener.beforeSet(this, BODY__PROP, value); _body = value; } @@ -110,9 +110,9 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WHEEL_1, - WHEEL_2, - BODY)); + WHEEL_1__PROP, + WHEEL_2__PROP, + BODY__PROP)); @Override public java.util.List properties() { @@ -122,9 +122,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WHEEL_1: return getWheel1(); - case WHEEL_2: return getWheel2(); - case BODY: return getBody(); + case WHEEL_1__PROP: return getWheel1(); + case WHEEL_2__PROP: return getWheel2(); + case BODY__PROP: return getBody(); default: return super.get(field); } } @@ -132,9 +132,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1: internalSetWheel1((Circle) value); break; - case WHEEL_2: internalSetWheel2((Circle) value); break; - case BODY: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; + case BODY__PROP: internalSetBody((Rectangle) value); break; default: super.set(field, value); break; } } @@ -143,15 +143,15 @@ public void set(String field, Object value) { protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); if (hasWheel1()) { - out.name(WHEEL_1); + out.name(WHEEL_1__PROP); getWheel1().writeContent(out); } if (hasWheel2()) { - out.name(WHEEL_2); + out.name(WHEEL_2__PROP); getWheel2().writeContent(out); } if (hasBody()) { - out.name(BODY); + out.name(BODY__PROP); getBody().writeContent(out); } } @@ -159,9 +159,9 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WHEEL_1: setWheel1(test.novisitexceptions.Circle.readCircle(in)); break; - case WHEEL_2: setWheel2(test.novisitexceptions.Circle.readCircle(in)); break; - case BODY: setBody(test.novisitexceptions.Rectangle.readRectangle(in)); break; + case WHEEL_1__PROP: setWheel1(test.novisitexceptions.Circle.readCircle(in)); break; + case WHEEL_2__PROP: setWheel2(test.novisitexceptions.Circle.readCircle(in)); break; + case BODY__PROP: setBody(test.novisitexceptions.Rectangle.readRectangle(in)); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java index a94a9817..edfe8040 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java @@ -16,7 +16,7 @@ static Circle create() { static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ - static final String RADIUS = "r"; + static final String RADIUS__PROP = "r"; /** Identifier for the {@link Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle_Impl.java index d71020c6..0404b7e2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle_Impl.java @@ -34,7 +34,7 @@ public Circle setRadius(int value) { /** Internal setter for {@link #getRadius()} without chain call utility. */ protected final void internalSetRadius(int value) { - _listener.beforeSet(this, RADIUS, value); + _listener.beforeSet(this, RADIUS__PROP, value); _radius = value; } @@ -57,7 +57,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - RADIUS)); + RADIUS__PROP)); @Override public java.util.List properties() { @@ -67,7 +67,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case RADIUS: return getRadius(); + case RADIUS__PROP: return getRadius(); default: return super.get(field); } } @@ -75,7 +75,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case RADIUS: internalSetRadius((int) value); break; + case RADIUS__PROP: internalSetRadius((int) value); break; default: super.set(field, value); break; } } @@ -83,14 +83,14 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(RADIUS); + out.name(RADIUS__PROP); out.value(getRadius()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case RADIUS: setRadius(in.nextInt()); break; + case RADIUS__PROP: setRadius(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java index 212f772b..442ebda7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java @@ -16,7 +16,7 @@ static Group create() { static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ - static final String SHAPES = "shapes"; + static final String SHAPES__PROP = "shapes"; /** Identifier for the {@link Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group_Impl.java index ff6747cc..f07e81a9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group_Impl.java @@ -8,12 +8,12 @@ class Group_Impl extends Shape_Impl implements Group { private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, Shape element) { - _listener.beforeAdd(Group_Impl.this, SHAPES, index, element); + _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); } @Override protected void afterRemove(int index, Shape element) { - _listener.afterRemove(Group_Impl.this, SHAPES, index, element); + _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } }; @@ -84,7 +84,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - SHAPES)); + SHAPES__PROP)); @Override public java.util.List properties() { @@ -94,7 +94,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case SHAPES: return getShapes(); + case SHAPES__PROP: return getShapes(); default: return super.get(field); } } @@ -102,7 +102,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; default: super.set(field, value); break; } } @@ -110,7 +110,7 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(SHAPES); + out.name(SHAPES__PROP); out.beginArray(); for (Shape x : getShapes()) { x.writeTo(out); @@ -121,7 +121,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case SHAPES: { + case SHAPES__PROP: { in.beginArray(); while (in.hasNext()) { addShape(test.novisitexceptions.Shape.readShape(in)); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java index 6d437bf9..567c1629 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java @@ -16,10 +16,10 @@ static Rectangle create() { static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ - static final String WIDTH = "w"; + static final String WIDTH__PROP = "w"; /** @see #getHeight() */ - static final String HEIGHT = "h"; + static final String HEIGHT__PROP = "h"; /** Identifier for the {@link Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle_Impl.java index 5b4d3da6..f0e1eef9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle_Impl.java @@ -36,7 +36,7 @@ public Rectangle setWidth(int value) { /** Internal setter for {@link #getWidth()} without chain call utility. */ protected final void internalSetWidth(int value) { - _listener.beforeSet(this, WIDTH, value); + _listener.beforeSet(this, WIDTH__PROP, value); _width = value; } @@ -53,7 +53,7 @@ public Rectangle setHeight(int value) { /** Internal setter for {@link #getHeight()} without chain call utility. */ protected final void internalSetHeight(int value) { - _listener.beforeSet(this, HEIGHT, value); + _listener.beforeSet(this, HEIGHT__PROP, value); _height = value; } @@ -76,8 +76,8 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - WIDTH, - HEIGHT)); + WIDTH__PROP, + HEIGHT__PROP)); @Override public java.util.List properties() { @@ -87,8 +87,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case WIDTH: return getWidth(); - case HEIGHT: return getHeight(); + case WIDTH__PROP: return getWidth(); + case HEIGHT__PROP: return getHeight(); default: return super.get(field); } } @@ -96,8 +96,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WIDTH: internalSetWidth((int) value); break; - case HEIGHT: internalSetHeight((int) value); break; + case WIDTH__PROP: internalSetWidth((int) value); break; + case HEIGHT__PROP: internalSetHeight((int) value); break; default: super.set(field, value); break; } } @@ -105,17 +105,17 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(WIDTH); + out.name(WIDTH__PROP); out.value(getWidth()); - out.name(HEIGHT); + out.name(HEIGHT__PROP); out.value(getHeight()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case WIDTH: setWidth(in.nextInt()); break; - case HEIGHT: setHeight(in.nextInt()); break; + case WIDTH__PROP: setWidth(in.nextInt()); break; + case HEIGHT__PROP: setHeight(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java index 5aa1e2ff..8dd6cb2b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java @@ -35,10 +35,10 @@ public interface Visitor extends AtomicShape.Visitor { } /** @see #getXCoordinate() */ - static final String X_COORDINATE = "x"; + static final String X_COORDINATE__PROP = "x"; /** @see #getYCoordinate() */ - static final String Y_COORDINATE = "y"; + static final String Y_COORDINATE__PROP = "y"; /** Identifier for the property {@link #getXCoordinate()} in binary format. */ static final int X_COORDINATE__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape_Impl.java index e10aee92..93faaa38 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape_Impl.java @@ -32,7 +32,7 @@ public Shape setXCoordinate(int value) { /** Internal setter for {@link #getXCoordinate()} without chain call utility. */ protected final void internalSetXCoordinate(int value) { - _listener.beforeSet(this, X_COORDINATE, value); + _listener.beforeSet(this, X_COORDINATE__PROP, value); _xCoordinate = value; } @@ -49,7 +49,7 @@ public Shape setYCoordinate(int value) { /** Internal setter for {@link #getYCoordinate()} without chain call utility. */ protected final void internalSetYCoordinate(int value) { - _listener.beforeSet(this, Y_COORDINATE, value); + _listener.beforeSet(this, Y_COORDINATE__PROP, value); _yCoordinate = value; } @@ -77,8 +77,8 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - X_COORDINATE, - Y_COORDINATE)); + X_COORDINATE__PROP, + Y_COORDINATE__PROP)); @Override public java.util.List properties() { @@ -88,8 +88,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case X_COORDINATE: return getXCoordinate(); - case Y_COORDINATE: return getYCoordinate(); + case X_COORDINATE__PROP: return getXCoordinate(); + case Y_COORDINATE__PROP: return getYCoordinate(); default: return Shape.super.get(field); } } @@ -97,8 +97,8 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case X_COORDINATE: internalSetXCoordinate((int) value); break; - case Y_COORDINATE: internalSetYCoordinate((int) value); break; + case X_COORDINATE__PROP: internalSetXCoordinate((int) value); break; + case Y_COORDINATE__PROP: internalSetYCoordinate((int) value); break; } } @@ -113,17 +113,17 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(X_COORDINATE); + out.name(X_COORDINATE__PROP); out.value(getXCoordinate()); - out.name(Y_COORDINATE); + out.name(Y_COORDINATE__PROP); out.value(getYCoordinate()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case X_COORDINATE: setXCoordinate(in.nextInt()); break; - case Y_COORDINATE: setYCoordinate(in.nextInt()); break; + case X_COORDINATE__PROP: setXCoordinate(in.nextInt()); break; + case Y_COORDINATE__PROP: setYCoordinate(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java index 63c69f9d..06bb14d2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java @@ -13,28 +13,28 @@ static NullableValues create() { static final String NULLABLE_VALUES__TYPE = "NullableValues"; /** @see #getInt() */ - static final String INT = "int"; + static final String INT__PROP = "int"; /** @see #getLong() */ - static final String LONG = "long"; + static final String LONG__PROP = "long"; /** @see #getBoolean() */ - static final String BOOLEAN = "boolean"; + static final String BOOLEAN__PROP = "boolean"; /** @see #getString() */ - static final String STRING = "string"; + static final String STRING__PROP = "string"; /** @see #getIntList() */ - static final String INT_LIST = "intList"; + static final String INT_LIST__PROP = "intList"; /** @see #getStringList() */ - static final String STRING_LIST = "stringList"; + static final String STRING_LIST__PROP = "stringList"; /** @see #getStringIntMap() */ - static final String STRING_INT_MAP = "stringIntMap"; + static final String STRING_INT_MAP__PROP = "stringIntMap"; /** @see #getOptionalDecision() */ - static final String OPTIONAL_DECISION = "optionalDecision"; + static final String OPTIONAL_DECISION__PROP = "optionalDecision"; /** Identifier for the property {@link #getInt()} in binary format. */ static final int INT__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues_Impl.java index 3780fd29..f8f469e6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues_Impl.java @@ -265,14 +265,14 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - INT, - LONG, - BOOLEAN, - STRING, - INT_LIST, - STRING_LIST, - STRING_INT_MAP, - OPTIONAL_DECISION)); + INT__PROP, + LONG__PROP, + BOOLEAN__PROP, + STRING__PROP, + INT_LIST__PROP, + STRING_LIST__PROP, + STRING_INT_MAP__PROP, + OPTIONAL_DECISION__PROP)); @Override public java.util.List properties() { @@ -282,14 +282,14 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case INT: return getInt(); - case LONG: return getLong(); - case BOOLEAN: return getBoolean(); - case STRING: return getString(); - case INT_LIST: return getIntList(); - case STRING_LIST: return getStringList(); - case STRING_INT_MAP: return getStringIntMap(); - case OPTIONAL_DECISION: return getOptionalDecision(); + case INT__PROP: return getInt(); + case LONG__PROP: return getLong(); + case BOOLEAN__PROP: return getBoolean(); + case STRING__PROP: return getString(); + case INT_LIST__PROP: return getIntList(); + case STRING_LIST__PROP: return getStringList(); + case STRING_INT_MAP__PROP: return getStringIntMap(); + case OPTIONAL_DECISION__PROP: return getOptionalDecision(); default: return NullableValues.super.get(field); } } @@ -297,14 +297,14 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case INT: internalSetInt((Integer) value); break; - case LONG: internalSetLong((Long) value); break; - case BOOLEAN: internalSetBoolean((Boolean) value); break; - case STRING: internalSetString((String) value); break; - case INT_LIST: internalSetIntList(de.haumacher.msgbuf.util.Conversions.asList(Integer.class, value)); break; - case STRING_LIST: internalSetStringList(de.haumacher.msgbuf.util.Conversions.asList(String.class, value)); break; - case STRING_INT_MAP: internalSetStringIntMap((java.util.Map) value); break; - case OPTIONAL_DECISION: internalSetOptionalDecision((Decision) value); break; + case INT__PROP: internalSetInt((Integer) value); break; + case LONG__PROP: internalSetLong((Long) value); break; + case BOOLEAN__PROP: internalSetBoolean((Boolean) value); break; + case STRING__PROP: internalSetString((String) value); break; + case INT_LIST__PROP: internalSetIntList(de.haumacher.msgbuf.util.Conversions.asList(Integer.class, value)); break; + case STRING_LIST__PROP: internalSetStringList(de.haumacher.msgbuf.util.Conversions.asList(String.class, value)); break; + case STRING_INT_MAP__PROP: internalSetStringIntMap((java.util.Map) value); break; + case OPTIONAL_DECISION__PROP: internalSetOptionalDecision((Decision) value); break; } } @@ -317,23 +317,23 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); if (hasInt()) { - out.name(INT); + out.name(INT__PROP); out.value(getInt()); } if (hasLong()) { - out.name(LONG); + out.name(LONG__PROP); out.value(getLong()); } if (hasBoolean()) { - out.name(BOOLEAN); + out.name(BOOLEAN__PROP); out.value(getBoolean()); } if (hasString()) { - out.name(STRING); + out.name(STRING__PROP); out.value(getString()); } if (hasIntList()) { - out.name(INT_LIST); + out.name(INT_LIST__PROP); out.beginArray(); for (int x : getIntList()) { out.value(x); @@ -341,7 +341,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. out.endArray(); } if (hasStringList()) { - out.name(STRING_LIST); + out.name(STRING_LIST__PROP); out.beginArray(); for (String x : getStringList()) { out.value(x); @@ -349,7 +349,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. out.endArray(); } if (hasStringIntMap()) { - out.name(STRING_INT_MAP); + out.name(STRING_INT_MAP__PROP); out.beginObject(); for (java.util.Map.Entry entry : getStringIntMap().entrySet()) { out.name(entry.getKey()); @@ -358,7 +358,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. out.endObject(); } if (hasOptionalDecision()) { - out.name(OPTIONAL_DECISION); + out.name(OPTIONAL_DECISION__PROP); getOptionalDecision().writeTo(out); } } @@ -366,11 +366,11 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case INT: setInt(in.nextInt()); break; - case LONG: setLong(in.nextLong()); break; - case BOOLEAN: setBoolean(in.nextBoolean()); break; - case STRING: setString(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; - case INT_LIST: { + case INT__PROP: setInt(in.nextInt()); break; + case LONG__PROP: setLong(in.nextLong()); break; + case BOOLEAN__PROP: setBoolean(in.nextBoolean()); break; + case STRING__PROP: setString(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case INT_LIST__PROP: { in.beginArray(); while (in.hasNext()) { addIntList(in.nextInt()); @@ -378,7 +378,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t in.endArray(); } break; - case STRING_LIST: { + case STRING_LIST__PROP: { in.beginArray(); while (in.hasNext()) { addStringList(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); @@ -386,7 +386,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t in.endArray(); } break; - case STRING_INT_MAP: { + case STRING_INT_MAP__PROP: { in.beginObject(); while (in.hasNext()) { putStringIntMap(in.nextName(), in.nextInt()); @@ -394,7 +394,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t in.endObject(); break; } - case OPTIONAL_DECISION: setOptionalDecision(test.nullable.data.Decision.readDecision(in)); break; + case OPTIONAL_DECISION__PROP: setOptionalDecision(test.nullable.data.Decision.readDecision(in)); break; default: super.readField(in, field); } } @@ -604,6 +604,10 @@ protected void readFieldXmlAttribute(String name, String value) { setStringList(java.util.Arrays.stream(value.split("\\s*,\\s*")).map(x -> x).collect(java.util.stream.Collectors.toList())); break; } + case OPTIONAL_DECISION__XML_ATTR: { + setOptionalDecision(test.nullable.data.Decision.valueOfProtocol(value)); + break; + } default: { // Skip unknown attribute. } @@ -637,6 +641,10 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l setStringList(java.util.Arrays.stream(in.getElementText().split("\\s*,\\s*")).map(x -> x).collect(java.util.stream.Collectors.toList())); break; } + case OPTIONAL_DECISION__XML_ATTR: { + setOptionalDecision(test.nullable.data.Decision.valueOfProtocol(in.getElementText())); + break; + } default: { internalSkipUntilMatchingEndElement(in); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/TestReverseReferences.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/TestReverseReferences.java index 053b2539..35890d36 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/TestReverseReferences.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/TestReverseReferences.java @@ -77,8 +77,8 @@ public void testReverseList() throws IOException { public void testSetListener() { Map properties = new HashMap<>(); A a1 = A.create().registerListener((self, prop, value) -> properties.put(prop, value)).setB(B.create()).setName("a1"); - assertEquals(a1.getB(), properties.get(A.B)); - assertEquals("a1", properties.get(A.NAME)); + assertEquals(a1.getB(), properties.get(A.B__PROP)); + assertEquals("a1", properties.get(A.NAME__PROP)); } public void testAddListener() { @@ -102,11 +102,11 @@ public void beforeAdd(Observable obj, String property, int index, Object element } }; A a1 = A.create().registerListener(l).setName("a1").addBs(B.create().setName("b1")).setChildren(Arrays.asList(A.create().setName("a2"))); - assertEquals("a1", properties.get(A.NAME)); - assertEquals(a1.getBs().get(0), properties.get(A.BS)); - assertEquals(a1.getChildren().get(0), properties.get(A.CHILDREN)); + assertEquals("a1", properties.get(A.NAME__PROP)); + assertEquals(a1.getBs().get(0), properties.get(A.BS__PROP)); + assertEquals(a1.getChildren().get(0), properties.get(A.CHILDREN__PROP)); a1.getBs().get(0).setName("b2"); - assertEquals("b2", properties.get(B.NAME)); + assertEquals("b2", properties.get(B.NAME__PROP)); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java index fc7c00de..1812f212 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java @@ -13,31 +13,31 @@ static A create() { static final String A__TYPE = "A"; /** @see #getName() */ - static final String NAME = "name"; + static final String NAME__PROP = "name"; /** @see #getContents() */ - static final String CONTENTS = "contents"; + static final String CONTENTS__PROP = "contents"; /** @see #getChildren() */ - static final String CHILDREN = "children"; + static final String CHILDREN__PROP = "children"; /** @see #getBs() */ - static final String BS = "bs"; + static final String BS__PROP = "bs"; /** @see #getB() */ - static final String B = "b"; + static final String B__PROP = "b"; /** @see #getOther() */ - static final String OTHER = "other"; + static final String OTHER__PROP = "other"; /** @see #getOthers() */ - static final String OTHERS = "others"; + static final String OTHERS__PROP = "others"; /** @see #getInOther() */ - static final String IN_OTHER = "inOther"; + static final String IN_OTHER__PROP = "inOther"; /** @see #getInOthers() */ - static final String IN_OTHERS = "inOthers"; + static final String IN_OTHERS__PROP = "inOthers"; /** Identifier for the property {@link #getName()} in binary format. */ static final int NAME__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A_Impl.java index 35cb6f59..e9d5913a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A_Impl.java @@ -9,26 +9,26 @@ class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements A { private final java.util.List _children = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, A element) { - _listener.beforeAdd(A_Impl.this, CHILDREN, index, element); + _listener.beforeAdd(A_Impl.this, CHILDREN__PROP, index, element); } @Override protected void afterRemove(int index, A element) { - _listener.afterRemove(A_Impl.this, CHILDREN, index, element); + _listener.afterRemove(A_Impl.this, CHILDREN__PROP, index, element); } }; private final java.util.List _bs = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, B element) { - _listener.beforeAdd(A_Impl.this, BS, index, element); + _listener.beforeAdd(A_Impl.this, BS__PROP, index, element); ((B_Impl) element).addInBs(A_Impl.this); } @Override protected void afterRemove(int index, B element) { ((B_Impl) element).removeInBs(A_Impl.this); - _listener.afterRemove(A_Impl.this, BS, index, element); + _listener.afterRemove(A_Impl.this, BS__PROP, index, element); } }; @@ -39,38 +39,38 @@ protected void afterRemove(int index, B element) { private final java.util.List _others = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, A element) { - _listener.beforeAdd(A_Impl.this, OTHERS, index, element); + _listener.beforeAdd(A_Impl.this, OTHERS__PROP, index, element); ((A_Impl) element).addInOthers(A_Impl.this); } @Override protected void afterRemove(int index, A element) { ((A_Impl) element).removeInOthers(A_Impl.this); - _listener.afterRemove(A_Impl.this, OTHERS, index, element); + _listener.afterRemove(A_Impl.this, OTHERS__PROP, index, element); } }; private final java.util.List _inOther = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, A element) { - _listener.beforeAdd(A_Impl.this, IN_OTHER, index, element); + _listener.beforeAdd(A_Impl.this, IN_OTHER__PROP, index, element); } @Override protected void afterRemove(int index, A element) { - _listener.afterRemove(A_Impl.this, IN_OTHER, index, element); + _listener.afterRemove(A_Impl.this, IN_OTHER__PROP, index, element); } }; private final java.util.List _inOthers = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, A element) { - _listener.beforeAdd(A_Impl.this, IN_OTHERS, index, element); + _listener.beforeAdd(A_Impl.this, IN_OTHERS__PROP, index, element); } @Override protected void afterRemove(int index, A element) { - _listener.afterRemove(A_Impl.this, IN_OTHERS, index, element); + _listener.afterRemove(A_Impl.this, IN_OTHERS__PROP, index, element); } }; @@ -96,7 +96,7 @@ public A setName(String value) { /** Internal setter for {@link #getName()} without chain call utility. */ protected final void internalSetName(String value) { - _listener.beforeSet(this, NAME, value); + _listener.beforeSet(this, NAME__PROP, value); _name = value; } @@ -113,7 +113,7 @@ public A setContents(A value) { /** Internal setter for {@link #getContents()} without chain call utility. */ protected final void internalSetContents(A value) { - _listener.beforeSet(this, CONTENTS, value); + _listener.beforeSet(this, CONTENTS__PROP, value); _contents = value; } @@ -203,7 +203,7 @@ public A setB(B value) { /** Internal setter for {@link #getB()} without chain call utility. */ protected final void internalSetB(B value) { - _listener.beforeSet(this, B, value); + _listener.beforeSet(this, B__PROP, value); if (_b != null) { ((B_Impl) _b).removeInB(this); } @@ -231,7 +231,7 @@ public A setOther(A value) { /** Internal setter for {@link #getOther()} without chain call utility. */ protected final void internalSetOther(A value) { - _listener.beforeSet(this, OTHER, value); + _listener.beforeSet(this, OTHER__PROP, value); if (_other != null) { ((A_Impl) _other).removeInOther(this); } @@ -371,15 +371,15 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - NAME, - CONTENTS, - CHILDREN, - BS, - B, - OTHER, - OTHERS, - IN_OTHER, - IN_OTHERS)); + NAME__PROP, + CONTENTS__PROP, + CHILDREN__PROP, + BS__PROP, + B__PROP, + OTHER__PROP, + OTHERS__PROP, + IN_OTHER__PROP, + IN_OTHERS__PROP)); @Override public java.util.List properties() { @@ -389,15 +389,15 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case NAME: return getName(); - case CONTENTS: return getContents(); - case CHILDREN: return getChildren(); - case BS: return getBs(); - case B: return getB(); - case OTHER: return getOther(); - case OTHERS: return getOthers(); - case IN_OTHER: return getInOther(); - case IN_OTHERS: return getInOthers(); + case NAME__PROP: return getName(); + case CONTENTS__PROP: return getContents(); + case CHILDREN__PROP: return getChildren(); + case BS__PROP: return getBs(); + case B__PROP: return getB(); + case OTHER__PROP: return getOther(); + case OTHERS__PROP: return getOthers(); + case IN_OTHER__PROP: return getInOther(); + case IN_OTHERS__PROP: return getInOthers(); default: return A.super.get(field); } } @@ -405,13 +405,13 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case NAME: internalSetName((String) value); break; - case CONTENTS: internalSetContents((A) value); break; - case CHILDREN: internalSetChildren(de.haumacher.msgbuf.util.Conversions.asList(A.class, value)); break; - case BS: internalSetBs(de.haumacher.msgbuf.util.Conversions.asList(B.class, value)); break; - case B: internalSetB((B) value); break; - case OTHER: internalSetOther((A) value); break; - case OTHERS: internalSetOthers(de.haumacher.msgbuf.util.Conversions.asList(A.class, value)); break; + case NAME__PROP: internalSetName((String) value); break; + case CONTENTS__PROP: internalSetContents((A) value); break; + case CHILDREN__PROP: internalSetChildren(de.haumacher.msgbuf.util.Conversions.asList(A.class, value)); break; + case BS__PROP: internalSetBs(de.haumacher.msgbuf.util.Conversions.asList(B.class, value)); break; + case B__PROP: internalSetB((B) value); break; + case OTHER__PROP: internalSetOther((A) value); break; + case OTHERS__PROP: internalSetOthers(de.haumacher.msgbuf.util.Conversions.asList(A.class, value)); break; } } @@ -423,33 +423,33 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(NAME); + out.name(NAME__PROP); out.value(getName()); if (hasContents()) { - out.name(CONTENTS); + out.name(CONTENTS__PROP); getContents().writeTo(out); } - out.name(CHILDREN); + out.name(CHILDREN__PROP); out.beginArray(); for (A x : getChildren()) { x.writeTo(out); } out.endArray(); - out.name(BS); + out.name(BS__PROP); out.beginArray(); for (B x : getBs()) { x.writeTo(out); } out.endArray(); if (hasB()) { - out.name(B); + out.name(B__PROP); getB().writeTo(out); } if (hasOther()) { - out.name(OTHER); + out.name(OTHER__PROP); getOther().writeTo(out); } - out.name(OTHERS); + out.name(OTHERS__PROP); out.beginArray(); for (A x : getOthers()) { x.writeTo(out); @@ -460,9 +460,9 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case NAME: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; - case CONTENTS: setContents(test.references.data.A.readA(in)); break; - case CHILDREN: { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case CONTENTS__PROP: setContents(test.references.data.A.readA(in)); break; + case CHILDREN__PROP: { in.beginArray(); while (in.hasNext()) { addChildren(test.references.data.A.readA(in)); @@ -470,7 +470,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t in.endArray(); } break; - case BS: { + case BS__PROP: { in.beginArray(); while (in.hasNext()) { addBs(test.references.data.B.readB(in)); @@ -478,9 +478,9 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t in.endArray(); } break; - case B: setB(test.references.data.B.readB(in)); break; - case OTHER: setOther(test.references.data.A.readA(in)); break; - case OTHERS: { + case B__PROP: setB(test.references.data.B.readB(in)); break; + case OTHER__PROP: setOther(test.references.data.A.readA(in)); break; + case OTHERS__PROP: { in.beginArray(); while (in.hasNext()) { addOthers(test.references.data.A.readA(in)); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java index 4970f3c6..44704947 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java @@ -13,13 +13,13 @@ static B create() { static final String B__TYPE = "B"; /** @see #getName() */ - static final String NAME = "name"; + static final String NAME__PROP = "name"; /** @see #getInBs() */ - static final String IN_BS = "inBs"; + static final String IN_BS__PROP = "inBs"; /** @see #getInB() */ - static final String IN_B = "inB"; + static final String IN_B__PROP = "inB"; /** Identifier for the property {@link #getName()} in binary format. */ static final int NAME__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B_Impl.java index ecc15651..374557cc 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B_Impl.java @@ -7,24 +7,24 @@ class B_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements B { private final java.util.List _inBs = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, A element) { - _listener.beforeAdd(B_Impl.this, IN_BS, index, element); + _listener.beforeAdd(B_Impl.this, IN_BS__PROP, index, element); } @Override protected void afterRemove(int index, A element) { - _listener.afterRemove(B_Impl.this, IN_BS, index, element); + _listener.afterRemove(B_Impl.this, IN_BS__PROP, index, element); } }; private final java.util.List _inB = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, A element) { - _listener.beforeAdd(B_Impl.this, IN_B, index, element); + _listener.beforeAdd(B_Impl.this, IN_B__PROP, index, element); } @Override protected void afterRemove(int index, A element) { - _listener.afterRemove(B_Impl.this, IN_B, index, element); + _listener.afterRemove(B_Impl.this, IN_B__PROP, index, element); } }; @@ -50,7 +50,7 @@ public B setName(String value) { /** Internal setter for {@link #getName()} without chain call utility. */ protected final void internalSetName(String value) { - _listener.beforeSet(this, NAME, value); + _listener.beforeSet(this, NAME__PROP, value); _name = value; } @@ -145,9 +145,9 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - NAME, - IN_BS, - IN_B)); + NAME__PROP, + IN_BS__PROP, + IN_B__PROP)); @Override public java.util.List properties() { @@ -157,9 +157,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case NAME: return getName(); - case IN_BS: return getInBs(); - case IN_B: return getInB(); + case NAME__PROP: return getName(); + case IN_BS__PROP: return getInBs(); + case IN_B__PROP: return getInB(); default: return B.super.get(field); } } @@ -167,7 +167,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case NAME: internalSetName((String) value); break; + case NAME__PROP: internalSetName((String) value); break; } } @@ -179,14 +179,14 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(NAME); + out.name(NAME__PROP); out.value(getName()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case NAME: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java index 81961b43..899e4747 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java @@ -13,13 +13,13 @@ static SearchRequest create() { static final String SEARCH_REQUEST__TYPE = "SearchRequest"; /** @see #getQuery() */ - static final String QUERY = "query"; + static final String QUERY__PROP = "query"; /** @see #getPageNumber() */ - static final String PAGE_NUMBER = "page_number"; + static final String PAGE_NUMBER__PROP = "page_number"; /** @see #getResultPerPage() */ - static final String RESULT_PER_PAGE = "result_per_page"; + static final String RESULT_PER_PAGE__PROP = "result_per_page"; /** Identifier for the property {@link #getQuery()} in binary format. */ static final int QUERY__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest_Impl.java index b4822381..e12ba7cd 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest_Impl.java @@ -30,7 +30,7 @@ public SearchRequest setQuery(String value) { /** Internal setter for {@link #getQuery()} without chain call utility. */ protected final void internalSetQuery(String value) { - _listener.beforeSet(this, QUERY, value); + _listener.beforeSet(this, QUERY__PROP, value); _query = value; } @@ -47,7 +47,7 @@ public SearchRequest setPageNumber(int value) { /** Internal setter for {@link #getPageNumber()} without chain call utility. */ protected final void internalSetPageNumber(int value) { - _listener.beforeSet(this, PAGE_NUMBER, value); + _listener.beforeSet(this, PAGE_NUMBER__PROP, value); _pageNumber = value; } @@ -64,7 +64,7 @@ public SearchRequest setResultPerPage(int value) { /** Internal setter for {@link #getResultPerPage()} without chain call utility. */ protected final void internalSetResultPerPage(int value) { - _listener.beforeSet(this, RESULT_PER_PAGE, value); + _listener.beforeSet(this, RESULT_PER_PAGE__PROP, value); _resultPerPage = value; } @@ -97,9 +97,9 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - QUERY, - PAGE_NUMBER, - RESULT_PER_PAGE)); + QUERY__PROP, + PAGE_NUMBER__PROP, + RESULT_PER_PAGE__PROP)); @Override public java.util.List properties() { @@ -109,9 +109,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case QUERY: return getQuery(); - case PAGE_NUMBER: return getPageNumber(); - case RESULT_PER_PAGE: return getResultPerPage(); + case QUERY__PROP: return getQuery(); + case PAGE_NUMBER__PROP: return getPageNumber(); + case RESULT_PER_PAGE__PROP: return getResultPerPage(); default: return SearchRequest.super.get(field); } } @@ -119,9 +119,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case QUERY: internalSetQuery((String) value); break; - case PAGE_NUMBER: internalSetPageNumber((int) value); break; - case RESULT_PER_PAGE: internalSetResultPerPage((int) value); break; + case QUERY__PROP: internalSetQuery((String) value); break; + case PAGE_NUMBER__PROP: internalSetPageNumber((int) value); break; + case RESULT_PER_PAGE__PROP: internalSetResultPerPage((int) value); break; } } @@ -133,20 +133,20 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(QUERY); + out.name(QUERY__PROP); out.value(getQuery()); - out.name(PAGE_NUMBER); + out.name(PAGE_NUMBER__PROP); out.value(getPageNumber()); - out.name(RESULT_PER_PAGE); + out.name(RESULT_PER_PAGE__PROP); out.value(getResultPerPage()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case QUERY: setQuery(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; - case PAGE_NUMBER: setPageNumber(in.nextInt()); break; - case RESULT_PER_PAGE: setResultPerPage(in.nextInt()); break; + case QUERY__PROP: setQuery(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case PAGE_NUMBER__PROP: setPageNumber(in.nextInt()); break; + case RESULT_PER_PAGE__PROP: setResultPerPage(in.nextInt()); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java index c5506675..c30a2f3f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java @@ -13,7 +13,7 @@ static AnnotatedMessage create() { static final String ANNOTATED_MESSAGE__TYPE = "m1"; /** @see #getAnnotatedField() */ - static final String ANNOTATED_FIELD = "f1"; + static final String ANNOTATED_FIELD__PROP = "f1"; /** Identifier for the {@link AnnotatedMessage} type in binary format. */ static final int ANNOTATED_MESSAGE__TYPE_ID = 2; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage_Impl.java index d469cb11..05422144 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage_Impl.java @@ -31,7 +31,7 @@ public AnnotatedMessage setAnnotatedField(String value) { /** Internal setter for {@link #getAnnotatedField()} without chain call utility. */ protected final void internalSetAnnotatedField(String value) { - _listener.beforeSet(this, ANNOTATED_FIELD, value); + _listener.beforeSet(this, ANNOTATED_FIELD__PROP, value); _annotatedField = value; } @@ -42,7 +42,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - ANNOTATED_FIELD)); + ANNOTATED_FIELD__PROP)); @Override public java.util.List properties() { @@ -52,7 +52,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case ANNOTATED_FIELD: return getAnnotatedField(); + case ANNOTATED_FIELD__PROP: return getAnnotatedField(); default: return super.get(field); } } @@ -60,7 +60,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case ANNOTATED_FIELD: internalSetAnnotatedField((String) value); break; + case ANNOTATED_FIELD__PROP: internalSetAnnotatedField((String) value); break; default: super.set(field, value); break; } } @@ -68,14 +68,14 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(ANNOTATED_FIELD); + out.name(ANNOTATED_FIELD__PROP); out.value(getAnnotatedField()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case ANNOTATED_FIELD: setAnnotatedField(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case ANNOTATED_FIELD__PROP: setAnnotatedField(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java index e389dbf6..c4e8d81b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java @@ -13,7 +13,7 @@ static SomeName create() { static final String SOME_NAME__TYPE = "some_name"; /** @see #getMyField() */ - static final String MY_FIELD = "my_field"; + static final String MY_FIELD__PROP = "my_field"; /** Identifier for the {@link SomeName} type in binary format. */ static final int SOME_NAME__TYPE_ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName_Impl.java index fee4be73..5fa15dba 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName_Impl.java @@ -31,7 +31,7 @@ public SomeName setMyField(String value) { /** Internal setter for {@link #getMyField()} without chain call utility. */ protected final void internalSetMyField(String value) { - _listener.beforeSet(this, MY_FIELD, value); + _listener.beforeSet(this, MY_FIELD__PROP, value); _myField = value; } @@ -42,7 +42,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - MY_FIELD)); + MY_FIELD__PROP)); @Override public java.util.List properties() { @@ -52,7 +52,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case MY_FIELD: return getMyField(); + case MY_FIELD__PROP: return getMyField(); default: return super.get(field); } } @@ -60,7 +60,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case MY_FIELD: internalSetMyField((String) value); break; + case MY_FIELD__PROP: internalSetMyField((String) value); break; default: super.set(field, value); break; } } @@ -68,14 +68,14 @@ public void set(String field, Object value) { @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(MY_FIELD); + out.name(MY_FIELD__PROP); out.value(getMyField()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case MY_FIELD: setMyField(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case MY_FIELD__PROP: setMyField(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; default: super.readField(in, field); } } From 0e0dc7c8b8dc3704a8fedc8aede9cf5f3049041c Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 28 Oct 2022 20:40:02 +0200 Subject: [PATCH 009/207] Prevent NPE in case of error in protocol definition. --- .../main/java/de/haumacher/msgbuf/generator/NameTable.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java index 3ec75c93..c6174b71 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java @@ -119,6 +119,10 @@ public Definition lookup(MessageDef context, QName name) { String baseName = name.getNames().get(0); Definition base = lookupBase(context, baseName); + if (base == null) { + System.out.println("ERROR: Name cannot be resolved" + (context == null ? "" : " in '" + context.getName() + "'") + ": " + baseName); + return null; + } for (int n = 1; n < name.getNames().size(); n++) { String nextName = name.getNames().get(n); Definition inner = lookupInner(base, nextName); From 8e4d3c77452df8d2512ed4964e73b973a2ef3e29 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 28 Oct 2022 20:40:39 +0200 Subject: [PATCH 010/207] Added constants to call main() programatically. --- .../haumacher/msgbuf/generator/Generator.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java index 46367bee..a554b7a9 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java @@ -40,6 +40,16 @@ */ public class Generator { + /** + * Argument giving the output directory. + */ + public static final String OUTPUT_DIR_ARG = "-out"; + + /** + * Argument giving the fully qualified class name of a generator plugin. + */ + public static final String PLUGIN_ARG = "-p"; + private NameTable _table = new NameTable(); private File _out = new File("."); private List _files = new ArrayList<>(); @@ -234,7 +244,10 @@ protected void error(String message, IOException ex) { } } - public static void main(String[] args) throws ParseException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException { + /** + * Main entry point invoked from the command line. + */ + public static void main(String... args) throws ParseException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException { if (args.length == 0) { printHelp(); return; @@ -244,12 +257,12 @@ public static void main(String[] args) throws ParseException, IOException, Insta Generator generator = new Generator(); for (int n = 0, cnt = args.length; n < cnt; ) { String arg = args[n++]; - if (arg.equals("-out")) { + if (arg.equals(OUTPUT_DIR_ARG)) { out = new File(args[n++]); } else if (arg.equals("-h")) { printHelp(); return; - } else if (arg.equals("-p")) { + } else if (arg.equals(PLUGIN_ARG)) { plugin = plugin.andThen((GeneratorPlugin) Class.forName(args[n++]).newInstance()); } else { File file = new File(arg); From 78462d17a00f79ce89106a8c06bbd0470b93bf48 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 28 Oct 2022 20:41:42 +0200 Subject: [PATCH 011/207] Added maven plugin for generating protocol code. --- .settings/org.eclipse.core.resources.prefs | 2 + .../org.eclipse.core.resources.prefs | 2 +- msgbuf-generator-maven-plugin/.classpath | 33 ++++ msgbuf-generator-maven-plugin/.gitignore | 1 + msgbuf-generator-maven-plugin/.project | 23 +++ .../org.eclipse.core.resources.prefs | 5 + .../.settings/org.eclipse.jdt.core.prefs | 8 + .../.settings/org.eclipse.m2e.core.prefs | 4 + msgbuf-generator-maven-plugin/pom.xml | 147 ++++++++++++++++++ .../src/it/settings.xml | 37 +++++ .../src/it/simple-it/pom.xml | 34 ++++ .../src/it/simple-it/verify.groovy | 3 + .../maven/GenerateMessageClasses.java | 80 ++++++++++ .../maven/TestGenerateMessageClasses.java | 42 +++++ .../test/resources/project-to-test/pom.xml | 19 +++ .../src/main/java/my/company/my-data.proto | 5 + msgbuf-parent/pom.xml | 64 ++++++-- pom.xml | 17 +- 18 files changed, 497 insertions(+), 29 deletions(-) create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 msgbuf-generator-maven-plugin/.classpath create mode 100644 msgbuf-generator-maven-plugin/.gitignore create mode 100644 msgbuf-generator-maven-plugin/.project create mode 100644 msgbuf-generator-maven-plugin/.settings/org.eclipse.core.resources.prefs create mode 100644 msgbuf-generator-maven-plugin/.settings/org.eclipse.jdt.core.prefs create mode 100644 msgbuf-generator-maven-plugin/.settings/org.eclipse.m2e.core.prefs create mode 100644 msgbuf-generator-maven-plugin/pom.xml create mode 100644 msgbuf-generator-maven-plugin/src/it/settings.xml create mode 100644 msgbuf-generator-maven-plugin/src/it/simple-it/pom.xml create mode 100644 msgbuf-generator-maven-plugin/src/it/simple-it/verify.groovy create mode 100644 msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java create mode 100644 msgbuf-generator-maven-plugin/src/test/java/de/haumacher/msgbuf/generator/maven/TestGenerateMessageClasses.java create mode 100644 msgbuf-generator-maven-plugin/src/test/resources/project-to-test/pom.xml create mode 100644 msgbuf-generator-maven-plugin/src/test/resources/project-to-test/src/main/java/my/company/my-data.proto diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..6d656553 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=utf-8 diff --git a/de.haumacher.msgbuf/.settings/org.eclipse.core.resources.prefs b/de.haumacher.msgbuf/.settings/org.eclipse.core.resources.prefs index a4d19936..b5ca0296 100644 --- a/de.haumacher.msgbuf/.settings/org.eclipse.core.resources.prefs +++ b/de.haumacher.msgbuf/.settings/org.eclipse.core.resources.prefs @@ -1,5 +1,5 @@ eclipse.preferences.version=1 encoding//src/main/java=utf-8 -encoding//src/main/resources=UTF-8 +encoding//src/main/resources=utf-8 encoding//src/test/java=utf-8 encoding/=utf-8 diff --git a/msgbuf-generator-maven-plugin/.classpath b/msgbuf-generator-maven-plugin/.classpath new file mode 100644 index 00000000..2fcc9100 --- /dev/null +++ b/msgbuf-generator-maven-plugin/.classpath @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msgbuf-generator-maven-plugin/.gitignore b/msgbuf-generator-maven-plugin/.gitignore new file mode 100644 index 00000000..b83d2226 --- /dev/null +++ b/msgbuf-generator-maven-plugin/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/msgbuf-generator-maven-plugin/.project b/msgbuf-generator-maven-plugin/.project new file mode 100644 index 00000000..0ef94a5a --- /dev/null +++ b/msgbuf-generator-maven-plugin/.project @@ -0,0 +1,23 @@ + + + msgbuf-generator-maven-plugin + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/msgbuf-generator-maven-plugin/.settings/org.eclipse.core.resources.prefs b/msgbuf-generator-maven-plugin/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..cdfe4f1b --- /dev/null +++ b/msgbuf-generator-maven-plugin/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/msgbuf-generator-maven-plugin/.settings/org.eclipse.jdt.core.prefs b/msgbuf-generator-maven-plugin/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..2af1e7b9 --- /dev/null +++ b/msgbuf-generator-maven-plugin/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=11 diff --git a/msgbuf-generator-maven-plugin/.settings/org.eclipse.m2e.core.prefs b/msgbuf-generator-maven-plugin/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..f897a7f1 --- /dev/null +++ b/msgbuf-generator-maven-plugin/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml new file mode 100644 index 00000000..b56f4257 --- /dev/null +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -0,0 +1,147 @@ + + + + + 4.0.0 + + + de.haumacher.msgbuf + msgbuf-parent + 1.1.0-SNAPSHOT + + + msgbuf-generator-maven-plugin + + maven-plugin + + + Maven Plugin for generating classes with the MsgBuf compiler. + + + + ${maven.version} + + + + UTF-8 + 11 + 11 + + + + + de.haumacher.msgbuf + msgbuf-generator + 1.1.0-SNAPSHOT + + + + org.apache.maven + maven-plugin-api + ${maven.version} + provided + + + org.apache.maven + maven-core + ${maven.version} + provided + + + org.apache.maven + maven-artifact + ${maven.version} + provided + + + org.apache.maven + maven-compat + ${maven.version} + test + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.6.0 + provided + + + junit + junit + 4.12 + test + + + org.apache.maven.plugin-testing + maven-plugin-testing-harness + 3.3.0 + test + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.6.4 + + + + + + mojo-descriptor + + descriptor + + + + help-goal + + helpmojo + + + + + + + + + + run-its + + + + org.apache.maven.plugins + maven-invoker-plugin + 3.1.0 + + true + ${project.build.directory}/it + + */pom.xml + + verify + ${project.build.directory}/local-repo + src/it/settings.xml + + clean + test-compile + + + + + integration-test + + install + integration-test + verify + + + + + + + + + \ No newline at end of file diff --git a/msgbuf-generator-maven-plugin/src/it/settings.xml b/msgbuf-generator-maven-plugin/src/it/settings.xml new file mode 100644 index 00000000..000e7266 --- /dev/null +++ b/msgbuf-generator-maven-plugin/src/it/settings.xml @@ -0,0 +1,37 @@ + + + + + + + it-repo + + true + + + + local.central + @localRepositoryUrl@ + + true + + + true + + + + + + local.central + @localRepositoryUrl@ + + true + + + true + + + + + + diff --git a/msgbuf-generator-maven-plugin/src/it/simple-it/pom.xml b/msgbuf-generator-maven-plugin/src/it/simple-it/pom.xml new file mode 100644 index 00000000..4e81df15 --- /dev/null +++ b/msgbuf-generator-maven-plugin/src/it/simple-it/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + de.haumacher.msgbuf.it + simple-it + 1.0-SNAPSHOT + + A simple IT verifying the basic use case. + + + UTF-8 + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + touch + validate + + touch + + + + + + + diff --git a/msgbuf-generator-maven-plugin/src/it/simple-it/verify.groovy b/msgbuf-generator-maven-plugin/src/it/simple-it/verify.groovy new file mode 100644 index 00000000..7b307c78 --- /dev/null +++ b/msgbuf-generator-maven-plugin/src/it/simple-it/verify.groovy @@ -0,0 +1,3 @@ +File touchFile = new File( basedir, "target/touch.txt" ); + +assert touchFile.isFile() diff --git a/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java b/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java new file mode 100644 index 00000000..7ab16c10 --- /dev/null +++ b/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java @@ -0,0 +1,80 @@ +package de.haumacher.msgbuf.generator.maven; + +import java.io.File; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +import de.haumacher.msgbuf.generator.Generator; + +/** + * Goal that invokes the MsgBuf compiler. + */ +@Mojo(name = GenerateMessageClasses.NAME, defaultPhase = LifecyclePhase.PROCESS_SOURCES) +public class GenerateMessageClasses extends AbstractMojo { + + /** + * Name of the target. + */ + public static final String NAME = "generate"; + + /** + * Directory where to generate source code to. + */ + @Parameter(defaultValue = "${project.build.sourceDirectory}", property = "outputDir", required = true) + private File _outputDirectory; + + /** + * Input where to search for *.proto files. + */ + @Parameter(defaultValue = "${project.build.sourceDirectory}", property = "input", required = true) + private File _input; + + @Override + public void execute() throws MojoExecutionException { + File outputDirectory = _outputDirectory; + if (!outputDirectory.exists()) { + outputDirectory.mkdirs(); + } + + try { + List files; + if (_input.isDirectory()) { + files = Files.walk(_input.toPath()) + .filter(p -> p.toFile().isFile()) + .filter(p -> p.getFileName().toString().endsWith(".proto")) + .map(p -> p.toAbsolutePath().toString()) + .collect(Collectors.toList()); + } else { + files = Collections.singletonList(_input.getAbsolutePath()); + } + if (files.isEmpty()) { + getLog().info("No protocol files found, skipping."); + return; + } + + ArrayList argList = new ArrayList<>(Arrays.asList(Generator.OUTPUT_DIR_ARG, _outputDirectory.getAbsolutePath())); + argList.addAll(files); + String[] args = argList.toArray(new String[0]); + Generator.main(args); + } catch (Throwable ex) { + throw new MojoExecutionException("Failed to invoke the generatore: " + ex.getMessage(), ex); + } + } + + /** + * The directory where source files are generated to. + */ + public File getOutputDirectory() { + return _outputDirectory; + } +} diff --git a/msgbuf-generator-maven-plugin/src/test/java/de/haumacher/msgbuf/generator/maven/TestGenerateMessageClasses.java b/msgbuf-generator-maven-plugin/src/test/java/de/haumacher/msgbuf/generator/maven/TestGenerateMessageClasses.java new file mode 100644 index 00000000..79235b86 --- /dev/null +++ b/msgbuf-generator-maven-plugin/src/test/java/de/haumacher/msgbuf/generator/maven/TestGenerateMessageClasses.java @@ -0,0 +1,42 @@ +package de.haumacher.msgbuf.generator.maven; + +import static org.junit.Assert.*; + +import java.io.File; + +import org.apache.maven.plugin.testing.MojoRule; +import org.junit.Rule; +import org.junit.Test; + +public class TestGenerateMessageClasses { + @Rule + public MojoRule rule = new MojoRule() { + @Override + protected void before() throws Throwable { + } + + @Override + protected void after() { + } + }; + + @Test + public void testSomething() throws Exception { + File pom = new File("target/test-classes/project-to-test/"); + assertNotNull(pom); + assertTrue(pom.exists()); + + GenerateMessageClasses generate = + (GenerateMessageClasses) rule.lookupConfiguredMojo(pom, GenerateMessageClasses.NAME); + assertNotNull(generate); + generate.execute(); + + File outputDirectory = (File) generate.getOutputDirectory(); + assertNotNull(outputDirectory); + assertTrue(outputDirectory.exists()); + + File touch = new File(outputDirectory, "my/company/MyMessage.java"); + assertTrue(touch.exists()); + } + +} diff --git a/msgbuf-generator-maven-plugin/src/test/resources/project-to-test/pom.xml b/msgbuf-generator-maven-plugin/src/test/resources/project-to-test/pom.xml new file mode 100644 index 00000000..7400a0c9 --- /dev/null +++ b/msgbuf-generator-maven-plugin/src/test/resources/project-to-test/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + + de.haumacher.msgbuf + msgbuf-generator-maven-plugin + 1.1.0-SNAPSHOT + jar + + Test Generator Plugin + + + + + msgbuf-generator-maven-plugin + + + + \ No newline at end of file diff --git a/msgbuf-generator-maven-plugin/src/test/resources/project-to-test/src/main/java/my/company/my-data.proto b/msgbuf-generator-maven-plugin/src/test/resources/project-to-test/src/main/java/my/company/my-data.proto new file mode 100644 index 00000000..ecf8cdc9 --- /dev/null +++ b/msgbuf-generator-maven-plugin/src/test/resources/project-to-test/src/main/java/my/company/my-data.proto @@ -0,0 +1,5 @@ +package my.company; + +message MyMessage { + string value; +} \ No newline at end of file diff --git a/msgbuf-parent/pom.xml b/msgbuf-parent/pom.xml index ae238a03..6ad083f3 100644 --- a/msgbuf-parent/pom.xml +++ b/msgbuf-parent/pom.xml @@ -23,25 +23,63 @@ + + 11 + 11 + utf-8 + 3.3.9 + + + + + + + maven-clean-plugin + 3.1.0 + + + maven-resources-plugin + 3.2.0 + + + maven-compiler-plugin + 3.10.1 + + + maven-plugin-plugin + 3.6.4 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + maven-invoker-plugin + 3.1.0 + + + + maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - UTF-8 - - - - - - org.apache.maven.plugins - maven-resources-plugin - 3.2.0 + 11 + 11 UTF-8 diff --git a/pom.xml b/pom.xml index f680da32..e8d5ad1b 100644 --- a/pom.xml +++ b/pom.xml @@ -10,6 +10,7 @@ de.haumacher.msgbuf de.haumacher.msgbuf.generator + msgbuf-generator-maven-plugin MsgBuf Parent @@ -52,25 +53,11 @@ 11 11 utf-8 + 3.3.9 - - maven-compiler-plugin - 3.10.1 - - - - - org.apache.maven.plugins - maven-resources-plugin - 3.2.0 - - UTF-8 - - - org.apache.maven.plugins From 2da4c4d42068c6ae4f0cec672f22379b871064ce Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Thu, 3 Nov 2022 19:51:29 +0100 Subject: [PATCH 012/207] Use service loader to find code generator plug-ins. --- de.haumacher.msgbuf.generator/pom.xml | 8 ++++++++ ...e.haumacher.msgbuf.generator.GeneratorPlugin | 1 + .../haumacher/msgbuf/generator/Generator.java | 17 +++++++++-------- 3 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 de.haumacher.msgbuf.generator/src/main/java/META-INF/services/de.haumacher.msgbuf.generator.GeneratorPlugin diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 9eed341e..fd55bdf6 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -46,6 +46,14 @@ + + + ${project.build.sourceDirectory} + + **/*.java + + + maven-compiler-plugin diff --git a/de.haumacher.msgbuf.generator/src/main/java/META-INF/services/de.haumacher.msgbuf.generator.GeneratorPlugin b/de.haumacher.msgbuf.generator/src/main/java/META-INF/services/de.haumacher.msgbuf.generator.GeneratorPlugin new file mode 100644 index 00000000..020ede1a --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/main/java/META-INF/services/de.haumacher.msgbuf.generator.GeneratorPlugin @@ -0,0 +1 @@ +de.haumacher.msgbuf.generator.plugins.XmlStreamingPlugin \ No newline at end of file diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java index a554b7a9..b88ff1bd 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.ServiceLoader; import de.haumacher.msgbuf.generator.ast.CustomType; import de.haumacher.msgbuf.generator.ast.Definition; @@ -45,11 +46,6 @@ public class Generator { */ public static final String OUTPUT_DIR_ARG = "-out"; - /** - * Argument giving the fully qualified class name of a generator plugin. - */ - public static final String PLUGIN_ARG = "-p"; - private NameTable _table = new NameTable(); private File _out = new File("."); private List _files = new ArrayList<>(); @@ -253,7 +249,6 @@ public static void main(String... args) throws ParseException, IOException, Inst return; } File out = null; - GeneratorPlugin plugin = GeneratorPlugin.none(); Generator generator = new Generator(); for (int n = 0, cnt = args.length; n < cnt; ) { String arg = args[n++]; @@ -262,8 +257,6 @@ public static void main(String... args) throws ParseException, IOException, Inst } else if (arg.equals("-h")) { printHelp(); return; - } else if (arg.equals(PLUGIN_ARG)) { - plugin = plugin.andThen((GeneratorPlugin) Class.forName(args[n++]).newInstance()); } else { File file = new File(arg); DefinitionFile content = generator.load(file); @@ -275,6 +268,14 @@ public static void main(String... args) throws ParseException, IOException, Inst if (out != null) { generator.setOut(out); } + + ServiceLoader pluginLoader = ServiceLoader.load(GeneratorPlugin.class); + + GeneratorPlugin plugin = GeneratorPlugin.none(); + for (GeneratorPlugin p : pluginLoader) { + plugin = plugin.andThen(p); + } + generator.generate(plugin); } From 399f3fc848387159b5b16da84877fe19424ed281 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 4 Nov 2022 19:04:02 +0100 Subject: [PATCH 013/207] Added XML serialization functionality. --- .../msgbuf/generator/CodeConvention.java | 5 + .../msgbuf/generator/EnumGenerator.java | 4 +- .../msgbuf/generator/GeneratorPlugin.java | 21 +++ .../msgbuf/generator/MessageGenerator.java | 4 +- .../generator/plugins/XmlStreamingPlugin.java | 161 ++++++++++++++++++ .../test/comments/data/SearchRequest.java | 2 +- .../comments/data/SearchRequest_Impl.java | 22 +++ .../test/enumeration/data/SearchRequest.java | 2 +- .../enumeration/data/SearchRequest_Impl.java | 23 +++ .../test/graph/data/AtomicShape_Impl.java | 12 ++ .../test/java/test/graph/data/Car_Impl.java | 32 ++++ .../java/test/graph/data/Circle_Impl.java | 18 ++ .../test/java/test/graph/data/Group_Impl.java | 22 +++ .../java/test/graph/data/Rectangle_Impl.java | 19 +++ .../src/test/java/test/graph/data/Shape.java | 2 +- .../test/java/test/graph/data/Shape_Impl.java | 16 ++ .../test/hierarchy/data/AtomicShape_Impl.java | 12 ++ .../java/test/hierarchy/data/Car_Impl.java | 32 ++++ .../java/test/hierarchy/data/Circle_Impl.java | 18 ++ .../java/test/hierarchy/data/Group_Impl.java | 22 +++ .../test/hierarchy/data/Optional_Impl.java | 23 +++ .../test/hierarchy/data/Rectangle_Impl.java | 19 +++ .../test/java/test/hierarchy/data/Shape.java | 2 +- .../java/test/hierarchy/data/Shape_Impl.java | 17 ++ .../src/test/java/test/innertypeclash/A.java | 4 +- .../test/java/test/innertypeclash/A_Impl.java | 53 ++++++ .../src/test/java/test/innertypeclash/B.java | 4 +- .../test/java/test/innertypeclash/B_Impl.java | 53 ++++++ .../test/java/test/lowercasemessage/A.java | 4 +- .../java/test/lowercasemessage/A_Impl.java | 58 +++++++ .../java/test/maptype/data/MyMessage.java | 2 +- .../test/maptype/data/MyMessage_Impl.java | 19 +++ .../test/java/test/maptype/data/Project.java | 2 +- .../java/test/maptype/data/Project_Impl.java | 21 +++ .../java/test/nested/data/SearchResponse.java | 4 +- .../test/nested/data/SearchResponse_Impl.java | 46 +++++ .../java/test/nointerfaces/AtomicShape.java | 12 ++ .../src/test/java/test/nointerfaces/Car.java | 32 ++++ .../test/java/test/nointerfaces/Circle.java | 18 ++ .../test/java/test/nointerfaces/Group.java | 22 +++ .../java/test/nointerfaces/Rectangle.java | 19 +++ .../test/java/test/nointerfaces/Shape.java | 18 +- .../java/test/nojson/AtomicShape_Impl.java | 12 ++ .../src/test/java/test/nojson/Car_Impl.java | 32 ++++ .../test/java/test/nojson/Circle_Impl.java | 18 ++ .../src/test/java/test/nojson/Group_Impl.java | 22 +++ .../test/java/test/nojson/Rectangle_Impl.java | 19 +++ .../src/test/java/test/nojson/Shape.java | 2 +- .../src/test/java/test/nojson/Shape_Impl.java | 16 ++ .../test/nolistener/AtomicShape_Impl.java | 12 ++ .../test/java/test/nolistener/Car_Impl.java | 32 ++++ .../java/test/nolistener/Circle_Impl.java | 18 ++ .../test/java/test/nolistener/Group_Impl.java | 22 +++ .../java/test/nolistener/Rectangle_Impl.java | 19 +++ .../src/test/java/test/nolistener/Shape.java | 2 +- .../test/java/test/nolistener/Shape_Impl.java | 16 ++ .../test/noreflection/AtomicShape_Impl.java | 12 ++ .../test/java/test/noreflection/Car_Impl.java | 32 ++++ .../java/test/noreflection/Circle_Impl.java | 18 ++ .../java/test/noreflection/Group_Impl.java | 22 +++ .../test/noreflection/Rectangle_Impl.java | 19 +++ .../test/java/test/noreflection/Shape.java | 2 +- .../java/test/noreflection/Shape_Impl.java | 16 ++ .../test/notypekind/AtomicShape_Impl.java | 12 ++ .../test/java/test/notypekind/Car_Impl.java | 32 ++++ .../java/test/notypekind/Circle_Impl.java | 18 ++ .../test/java/test/notypekind/Group_Impl.java | 22 +++ .../java/test/notypekind/Rectangle_Impl.java | 19 +++ .../src/test/java/test/notypekind/Shape.java | 2 +- .../test/java/test/notypekind/Shape_Impl.java | 16 ++ .../java/test/novisit/AtomicShape_Impl.java | 12 ++ .../src/test/java/test/novisit/Car_Impl.java | 32 ++++ .../test/java/test/novisit/Circle_Impl.java | 18 ++ .../test/java/test/novisit/Group_Impl.java | 22 +++ .../java/test/novisit/Rectangle_Impl.java | 19 +++ .../src/test/java/test/novisit/Shape.java | 2 +- .../test/java/test/novisit/Shape_Impl.java | 16 ++ .../novisitexceptions/AtomicShape_Impl.java | 12 ++ .../java/test/novisitexceptions/Car_Impl.java | 32 ++++ .../test/novisitexceptions/Circle_Impl.java | 18 ++ .../test/novisitexceptions/Group_Impl.java | 22 +++ .../novisitexceptions/Rectangle_Impl.java | 19 +++ .../java/test/novisitexceptions/Shape.java | 2 +- .../test/novisitexceptions/Shape_Impl.java | 16 ++ .../test/nullable/data/NullableValues.java | 2 +- .../nullable/data/NullableValues_Impl.java | 26 +++ .../test/oneoffield/data/SampleMessage.java | 2 +- .../oneoffield/data/SampleMessage_Impl.java | 19 +++ .../test/java/test/onlyxml/TestOnlyXml.java | 17 ++ .../test/onlyxml/data/AtomicShape_Impl.java | 12 ++ .../test/java/test/onlyxml/data/Car_Impl.java | 32 ++++ .../java/test/onlyxml/data/Circle_Impl.java | 18 ++ .../java/test/onlyxml/data/Group_Impl.java | 22 +++ .../java/test/onlyxml/data/Optional_Impl.java | 23 +++ .../test/onlyxml/data/Rectangle_Impl.java | 19 +++ .../test/java/test/onlyxml/data/Shape.java | 2 +- .../java/test/onlyxml/data/Shape_Impl.java | 16 ++ .../java/test/options/data/MyMessage1.java | 2 +- .../test/options/data/MyMessage1_Impl.java | 19 +++ .../java/test/options/data/MyMessage2.java | 2 +- .../test/options/data/MyMessage2_Impl.java | 19 +++ .../src/test/java/test/references/data/A.java | 2 +- .../java/test/references/data/A_Impl.java | 60 +++++++ .../src/test/java/test/references/data/B.java | 2 +- .../java/test/references/data/B_Impl.java | 30 ++++ .../java/test/types/data/SearchRequest.java | 2 +- .../test/types/data/SearchRequest_Impl.java | 22 +++ .../underscorename/AnnotatedMessage_Impl.java | 18 ++ .../java/test/underscorename/BaseMsg.java | 2 +- .../test/underscorename/BaseMsg_Impl.java | 14 ++ .../test/underscorename/SomeName_Impl.java | 18 ++ de.haumacher.msgbuf/.classpath | 1 + .../haumacher/msgbuf/xml/XmlSerializable.java | 45 +++++ .../src/main/java/module-info.java | 24 +-- 114 files changed, 2071 insertions(+), 48 deletions(-) create mode 100644 de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/xml/XmlSerializable.java diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java index 15041c8c..0dd91dfa 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java @@ -252,5 +252,10 @@ public static String classifierName(Constant constant) { * Enum method that resolves an enum value from a protocol string. */ public static final String ENUM_VALUE_OF_PROTOCOL = "valueOfProtocol"; + + /** + * Enum method that returns the protocol string for the classifier. + */ + public static final String ENUM_PROTOCOL_NAME_FUN = "protocolName"; } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/EnumGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/EnumGenerator.java index 6dd60e36..08d3dafd 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/EnumGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/EnumGenerator.java @@ -66,7 +66,7 @@ protected void generate() { line(" * @see #" + CodeConvention.ENUM_VALUE_OF_PROTOCOL + "(String)"); line(" */"); line("@Override"); - line("public String protocolName() {"); + line("public String " + CodeConvention.ENUM_PROTOCOL_NAME_FUN + "() {"); { line("return _protocolName;"); } @@ -91,7 +91,7 @@ protected void generate() { line("/** Writes this instance to the given output. */"); line("public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException {"); { - line("out.value(protocolName());"); + line("out.value(" + CodeConvention.ENUM_PROTOCOL_NAME_FUN + "());"); } line("}"); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java index 41f4bc2b..b27322bb 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java @@ -3,6 +3,7 @@ */ package de.haumacher.msgbuf.generator; +import java.util.List; import java.util.Map; import de.haumacher.msgbuf.generator.ast.MessageDef; @@ -23,6 +24,20 @@ default void init(Map options) { // Ignore. } + /** + * Adds interfaces to the generated type. + * + * @param options + * The options from the top-level definition file. + * @param def + * The {@link MessageDef} that is being translated. + * @param generalizations + * The generalization list to extend. + */ + default void addInterfaces(Map options, MessageDef def, List generalizations) { + // No additional interfaces by default. + } + /** * Creates a {@link FileGenerator} that is expanded within the interface class. * @@ -68,6 +83,12 @@ public void init(Map options) { next.init(options); } + @Override + public void addInterfaces(Map options, MessageDef def, List generalizations) { + self.addInterfaces(options, def, generalizations); + next.addInterfaces(options, def, generalizations); + } + @Override public FileGenerator messageImplContents(Map options, MessageDef def) { return (out, indent) -> { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index fb9a6686..d5343db2 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -164,7 +164,7 @@ private String getExtends() { } addMixins(generalizations); } - + return generalizationList("extends", generalizations); } @@ -200,6 +200,8 @@ private void addImplements(List generalizations) { } private void addMixins(List generalizations) { + _plugin.addInterfaces(_options, _def, generalizations); + Option operations = _def.getOptions().get("Operations"); if (operations != null) { if (operations instanceof StringOption) { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java index c7f5f18d..212ffb3f 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java @@ -40,6 +40,17 @@ public void init(Map options) { _noXmlNames = noXmlNames(options); } + @Override + public void addInterfaces(Map options, MessageDef def, List generalizations) { + if (noXml(options)) { + return; + } + + if (!def.hasExtends()) { + generalizations.add("de.haumacher.msgbuf.xml.XmlSerializable"); + } + } + @Override public FileGenerator messageInterfaceContents(Map options, MessageDef def) { if (noXml(options)) { @@ -80,6 +91,101 @@ protected void generate() { line("private static final String " + xmlFieldNameConstant(field) + " = \"" + xmlFieldName(field) + "\";"); } + if (!def.isAbstract()) { + nl(); + line("@Override"); + line("public String getXmlTagName() {"); + { + line("return " + xmlTypeNameConstant(def) + ";"); + } + line("}"); + } + + if (!def.hasExtends()) { + nl(); + line("@Override"); + line("public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException {"); + { + line("writeAttributes(out);"); + line("writeElements(out);"); + } + line("}"); + } + + nl(); + line("/** Serializes all fields that are written as XML attributes. */"); + if (def.hasExtends()) { + line("@Override"); + } + line("protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException {"); + { + if (def.hasExtends()) { + line("super.writeAttributes(out);"); + } + for (Field field : def.getFields()) { + if (field.getType().kind() == Type.TypeKind.PRIMITIVE_TYPE || isEnum(field.getType())) { + line("out.writeAttribute(" + xmlFieldNameConstant(field) + ", " + asString(field, CodeConvention.getterName(field) + "()") + ");"); + } + } + } + line("}"); + + nl(); + line("/** Serializes all fields that are written as XML elements. */"); + if (def.hasExtends()) { + line("@Override"); + } + line("protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException {"); + { + if (def.hasExtends()) { + line("super.writeElements(out);"); + } + + for (Field field : def.getFields()) { + Type type = field.getType(); + switch (type.kind()) { + case PRIMITIVE_TYPE: { + continue; + } + + case CUSTOM_TYPE: { + Definition typeDefinition = ((CustomType) type).getDefinition(); + if (typeDefinition instanceof EnumDef) { + continue; + } + + boolean nullable = Util.isNullable(field); + if (nullable) { + line("if (" + CodeConvention.hasName(field) + "()" + ") {"); + } + { + line("out.writeStartElement(" + xmlFieldNameConstant(field) + ");"); + if (field.isRepeated()) { + line("for (" + qTypeName(typeDefinition) + " element : " + getterName(field) + "()) {"); + { + line("element.writeTo(out);"); + } + line("}"); + } else { + if (((MessageDef) typeDefinition).isAbstract()) { + // Create element encoding the type. + line(CodeConvention.getterName(field) + "()" + ".writeTo(out);"); + } else { + // Embed into field element. + line(CodeConvention.getterName(field) + "()" + ".writeContent(out);"); + } + } + line("out.writeEndElement();"); + } + if (nullable) { + line("}"); + } + } + } + } + } + line("}"); + nl(); line("/** Creates a new {@link " + typeName(def) + "} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */"); line("public static " + implName(def) + " " + readXmlContent(def) + "(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException {"); @@ -384,11 +490,24 @@ String fromString(Field field, String value) { } } + String asString(Field field, String value) { + Type type = field.getType(); + if (field.isRepeated()) { + return toStringList(type, value); + } else { + return toStringSingle(type, value); + } + } + String fromStringList(de.haumacher.msgbuf.generator.ast.Type type, String value) { return "java.util.Arrays.stream(" + value + ".split(\"\\\\s*,\\\\s*\")).map(x -> " + fromStringSingle(type, "x") + ").collect(java.util.stream.Collectors.toList())"; } + String toStringList(de.haumacher.msgbuf.generator.ast.Type type, String value) { + return value + ".stream().map(x -> " + toStringSingle(type, "x") + ").collect(java.util.stream.Collectors.joining(\", \"))"; + } + String fromStringSingle(de.haumacher.msgbuf.generator.ast.Type type, String value) { if (isEnum(type)) { return CodeConvention.qTypeName(((CustomType) type).getDefinition()) + "." + CodeConvention.ENUM_VALUE_OF_PROTOCOL + "(" + value + ")"; @@ -431,6 +550,48 @@ String fromStringSingle(de.haumacher.msgbuf.generator.ast.Type type, String valu throw new UnsupportedOperationException("Cannot read values of type: " + primitiveType); } + String toStringSingle(de.haumacher.msgbuf.generator.ast.Type type, String value) { + if (isEnum(type)) { + return value + "." + CodeConvention.ENUM_PROTOCOL_NAME_FUN + "()"; + } + + PrimitiveType primitiveType = (PrimitiveType) type; + switch (primitiveType.getKind()) { + case BOOL: + return "Boolean.toString(" + value + ")"; + + case SFIXED_32: + case SINT_32: + case INT_32: + return "Integer.toString(" + value + ")"; + + case FIXED_32: + case UINT_32: + return "(int) Long.toString(" + value + ")"; + + case FIXED_64: + case INT_64: + case UINT_64: + case SFIXED_64: + case SINT_64: + return "Long.toString(" + value + ")"; + + case DOUBLE: + return "Double.toString(" + value + ")"; + + case FLOAT: + return "Float.toString(" + value + ")"; + + case STRING: + return value; + + case BYTES: + return "java.util.Base64.getEncoder().encodeToString(" + value + ");"; + } + + throw new UnsupportedOperationException("Cannot read values of type: " + primitiveType); + } + boolean isEnum(Type type) { return type instanceof CustomType && ((CustomType) type).getDefinition() instanceof EnumDef; } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java index 7294cb10..a2df6217 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java @@ -4,7 +4,7 @@ * SearchRequest represents a search query, with {@link #getPageNumber() pagination options} to * indicate which results to include in the response. */ -public interface SearchRequest extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface SearchRequest extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** * Creates a {@link SearchRequest} instance. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest_Impl.java index 41d1f8d8..f457bf40 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest_Impl.java @@ -215,6 +215,28 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getResultPerPage} property. */ private static final String RESULT_PER_PAGE__XML_ATTR = "result-per-page"; + @Override + public String getXmlTagName() { + return SEARCH_REQUEST__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(QUERY__XML_ATTR, getQuery()); + out.writeAttribute(PAGE_NUMBER__XML_ATTR, Integer.toString(getPageNumber())); + out.writeAttribute(RESULT_PER_PAGE__XML_ATTR, Integer.toString(getResultPerPage())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link SearchRequest} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SearchRequest_Impl readSearchRequest_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SearchRequest_Impl result = new SearchRequest_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java index 47d3f23e..127bfb93 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java @@ -1,6 +1,6 @@ package test.enumeration.data; -public interface SearchRequest extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface SearchRequest extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { public enum Corpus implements de.haumacher.msgbuf.data.ProtocolEnum { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest_Impl.java index 58b5feca..51f7f300 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest_Impl.java @@ -243,6 +243,29 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getCorpus} property. */ private static final String CORPUS__XML_ATTR = "corpus"; + @Override + public String getXmlTagName() { + return SEARCH_REQUEST__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(QUERY__XML_ATTR, getQuery()); + out.writeAttribute(PAGE_NUMBER__XML_ATTR, Integer.toString(getPageNumber())); + out.writeAttribute(RESULT_PER_PAGE__XML_ATTR, Integer.toString(getResultPerPage())); + out.writeAttribute(CORPUS__XML_ATTR, getCorpus().protocolName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link SearchRequest} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SearchRequest_Impl readSearchRequest_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SearchRequest_Impl result = new SearchRequest_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/AtomicShape_Impl.java index 870204b9..d3911db6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/AtomicShape_Impl.java @@ -27,6 +27,18 @@ public AtomicShape setYCoordinate(int value) { /** XML element name representing a {@link AtomicShape} type. */ public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape_Impl readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car_Impl.java index 6dd4dcc8..f7ebd464 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car_Impl.java @@ -209,6 +209,38 @@ public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf /** XML attribute or element name of a {@link #getBody} property. */ private static final String BODY__XML_ATTR = "body"; + @Override + public String getXmlTagName() { + return CAR__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + if (hasWheel1()) { + out.writeStartElement(WHEEL_1__XML_ATTR); + getWheel1().writeContent(out); + out.writeEndElement(); + } + if (hasWheel2()) { + out.writeStartElement(WHEEL_2__XML_ATTR); + getWheel2().writeContent(out); + out.writeEndElement(); + } + if (hasBody()) { + out.writeStartElement(BODY__XML_ATTR); + getBody().writeContent(out); + out.writeEndElement(); + } + } + /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle_Impl.java index 8555965c..811e0380 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle_Impl.java @@ -112,6 +112,24 @@ public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf /** XML attribute or element name of a {@link #getRadius} property. */ private static final String RADIUS__XML_ATTR = "r"; + @Override + public String getXmlTagName() { + return CIRCLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(RADIUS__XML_ATTR, Integer.toString(getRadius())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group_Impl.java index dd222633..e29e6c93 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group_Impl.java @@ -175,6 +175,28 @@ public Object readElement(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.ms /** XML attribute or element name of a {@link #getShapes} property. */ private static final String SHAPES__XML_ATTR = "shapes"; + @Override + public String getXmlTagName() { + return GROUP__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + out.writeStartElement(SHAPES__XML_ATTR); + for (test.graph.data.Shape element : getShapes()) { + element.writeTo(out); + } + out.writeEndElement(); + } + /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle_Impl.java index 21d76dd7..f0217112 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle_Impl.java @@ -144,6 +144,25 @@ public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf /** XML attribute or element name of a {@link #getHeight} property. */ private static final String HEIGHT__XML_ATTR = "h"; + @Override + public String getXmlTagName() { + return RECTANGLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WIDTH__XML_ATTR, Integer.toString(getWidth())); + out.writeAttribute(HEIGHT__XML_ATTR, Integer.toString(getHeight())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java index e9a6fd39..86290181 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java @@ -3,7 +3,7 @@ /** * An abstract base class for all shapes */ -public interface Shape extends de.haumacher.msgbuf.graph.SharedGraphNode { +public interface Shape extends de.haumacher.msgbuf.graph.SharedGraphNode, de.haumacher.msgbuf.xml.XmlSerializable { /** Type codes for the {@link Shape} hierarchy. */ public enum TypeKind { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape_Impl.java index a2710e17..fe28aaa9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape_Impl.java @@ -122,6 +122,22 @@ public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf /** XML attribute or element name of a {@link #getYCoordinate} property. */ private static final String Y_COORDINATE__XML_ATTR = "y"; + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(X_COORDINATE__XML_ATTR, Integer.toString(getXCoordinate())); + out.writeAttribute(Y_COORDINATE__XML_ATTR, Integer.toString(getYCoordinate())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape_Impl.java index ef23d11f..04121ab0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape_Impl.java @@ -33,6 +33,18 @@ public AtomicShape setColor(Color value) { /** XML element name representing a {@link AtomicShape} type. */ public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape_Impl readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car_Impl.java index 09611376..cf9c97c9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car_Impl.java @@ -223,6 +223,38 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getBody} property. */ private static final String BODY__XML_ATTR = "body"; + @Override + public String getXmlTagName() { + return CAR__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + if (hasWheel1()) { + out.writeStartElement(WHEEL_1__XML_ATTR); + getWheel1().writeContent(out); + out.writeEndElement(); + } + if (hasWheel2()) { + out.writeStartElement(WHEEL_2__XML_ATTR); + getWheel2().writeContent(out); + out.writeEndElement(); + } + if (hasBody()) { + out.writeStartElement(BODY__XML_ATTR); + getBody().writeContent(out); + out.writeEndElement(); + } + } + /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle_Impl.java index 0e935e2b..48606990 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle_Impl.java @@ -134,6 +134,24 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getRadius} property. */ private static final String RADIUS__XML_ATTR = "radius"; + @Override + public String getXmlTagName() { + return CIRCLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(RADIUS__XML_ATTR, Integer.toString(getRadius())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group_Impl.java index 5f012203..cedd5d0b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group_Impl.java @@ -186,6 +186,28 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getShapes} property. */ private static final String SHAPES__XML_ATTR = "shapes"; + @Override + public String getXmlTagName() { + return GROUP__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + out.writeStartElement(SHAPES__XML_ATTR); + for (test.hierarchy.data.Shape element : getShapes()) { + element.writeTo(out); + } + out.writeEndElement(); + } + /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional_Impl.java index a830c8b8..4209d530 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional_Impl.java @@ -174,6 +174,29 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getShape} property. */ private static final String SHAPE__XML_ATTR = "shape"; + @Override + public String getXmlTagName() { + return OPTIONAL__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(HIDDEN__XML_ATTR, Boolean.toString(isHidden())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + if (hasShape()) { + out.writeStartElement(SHAPE__XML_ATTR); + getShape().writeTo(out); + out.writeEndElement(); + } + } + /** Creates a new {@link Optional} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Optional_Impl readOptional_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Optional_Impl result = new Optional_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle_Impl.java index 5be10d7e..3548e137 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle_Impl.java @@ -165,6 +165,25 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getHeight} property. */ private static final String HEIGHT__XML_ATTR = "h"; + @Override + public String getXmlTagName() { + return RECTANGLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WIDTH__XML_ATTR, Integer.toString(getWidth())); + out.writeAttribute(HEIGHT__XML_ATTR, Integer.toString(getHeight())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java index 1e47b993..5b3efd11 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java @@ -3,7 +3,7 @@ /** * An abstract base class for all shapes */ -public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** Type codes for the {@link Shape} hierarchy. */ public enum TypeKind { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape_Impl.java index d77f617d..b6a7660f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape_Impl.java @@ -209,6 +209,23 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getColor} property. */ private static final String COLOR__XML_ATTR = "color"; + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(X_COORDINATE__XML_ATTR, Integer.toString(getXCoordinate())); + out.writeAttribute(Y_COORDINATE__XML_ATTR, Integer.toString(getYCoordinate())); + out.writeAttribute(COLOR__XML_ATTR, getColor().protocolName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java index a3616ea6..953b053a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java @@ -1,7 +1,7 @@ package test.innertypeclash; -public interface A extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { - public interface C extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface A extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + public interface C extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** * Creates a {@link C} instance. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A_Impl.java index 6abd7a81..d69c898f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A_Impl.java @@ -87,6 +87,25 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML element name representing a {@link C} type. */ public static final String C__XML_ELEMENT = "c"; + @Override + public String getXmlTagName() { + return C__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link C} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static C_Impl readC_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { C_Impl result = new C_Impl(); @@ -380,6 +399,40 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getC} property. */ private static final String C__XML_ATTR = "c"; + @Override + public String getXmlTagName() { + return A__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasAc()) { + out.writeStartElement(AC__XML_ATTR); + getAc().writeContent(out); + out.writeEndElement(); + } + if (hasBc()) { + out.writeStartElement(BC__XML_ATTR); + getBc().writeContent(out); + out.writeEndElement(); + } + if (hasC()) { + out.writeStartElement(C__XML_ATTR); + getC().writeContent(out); + out.writeEndElement(); + } + } + /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static A_Impl readA_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { A_Impl result = new A_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java index 2f5c249d..6b26e52d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java @@ -1,7 +1,7 @@ package test.innertypeclash; -public interface B extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { - public interface C extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface B extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + public interface C extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** * Creates a {@link C} instance. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B_Impl.java index bf8291e7..271f4010 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B_Impl.java @@ -87,6 +87,25 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML element name representing a {@link C} type. */ public static final String C__XML_ELEMENT = "c"; + @Override + public String getXmlTagName() { + return C__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link C} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static C_Impl readC_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { C_Impl result = new C_Impl(); @@ -380,6 +399,40 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getC} property. */ private static final String C__XML_ATTR = "c"; + @Override + public String getXmlTagName() { + return B__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasAc()) { + out.writeStartElement(AC__XML_ATTR); + getAc().writeContent(out); + out.writeEndElement(); + } + if (hasBc()) { + out.writeStartElement(BC__XML_ATTR); + getBc().writeContent(out); + out.writeEndElement(); + } + if (hasC()) { + out.writeStartElement(C__XML_ATTR); + getC().writeContent(out); + out.writeEndElement(); + } + } + /** Creates a new {@link B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static B_Impl readB_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { B_Impl result = new B_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java index 6d8816ef..747d765b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java @@ -1,7 +1,7 @@ package test.lowercasemessage; -public interface A extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { - public interface B extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface A extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + public interface B extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** * Creates a {@link B} instance. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A_Impl.java index 8735554d..63c86667 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A_Impl.java @@ -199,6 +199,35 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getB1} property. */ private static final String B_1__XML_ATTR = "b-1"; + @Override + public String getXmlTagName() { + return B__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasA1()) { + out.writeStartElement(A_1__XML_ATTR); + getA1().writeContent(out); + out.writeEndElement(); + } + if (hasB1()) { + out.writeStartElement(B_1__XML_ATTR); + getB1().writeContent(out); + out.writeEndElement(); + } + } + /** Creates a new {@link B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static B_Impl readB_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { B_Impl result = new B_Impl(); @@ -460,6 +489,35 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getB1} property. */ private static final String B_1__XML_ATTR = "b-1"; + @Override + public String getXmlTagName() { + return A__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasA1()) { + out.writeStartElement(A_1__XML_ATTR); + getA1().writeContent(out); + out.writeEndElement(); + } + if (hasB1()) { + out.writeStartElement(B_1__XML_ATTR); + getB1().writeContent(out); + out.writeEndElement(); + } + } + /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static A_Impl readA_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { A_Impl result = new A_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java index 4c417506..c011403c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java @@ -1,6 +1,6 @@ package test.maptype.data; -public interface MyMessage extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface MyMessage extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** * Creates a {@link MyMessage} instance. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage_Impl.java index 39529606..afd2a9ea 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage_Impl.java @@ -293,6 +293,25 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getRating} property. */ private static final String RATING__XML_ATTR = "rating"; + @Override + public String getXmlTagName() { + return MY_MESSAGE__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link MyMessage} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static MyMessage_Impl readMyMessage_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { MyMessage_Impl result = new MyMessage_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java index 795d5bba..819f4853 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java @@ -1,6 +1,6 @@ package test.maptype.data; -public interface Project extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface Project extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** * Creates a {@link Project} instance. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project_Impl.java index 44bc6e69..2b1e04f3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project_Impl.java @@ -180,6 +180,27 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getCost} property. */ private static final String COST__XML_ATTR = "cost"; + @Override + public String getXmlTagName() { + return PROJECT__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + out.writeAttribute(COST__XML_ATTR, Double.toString(getCost())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link Project} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Project_Impl readProject_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Project_Impl result = new Project_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java index 155047fc..7393c571 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java @@ -1,7 +1,7 @@ package test.nested.data; -public interface SearchResponse extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { - public interface Result extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface SearchResponse extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + public interface Result extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** * Creates a {@link Result} instance. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse_Impl.java index 33f26f52..41f7ee23 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse_Impl.java @@ -263,6 +263,28 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getSnippets} property. */ private static final String SNIPPETS__XML_ATTR = "snippets"; + @Override + public String getXmlTagName() { + return RESULT__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(URL__XML_ATTR, getUrl()); + out.writeAttribute(TITLE__XML_ATTR, getTitle()); + out.writeAttribute(SNIPPETS__XML_ATTR, getSnippets().stream().map(x -> x).collect(java.util.stream.Collectors.joining(", "))); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link Result} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Result_Impl readResult_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Result_Impl result = new Result_Impl(); @@ -543,6 +565,30 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getResults} property. */ private static final String RESULTS__XML_ATTR = "results"; + @Override + public String getXmlTagName() { + return SEARCH_RESPONSE__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeStartElement(RESULTS__XML_ATTR); + for (test.nested.data.SearchResponse.Result element : getResults()) { + element.writeTo(out); + } + out.writeEndElement(); + } + /** Creates a new {@link SearchResponse} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SearchResponse_Impl readSearchResponse_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SearchResponse_Impl result = new SearchResponse_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/AtomicShape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/AtomicShape.java index c3a5826d..6510b528 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/AtomicShape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/AtomicShape.java @@ -68,6 +68,18 @@ public static AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader /** XML element name representing a {@link AtomicShape} type. */ public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java index 4e4e8a58..d981f3cd 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java @@ -281,6 +281,38 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getBody} property. */ private static final String BODY__XML_ATTR = "body"; + @Override + public String getXmlTagName() { + return CAR__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + if (hasWheel1()) { + out.writeStartElement(WHEEL_1__XML_ATTR); + getWheel1().writeContent(out); + out.writeEndElement(); + } + if (hasWheel2()) { + out.writeStartElement(WHEEL_2__XML_ATTR); + getWheel2().writeContent(out); + out.writeEndElement(); + } + if (hasBody()) { + out.writeStartElement(BODY__XML_ATTR); + getBody().writeContent(out); + out.writeEndElement(); + } + } + /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car result = new Car(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java index 960f74e5..1e838bff 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java @@ -166,6 +166,24 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getRadius} property. */ private static final String RADIUS__XML_ATTR = "r"; + @Override + public String getXmlTagName() { + return CIRCLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(RADIUS__XML_ATTR, Integer.toString(getRadius())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle result = new Circle(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java index dba2df73..23e9c85d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java @@ -226,6 +226,28 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getShapes} property. */ private static final String SHAPES__XML_ATTR = "shapes"; + @Override + public String getXmlTagName() { + return GROUP__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + out.writeStartElement(SHAPES__XML_ATTR); + for (test.nointerfaces.Shape element : getShapes()) { + element.writeTo(out); + } + out.writeEndElement(); + } + /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group result = new Group(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java index 0c740792..5a2c8358 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java @@ -215,6 +215,25 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getHeight} property. */ private static final String HEIGHT__XML_ATTR = "h"; + @Override + public String getXmlTagName() { + return RECTANGLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WIDTH__XML_ATTR, Integer.toString(getWidth())); + out.writeAttribute(HEIGHT__XML_ATTR, Integer.toString(getHeight())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle result = new Rectangle(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java index bfa6eb74..c638051b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java @@ -3,7 +3,7 @@ /** * An abstract base class for all shapes */ -public abstract class Shape extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public abstract class Shape extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** Type codes for the {@link Shape} hierarchy. */ public enum TypeKind { @@ -263,6 +263,22 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getYCoordinate} property. */ private static final String Y_COORDINATE__XML_ATTR = "y"; + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(X_COORDINATE__XML_ATTR, Integer.toString(getXCoordinate())); + out.writeAttribute(Y_COORDINATE__XML_ATTR, Integer.toString(getYCoordinate())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/AtomicShape_Impl.java index 00fb57ed..9fdec356 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/AtomicShape_Impl.java @@ -27,6 +27,18 @@ public AtomicShape setYCoordinate(int value) { /** XML element name representing a {@link AtomicShape} type. */ public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape_Impl readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car_Impl.java index 8f150fb4..1730d500 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car_Impl.java @@ -190,6 +190,38 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getBody} property. */ private static final String BODY__XML_ATTR = "body"; + @Override + public String getXmlTagName() { + return CAR__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + if (hasWheel1()) { + out.writeStartElement(WHEEL_1__XML_ATTR); + getWheel1().writeContent(out); + out.writeEndElement(); + } + if (hasWheel2()) { + out.writeStartElement(WHEEL_2__XML_ATTR); + getWheel2().writeContent(out); + out.writeEndElement(); + } + if (hasBody()) { + out.writeStartElement(BODY__XML_ATTR); + getBody().writeContent(out); + out.writeEndElement(); + } + } + /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle_Impl.java index a1e16e63..da4607ed 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle_Impl.java @@ -113,6 +113,24 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getRadius} property. */ private static final String RADIUS__XML_ATTR = "r"; + @Override + public String getXmlTagName() { + return CIRCLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(RADIUS__XML_ATTR, Integer.toString(getRadius())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group_Impl.java index 3897d1c7..308aaa6c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group_Impl.java @@ -154,6 +154,28 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getShapes} property. */ private static final String SHAPES__XML_ATTR = "shapes"; + @Override + public String getXmlTagName() { + return GROUP__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + out.writeStartElement(SHAPES__XML_ATTR); + for (test.nojson.Shape element : getShapes()) { + element.writeTo(out); + } + out.writeEndElement(); + } + /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle_Impl.java index 26ce9756..c98a2458 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle_Impl.java @@ -141,6 +141,25 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getHeight} property. */ private static final String HEIGHT__XML_ATTR = "h"; + @Override + public String getXmlTagName() { + return RECTANGLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WIDTH__XML_ATTR, Integer.toString(getWidth())); + out.writeAttribute(HEIGHT__XML_ATTR, Integer.toString(getHeight())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java index 48a3591f..27b9064b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java @@ -3,7 +3,7 @@ /** * An abstract base class for all shapes */ -public interface Shape extends de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface Shape extends de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** Type codes for the {@link Shape} hierarchy. */ public enum TypeKind { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape_Impl.java index 28bf0187..e39fa7d6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape_Impl.java @@ -151,6 +151,22 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getYCoordinate} property. */ private static final String Y_COORDINATE__XML_ATTR = "y"; + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(X_COORDINATE__XML_ATTR, Integer.toString(getXCoordinate())); + out.writeAttribute(Y_COORDINATE__XML_ATTR, Integer.toString(getYCoordinate())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/AtomicShape_Impl.java index be66766b..e4c468e9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/AtomicShape_Impl.java @@ -27,6 +27,18 @@ public AtomicShape setYCoordinate(int value) { /** XML element name representing a {@link AtomicShape} type. */ public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape_Impl readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car_Impl.java index d9f2d67e..f4a92549 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car_Impl.java @@ -214,6 +214,38 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getBody} property. */ private static final String BODY__XML_ATTR = "body"; + @Override + public String getXmlTagName() { + return CAR__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + if (hasWheel1()) { + out.writeStartElement(WHEEL_1__XML_ATTR); + getWheel1().writeContent(out); + out.writeEndElement(); + } + if (hasWheel2()) { + out.writeStartElement(WHEEL_2__XML_ATTR); + getWheel2().writeContent(out); + out.writeEndElement(); + } + if (hasBody()) { + out.writeStartElement(BODY__XML_ATTR); + getBody().writeContent(out); + out.writeEndElement(); + } + } + /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle_Impl.java index 0bfb222a..65b87311 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle_Impl.java @@ -127,6 +127,24 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getRadius} property. */ private static final String RADIUS__XML_ATTR = "r"; + @Override + public String getXmlTagName() { + return CIRCLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(RADIUS__XML_ATTR, Integer.toString(getRadius())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group_Impl.java index f7b27caa..3fbad377 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group_Impl.java @@ -170,6 +170,28 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getShapes} property. */ private static final String SHAPES__XML_ATTR = "shapes"; + @Override + public String getXmlTagName() { + return GROUP__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + out.writeStartElement(SHAPES__XML_ATTR); + for (test.nolistener.Shape element : getShapes()) { + element.writeTo(out); + } + out.writeEndElement(); + } + /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle_Impl.java index 125b06ff..979caa95 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle_Impl.java @@ -157,6 +157,25 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getHeight} property. */ private static final String HEIGHT__XML_ATTR = "h"; + @Override + public String getXmlTagName() { + return RECTANGLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WIDTH__XML_ATTR, Integer.toString(getWidth())); + out.writeAttribute(HEIGHT__XML_ATTR, Integer.toString(getHeight())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java index ecd016f5..e9809ba4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java @@ -3,7 +3,7 @@ /** * An abstract base class for all shapes */ -public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.data.ReflectiveDataObject { +public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.data.ReflectiveDataObject, de.haumacher.msgbuf.xml.XmlSerializable { /** Type codes for the {@link Shape} hierarchy. */ public enum TypeKind { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape_Impl.java index b9ce1cbf..17054c5f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape_Impl.java @@ -153,6 +153,22 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getYCoordinate} property. */ private static final String Y_COORDINATE__XML_ATTR = "y"; + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(X_COORDINATE__XML_ATTR, Integer.toString(getXCoordinate())); + out.writeAttribute(Y_COORDINATE__XML_ATTR, Integer.toString(getYCoordinate())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape_Impl.java index 2289c530..2c4c0ddc 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape_Impl.java @@ -28,6 +28,18 @@ public AtomicShape setYCoordinate(int value) { /** XML element name representing a {@link AtomicShape} type. */ public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape_Impl readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car_Impl.java index ce3fab45..6b7374ab 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car_Impl.java @@ -192,6 +192,38 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getBody} property. */ private static final String BODY__XML_ATTR = "body"; + @Override + public String getXmlTagName() { + return CAR__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + if (hasWheel1()) { + out.writeStartElement(WHEEL_1__XML_ATTR); + getWheel1().writeContent(out); + out.writeEndElement(); + } + if (hasWheel2()) { + out.writeStartElement(WHEEL_2__XML_ATTR); + getWheel2().writeContent(out); + out.writeEndElement(); + } + if (hasBody()) { + out.writeStartElement(BODY__XML_ATTR); + getBody().writeContent(out); + out.writeEndElement(); + } + } + /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle_Impl.java index ab81d5a6..4fd33bd0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle_Impl.java @@ -105,6 +105,24 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getRadius} property. */ private static final String RADIUS__XML_ATTR = "r"; + @Override + public String getXmlTagName() { + return CIRCLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(RADIUS__XML_ATTR, Integer.toString(getRadius())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group_Impl.java index 5a813553..8863dd7a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group_Impl.java @@ -148,6 +148,28 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getShapes} property. */ private static final String SHAPES__XML_ATTR = "shapes"; + @Override + public String getXmlTagName() { + return GROUP__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + out.writeStartElement(SHAPES__XML_ATTR); + for (test.noreflection.Shape element : getShapes()) { + element.writeTo(out); + } + out.writeEndElement(); + } + /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle_Impl.java index 4f92b541..cd4d0d06 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle_Impl.java @@ -135,6 +135,25 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getHeight} property. */ private static final String HEIGHT__XML_ATTR = "h"; + @Override + public String getXmlTagName() { + return RECTANGLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WIDTH__XML_ATTR, Integer.toString(getWidth())); + out.writeAttribute(HEIGHT__XML_ATTR, Integer.toString(getHeight())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape.java index 7406fd81..82b7de82 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape.java @@ -3,7 +3,7 @@ /** * An abstract base class for all shapes */ -public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject { +public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.xml.XmlSerializable { /** Type codes for the {@link Shape} hierarchy. */ public enum TypeKind { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape_Impl.java index 9430cccb..00873832 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape_Impl.java @@ -133,6 +133,22 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getYCoordinate} property. */ private static final String Y_COORDINATE__XML_ATTR = "y"; + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(X_COORDINATE__XML_ATTR, Integer.toString(getXCoordinate())); + out.writeAttribute(Y_COORDINATE__XML_ATTR, Integer.toString(getYCoordinate())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/AtomicShape_Impl.java index ecbc5c37..102c2900 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/AtomicShape_Impl.java @@ -27,6 +27,18 @@ public AtomicShape setYCoordinate(int value) { /** XML element name representing a {@link AtomicShape} type. */ public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape_Impl readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car_Impl.java index 1101f1e8..beb71128 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car_Impl.java @@ -212,6 +212,38 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getBody} property. */ private static final String BODY__XML_ATTR = "body"; + @Override + public String getXmlTagName() { + return CAR__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + if (hasWheel1()) { + out.writeStartElement(WHEEL_1__XML_ATTR); + getWheel1().writeContent(out); + out.writeEndElement(); + } + if (hasWheel2()) { + out.writeStartElement(WHEEL_2__XML_ATTR); + getWheel2().writeContent(out); + out.writeEndElement(); + } + if (hasBody()) { + out.writeStartElement(BODY__XML_ATTR); + getBody().writeContent(out); + out.writeEndElement(); + } + } + /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle_Impl.java index 1eb33511..251656ea 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle_Impl.java @@ -123,6 +123,24 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getRadius} property. */ private static final String RADIUS__XML_ATTR = "r"; + @Override + public String getXmlTagName() { + return CIRCLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(RADIUS__XML_ATTR, Integer.toString(getRadius())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group_Impl.java index 400d398f..b58209f8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group_Impl.java @@ -175,6 +175,28 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getShapes} property. */ private static final String SHAPES__XML_ATTR = "shapes"; + @Override + public String getXmlTagName() { + return GROUP__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + out.writeStartElement(SHAPES__XML_ATTR); + for (test.notypekind.Shape element : getShapes()) { + element.writeTo(out); + } + out.writeEndElement(); + } + /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle_Impl.java index e0983168..3ef57dad 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle_Impl.java @@ -154,6 +154,25 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getHeight} property. */ private static final String HEIGHT__XML_ATTR = "h"; + @Override + public String getXmlTagName() { + return RECTANGLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WIDTH__XML_ATTR, Integer.toString(getWidth())); + out.writeAttribute(HEIGHT__XML_ATTR, Integer.toString(getHeight())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java index 33649bfb..ec19fd7c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java @@ -3,7 +3,7 @@ /** * An abstract base class for all shapes */ -public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** Visitor interface for the {@link Shape} hierarchy.*/ public interface Visitor extends AtomicShape.Visitor { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape_Impl.java index 281ffd7b..95203059 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape_Impl.java @@ -174,6 +174,22 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getYCoordinate} property. */ private static final String Y_COORDINATE__XML_ATTR = "y"; + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(X_COORDINATE__XML_ATTR, Integer.toString(getXCoordinate())); + out.writeAttribute(Y_COORDINATE__XML_ATTR, Integer.toString(getYCoordinate())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/AtomicShape_Impl.java index 2a555f7e..a4d95294 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/AtomicShape_Impl.java @@ -27,6 +27,18 @@ public AtomicShape setYCoordinate(int value) { /** XML element name representing a {@link AtomicShape} type. */ public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape_Impl readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car_Impl.java index 40d259ae..497825d0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car_Impl.java @@ -217,6 +217,38 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getBody} property. */ private static final String BODY__XML_ATTR = "body"; + @Override + public String getXmlTagName() { + return CAR__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + if (hasWheel1()) { + out.writeStartElement(WHEEL_1__XML_ATTR); + getWheel1().writeContent(out); + out.writeEndElement(); + } + if (hasWheel2()) { + out.writeStartElement(WHEEL_2__XML_ATTR); + getWheel2().writeContent(out); + out.writeEndElement(); + } + if (hasBody()) { + out.writeStartElement(BODY__XML_ATTR); + getBody().writeContent(out); + out.writeEndElement(); + } + } + /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle_Impl.java index a9b34001..447a2adc 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle_Impl.java @@ -128,6 +128,24 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getRadius} property. */ private static final String RADIUS__XML_ATTR = "r"; + @Override + public String getXmlTagName() { + return CIRCLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(RADIUS__XML_ATTR, Integer.toString(getRadius())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group_Impl.java index f30e403a..28ce56be 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group_Impl.java @@ -180,6 +180,28 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getShapes} property. */ private static final String SHAPES__XML_ATTR = "shapes"; + @Override + public String getXmlTagName() { + return GROUP__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + out.writeStartElement(SHAPES__XML_ATTR); + for (test.novisit.Shape element : getShapes()) { + element.writeTo(out); + } + out.writeEndElement(); + } + /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle_Impl.java index 1d732ff5..e1b53215 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle_Impl.java @@ -159,6 +159,25 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getHeight} property. */ private static final String HEIGHT__XML_ATTR = "h"; + @Override + public String getXmlTagName() { + return RECTANGLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WIDTH__XML_ATTR, Integer.toString(getWidth())); + out.writeAttribute(HEIGHT__XML_ATTR, Integer.toString(getHeight())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java index 9a5ef03a..ddecf398 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java @@ -3,7 +3,7 @@ /** * An abstract base class for all shapes */ -public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** Type codes for the {@link Shape} hierarchy. */ public enum TypeKind { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape_Impl.java index 1c908a13..ef04b380 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape_Impl.java @@ -177,6 +177,22 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getYCoordinate} property. */ private static final String Y_COORDINATE__XML_ATTR = "y"; + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(X_COORDINATE__XML_ATTR, Integer.toString(getXCoordinate())); + out.writeAttribute(Y_COORDINATE__XML_ATTR, Integer.toString(getYCoordinate())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/AtomicShape_Impl.java index 4d16976e..912178f4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/AtomicShape_Impl.java @@ -27,6 +27,18 @@ public AtomicShape setYCoordinate(int value) { /** XML element name representing a {@link AtomicShape} type. */ public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape_Impl readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car_Impl.java index 2334b67c..80685b93 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car_Impl.java @@ -217,6 +217,38 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getBody} property. */ private static final String BODY__XML_ATTR = "body"; + @Override + public String getXmlTagName() { + return CAR__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + if (hasWheel1()) { + out.writeStartElement(WHEEL_1__XML_ATTR); + getWheel1().writeContent(out); + out.writeEndElement(); + } + if (hasWheel2()) { + out.writeStartElement(WHEEL_2__XML_ATTR); + getWheel2().writeContent(out); + out.writeEndElement(); + } + if (hasBody()) { + out.writeStartElement(BODY__XML_ATTR); + getBody().writeContent(out); + out.writeEndElement(); + } + } + /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle_Impl.java index 0404b7e2..9a6de57f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle_Impl.java @@ -128,6 +128,24 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getRadius} property. */ private static final String RADIUS__XML_ATTR = "r"; + @Override + public String getXmlTagName() { + return CIRCLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(RADIUS__XML_ATTR, Integer.toString(getRadius())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group_Impl.java index f07e81a9..c548d878 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group_Impl.java @@ -180,6 +180,28 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getShapes} property. */ private static final String SHAPES__XML_ATTR = "shapes"; + @Override + public String getXmlTagName() { + return GROUP__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + out.writeStartElement(SHAPES__XML_ATTR); + for (test.novisitexceptions.Shape element : getShapes()) { + element.writeTo(out); + } + out.writeEndElement(); + } + /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle_Impl.java index f0e1eef9..08a6eeba 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle_Impl.java @@ -159,6 +159,25 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getHeight} property. */ private static final String HEIGHT__XML_ATTR = "h"; + @Override + public String getXmlTagName() { + return RECTANGLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WIDTH__XML_ATTR, Integer.toString(getWidth())); + out.writeAttribute(HEIGHT__XML_ATTR, Integer.toString(getHeight())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java index 8dd6cb2b..72144dde 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java @@ -3,7 +3,7 @@ /** * An abstract base class for all shapes */ -public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** Type codes for the {@link Shape} hierarchy. */ public enum TypeKind { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape_Impl.java index 93faaa38..fa1b3d7d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape_Impl.java @@ -177,6 +177,22 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getYCoordinate} property. */ private static final String Y_COORDINATE__XML_ATTR = "y"; + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(X_COORDINATE__XML_ATTR, Integer.toString(getXCoordinate())); + out.writeAttribute(Y_COORDINATE__XML_ATTR, Integer.toString(getYCoordinate())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java index 06bb14d2..b3d4d7a2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java @@ -1,6 +1,6 @@ package test.nullable.data; -public interface NullableValues extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.data.ReflectiveDataObject { +public interface NullableValues extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.data.ReflectiveDataObject, de.haumacher.msgbuf.xml.XmlSerializable { /** * Creates a {@link NullableValues} instance. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues_Impl.java index f8f469e6..04c43bce 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues_Impl.java @@ -550,6 +550,32 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getOptionalDecision} property. */ private static final String OPTIONAL_DECISION__XML_ATTR = "optional-decision"; + @Override + public String getXmlTagName() { + return NULLABLE_VALUES__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(INT__XML_ATTR, Integer.toString(getInt())); + out.writeAttribute(LONG__XML_ATTR, Long.toString(getLong())); + out.writeAttribute(BOOLEAN__XML_ATTR, Boolean.toString(getBoolean())); + out.writeAttribute(STRING__XML_ATTR, getString()); + out.writeAttribute(INT_LIST__XML_ATTR, getIntList().stream().map(x -> Integer.toString(x)).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(STRING_LIST__XML_ATTR, getStringList().stream().map(x -> x).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(OPTIONAL_DECISION__XML_ATTR, getOptionalDecision().protocolName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link NullableValues} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static NullableValues_Impl readNullableValues_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { NullableValues_Impl result = new NullableValues_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java b/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java index effe3ab3..7408248d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java @@ -1,6 +1,6 @@ package test.oneoffield.data; -public interface SampleMessage extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface SampleMessage extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** * Creates a {@link SampleMessage} instance. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage_Impl.java index 7b9b6d1e..c632b29b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage_Impl.java @@ -86,6 +86,25 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML element name representing a {@link SampleMessage} type. */ public static final String SAMPLE_MESSAGE__XML_ELEMENT = "sample-message"; + @Override + public String getXmlTagName() { + return SAMPLE_MESSAGE__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link SampleMessage} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SampleMessage_Impl readSampleMessage_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SampleMessage_Impl result = new SampleMessage_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/TestOnlyXml.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/TestOnlyXml.java index f9a9fccc..b4f995ab 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/TestOnlyXml.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/TestOnlyXml.java @@ -4,12 +4,15 @@ package test.onlyxml; import java.io.StringReader; +import java.io.StringWriter; import javax.xml.stream.FactoryConfigurationError; import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; +import de.haumacher.msgbuf.xml.XmlSerializable; import junit.framework.TestCase; import test.onlyxml.data.Car; import test.onlyxml.data.Circle; @@ -30,7 +33,21 @@ public void testXmlRead() throws XMLStreamException, FactoryConfigurationError { private void checkShape(String xml) throws XMLStreamException, FactoryConfigurationError { Shape shape = Shape.readShape(reader(xml)); + checkShape(shape); + String serialized = toXml(shape); + Shape reRead = Shape.readShape(reader(serialized)); + checkShape(reRead); + } + + private String toXml(XmlSerializable shape) throws XMLStreamException { + StringWriter buffer = new StringWriter(); + shape.writeTo(XMLOutputFactory.newDefaultFactory().createXMLStreamWriter(buffer)); + String serialized = buffer.toString(); + return serialized; + } + + private void checkShape(Shape shape) { assertNotNull(shape); assertTrue(shape instanceof Group); Group group = (Group) shape; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/AtomicShape_Impl.java index 190d73a5..c5944510 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/AtomicShape_Impl.java @@ -27,6 +27,18 @@ public AtomicShape setYCoordinate(int value) { /** XML element name representing a {@link AtomicShape} type. */ public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape_Impl readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Car_Impl.java index edbab921..22242652 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Car_Impl.java @@ -107,6 +107,38 @@ public Car setYCoordinate(int value) { /** XML attribute or element name of a {@link #getBody} property. */ private static final String BODY__XML_ATTR = "body"; + @Override + public String getXmlTagName() { + return CAR__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + if (hasWheel1()) { + out.writeStartElement(WHEEL_1__XML_ATTR); + getWheel1().writeContent(out); + out.writeEndElement(); + } + if (hasWheel2()) { + out.writeStartElement(WHEEL_2__XML_ATTR); + getWheel2().writeContent(out); + out.writeEndElement(); + } + if (hasBody()) { + out.writeStartElement(BODY__XML_ATTR); + getBody().writeContent(out); + out.writeEndElement(); + } + } + /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Circle_Impl.java index ce9cc4ab..1b5a8c14 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Circle_Impl.java @@ -50,6 +50,24 @@ public Circle setYCoordinate(int value) { /** XML attribute or element name of a {@link #getRadius} property. */ private static final String RADIUS__XML_ATTR = "radius"; + @Override + public String getXmlTagName() { + return CIRCLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(RADIUS__XML_ATTR, Integer.toString(getRadius())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Group_Impl.java index 890648ec..75856d55 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Group_Impl.java @@ -68,6 +68,28 @@ public Group setYCoordinate(int value) { /** XML attribute or element name of a {@link #getShapes} property. */ private static final String SHAPES__XML_ATTR = "shapes"; + @Override + public String getXmlTagName() { + return GROUP__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + out.writeStartElement(SHAPES__XML_ATTR); + for (test.onlyxml.data.Shape element : getShapes()) { + element.writeTo(out); + } + out.writeEndElement(); + } + /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Optional_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Optional_Impl.java index 02c27d67..a49343c3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Optional_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Optional_Impl.java @@ -76,6 +76,29 @@ public Optional setYCoordinate(int value) { /** XML attribute or element name of a {@link #getShape} property. */ private static final String SHAPE__XML_ATTR = "shape"; + @Override + public String getXmlTagName() { + return OPTIONAL__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(HIDDEN__XML_ATTR, Boolean.toString(isHidden())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + if (hasShape()) { + out.writeStartElement(SHAPE__XML_ATTR); + getShape().writeTo(out); + out.writeEndElement(); + } + } + /** Creates a new {@link Optional} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Optional_Impl readOptional_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Optional_Impl result = new Optional_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Rectangle_Impl.java index 76725377..ebb8dde5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Rectangle_Impl.java @@ -71,6 +71,25 @@ public Rectangle setYCoordinate(int value) { /** XML attribute or element name of a {@link #getHeight} property. */ private static final String HEIGHT__XML_ATTR = "h"; + @Override + public String getXmlTagName() { + return RECTANGLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WIDTH__XML_ATTR, Integer.toString(getWidth())); + out.writeAttribute(HEIGHT__XML_ATTR, Integer.toString(getHeight())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Shape.java index 42d65936..89cfd044 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Shape.java @@ -3,7 +3,7 @@ /** * An abstract base class for all shapes */ -public interface Shape { +public interface Shape extends de.haumacher.msgbuf.xml.XmlSerializable { /** * X coordinate of the origin of the coordinate system of this {@link Shape}. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Shape_Impl.java index e564ee0e..324034fc 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Shape_Impl.java @@ -57,6 +57,22 @@ protected final void internalSetYCoordinate(int value) { /** XML attribute or element name of a {@link #getYCoordinate} property. */ private static final String Y_COORDINATE__XML_ATTR = "y"; + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(X_COORDINATE__XML_ATTR, Integer.toString(getXCoordinate())); + out.writeAttribute(Y_COORDINATE__XML_ATTR, Integer.toString(getYCoordinate())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java index c632b8fa..efc059aa 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java @@ -1,6 +1,6 @@ package test.options.data; -public interface MyMessage1 extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface MyMessage1 extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { public enum EnumAllowingAlias implements de.haumacher.msgbuf.data.ProtocolEnum { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1_Impl.java index 0bca40c2..f5102941 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1_Impl.java @@ -86,6 +86,25 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML element name representing a {@link MyMessage1} type. */ public static final String MY_MESSAGE_1__XML_ELEMENT = "my-message-1"; + @Override + public String getXmlTagName() { + return MY_MESSAGE_1__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link MyMessage1} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static MyMessage1_Impl readMyMessage1_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { MyMessage1_Impl result = new MyMessage1_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java index 2c25adf6..23a49715 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java @@ -1,6 +1,6 @@ package test.options.data; -public interface MyMessage2 extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface MyMessage2 extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { public enum EnumNotAllowingAlias implements de.haumacher.msgbuf.data.ProtocolEnum { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2_Impl.java index f59c385a..e8058b33 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2_Impl.java @@ -86,6 +86,25 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML element name representing a {@link MyMessage2} type. */ public static final String MY_MESSAGE_2__XML_ELEMENT = "my-message-2"; + @Override + public String getXmlTagName() { + return MY_MESSAGE_2__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link MyMessage2} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static MyMessage2_Impl readMyMessage2_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { MyMessage2_Impl result = new MyMessage2_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java index 1812f212..4e564293 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java @@ -1,6 +1,6 @@ package test.references.data; -public interface A extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface A extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** * Creates a {@link A} instance. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A_Impl.java index e9d5913a..5c51079b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A_Impl.java @@ -630,6 +630,66 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getInOthers} property. */ private static final String IN_OTHERS__XML_ATTR = "in-others"; + @Override + public String getXmlTagName() { + return A__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasContents()) { + out.writeStartElement(CONTENTS__XML_ATTR); + getContents().writeContent(out); + out.writeEndElement(); + } + out.writeStartElement(CHILDREN__XML_ATTR); + for (test.references.data.A element : getChildren()) { + element.writeTo(out); + } + out.writeEndElement(); + out.writeStartElement(BS__XML_ATTR); + for (test.references.data.B element : getBs()) { + element.writeTo(out); + } + out.writeEndElement(); + if (hasB()) { + out.writeStartElement(B__XML_ATTR); + getB().writeContent(out); + out.writeEndElement(); + } + if (hasOther()) { + out.writeStartElement(OTHER__XML_ATTR); + getOther().writeContent(out); + out.writeEndElement(); + } + out.writeStartElement(OTHERS__XML_ATTR); + for (test.references.data.A element : getOthers()) { + element.writeTo(out); + } + out.writeEndElement(); + out.writeStartElement(IN_OTHER__XML_ATTR); + for (test.references.data.A element : getInOther()) { + element.writeTo(out); + } + out.writeEndElement(); + out.writeStartElement(IN_OTHERS__XML_ATTR); + for (test.references.data.A element : getInOthers()) { + element.writeTo(out); + } + out.writeEndElement(); + } + /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static A_Impl readA_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { A_Impl result = new A_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java index 44704947..1b269698 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java @@ -1,6 +1,6 @@ package test.references.data; -public interface B extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface B extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** * Creates a {@link B} instance. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B_Impl.java index 374557cc..3340d3b1 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B_Impl.java @@ -245,6 +245,36 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getInB} property. */ private static final String IN_B__XML_ATTR = "in-b"; + @Override + public String getXmlTagName() { + return B__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeStartElement(IN_BS__XML_ATTR); + for (test.references.data.A element : getInBs()) { + element.writeTo(out); + } + out.writeEndElement(); + out.writeStartElement(IN_B__XML_ATTR); + for (test.references.data.A element : getInB()) { + element.writeTo(out); + } + out.writeEndElement(); + } + /** Creates a new {@link B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static B_Impl readB_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { B_Impl result = new B_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java index 899e4747..d089e66f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java @@ -1,6 +1,6 @@ package test.types.data; -public interface SearchRequest extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface SearchRequest extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** * Creates a {@link SearchRequest} instance. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest_Impl.java index e12ba7cd..7d300582 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest_Impl.java @@ -211,6 +211,28 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getResultPerPage} property. */ private static final String RESULT_PER_PAGE__XML_ATTR = "result-per-page"; + @Override + public String getXmlTagName() { + return SEARCH_REQUEST__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(QUERY__XML_ATTR, getQuery()); + out.writeAttribute(PAGE_NUMBER__XML_ATTR, Integer.toString(getPageNumber())); + out.writeAttribute(RESULT_PER_PAGE__XML_ATTR, Integer.toString(getResultPerPage())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link SearchRequest} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SearchRequest_Impl readSearchRequest_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SearchRequest_Impl result = new SearchRequest_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage_Impl.java index 05422144..d0c6e44f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage_Impl.java @@ -113,6 +113,24 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getAnnotatedField} property. */ private static final String ANNOTATED_FIELD__XML_ATTR = "f1"; + @Override + public String getXmlTagName() { + return ANNOTATED_MESSAGE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(ANNOTATED_FIELD__XML_ATTR, getAnnotatedField()); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link AnnotatedMessage} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AnnotatedMessage_Impl readAnnotated_message_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { AnnotatedMessage_Impl result = new AnnotatedMessage_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/BaseMsg.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/BaseMsg.java index 7ce26697..017851b8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/BaseMsg.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/BaseMsg.java @@ -1,6 +1,6 @@ package test.underscorename; -public interface BaseMsg extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public interface BaseMsg extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** Type codes for the {@link BaseMsg} hierarchy. */ public enum TypeKind { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/BaseMsg_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/BaseMsg_Impl.java index 136ed527..fefb438e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/BaseMsg_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/BaseMsg_Impl.java @@ -80,6 +80,20 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML element name representing a {@link BaseMsg} type. */ public static final String BASE_MSG__XML_ELEMENT = "base-msg"; + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + /** Creates a new {@link BaseMsg} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static BaseMsg_Impl readBase_msg_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName_Impl.java index 5fa15dba..a43aa28d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName_Impl.java @@ -113,6 +113,24 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getMyField} property. */ private static final String MY_FIELD__XML_ATTR = "my-field"; + @Override + public String getXmlTagName() { + return SOME_NAME__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(MY_FIELD__XML_ATTR, getMyField()); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + } + /** Creates a new {@link SomeName} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SomeName_Impl readSome_name_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SomeName_Impl result = new SomeName_Impl(); diff --git a/de.haumacher.msgbuf/.classpath b/de.haumacher.msgbuf/.classpath index e2008929..88d9f461 100644 --- a/de.haumacher.msgbuf/.classpath +++ b/de.haumacher.msgbuf/.classpath @@ -3,6 +3,7 @@ + diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/xml/XmlSerializable.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/xml/XmlSerializable.java new file mode 100644 index 00000000..eac6b876 --- /dev/null +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/xml/XmlSerializable.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 Bernhard Haumacher et al. All Rights Reserved. + */ +package de.haumacher.msgbuf.xml; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import de.haumacher.msgbuf.data.DataObject; + +/** + * Optional interface implemented by {@link DataObject}s that support XML serialization. + */ +public interface XmlSerializable { + + /** + * Serializes this object to XML. + * + * @param out + * The {@link XMLStreamWriter} to write this object to. + * @throws XMLStreamException + * If writing fails. + */ + default void writeTo(XMLStreamWriter out) throws XMLStreamException { + out.writeStartElement(getXmlTagName()); + writeContent(out); + out.writeEndElement(); + } + + /** + * Writes the contents of this object (attributes and sub-elements) to XML. + * + * @param out + * The {@link XMLStreamWriter} to write this object to. + * @throws XMLStreamException + * If writing fails. + */ + void writeContent(XMLStreamWriter out) throws XMLStreamException; + + /** + * The tag name used to {@link #writeTo(XMLStreamWriter) write this object} as top-level element in an XML document. + */ + String getXmlTagName(); + +} diff --git a/de.haumacher.msgbuf/src/main/java/module-info.java b/de.haumacher.msgbuf/src/main/java/module-info.java index baa27070..4be94f56 100644 --- a/de.haumacher.msgbuf/src/main/java/module-info.java +++ b/de.haumacher.msgbuf/src/main/java/module-info.java @@ -5,23 +5,17 @@ * MsgBuf API module. */ module de.haumacher.msgbuf { - exports de.haumacher.msgbuf.data; - - exports de.haumacher.msgbuf.server.io; - - exports de.haumacher.msgbuf.util; - - exports de.haumacher.msgbuf.coder; - exports de.haumacher.msgbuf.binary; - + exports de.haumacher.msgbuf.coder; + exports de.haumacher.msgbuf.data; exports de.haumacher.msgbuf.graph; - - exports de.haumacher.msgbuf.observer; - - exports de.haumacher.msgbuf.io; - exports de.haumacher.msgbuf.graph.cmd; - + exports de.haumacher.msgbuf.io; exports de.haumacher.msgbuf.json; + exports de.haumacher.msgbuf.observer; + exports de.haumacher.msgbuf.server.io; + exports de.haumacher.msgbuf.util; + exports de.haumacher.msgbuf.xml; + + requires transitive java.xml; } \ No newline at end of file From 03d62aebd5e41fb28f068004dda8ebcc44793020 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 6 Nov 2022 18:49:52 +0100 Subject: [PATCH 014/207] Fixed order of artifact and version tags. --- de.haumacher.msgbuf.generator/pom.xml | 2 +- de.haumacher.msgbuf/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index fd55bdf6..fc397d79 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -3,8 +3,8 @@ de.haumacher.msgbuf - 1.1.0-SNAPSHOT msgbuf-parent + 1.1.0-SNAPSHOT msgbuf-generator diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 73a8a3fb..597acf8a 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -3,8 +3,8 @@ de.haumacher.msgbuf - 1.1.0-SNAPSHOT msgbuf-parent + 1.1.0-SNAPSHOT msgbuf-api From 124b0dcf2d5ba73d624d5d29632badd2b006445a Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 6 Nov 2022 18:50:52 +0100 Subject: [PATCH 015/207] [maven-release-plugin] prepare release msgbuf-api-1.1.0 --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index fc397d79..933bb95e 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.0-SNAPSHOT + 1.1.0 msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.0-SNAPSHOT + 1.1.0 diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 597acf8a..197e7728 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.0-SNAPSHOT + 1.1.0 msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index b56f4257..8a7cd138 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.0-SNAPSHOT + 1.1.0 msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.0-SNAPSHOT + 1.1.0 diff --git a/pom.xml b/pom.xml index e8d5ad1b..31579496 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.0-SNAPSHOT + 1.1.0 pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - HEAD + msgbuf-api-1.1.0 From addc20b1f36458951b8e4e9fa3fd4a015b02ba03 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 6 Nov 2022 18:51:30 +0100 Subject: [PATCH 016/207] [maven-release-plugin] prepare for next development iteration --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 933bb95e..eae09095 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.0 + 1.1.1-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.0 + 1.1.1-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 197e7728..c3905d3c 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.0 + 1.1.1-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 8a7cd138..5f3a00d0 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.0 + 1.1.1-SNAPSHOT msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.0 + 1.1.1-SNAPSHOT diff --git a/pom.xml b/pom.xml index 31579496..a8330f09 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.0 + 1.1.1-SNAPSHOT pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - msgbuf-api-1.1.0 + HEAD From 600ddd6402fab5c1acf8a0b0fc9cbd283550a296 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 6 Nov 2022 19:05:03 +0100 Subject: [PATCH 017/207] Added howto release. --- HOWTO-RELEASE.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 HOWTO-RELEASE.md diff --git a/HOWTO-RELEASE.md b/HOWTO-RELEASE.md new file mode 100644 index 00000000..e3ee79b3 --- /dev/null +++ b/HOWTO-RELEASE.md @@ -0,0 +1,20 @@ +# How to release to Maven Central + +## Set stable version number + +``` +mvn release:clean release:prepare +``` + +## Create staging repository + +``` +mvn release:perform +``` + +## Release to Maven Central + +``` +cd target/checkout/ +mvn nexus-staging:release +``` From 09cceb53c7c74e76f9b7aa3de95c0ff753fd924d Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 6 Nov 2022 19:05:29 +0100 Subject: [PATCH 018/207] Updated version and added description of new maven plugin. --- README.md | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 492482d3..2a9ab51c 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,41 @@ In contrast to `protobuf`, `msgbuf` supports: `msgbuf` currently serializes messages in JSON format. For GWT-compatibility it uses a modified `JsonReader`/`JsonWriter` from the [gson library](https://github.com/google/gson) that was abstracted from the unsupported `Reader`/`Writer` Java API. +## Setup with Maven + +### Add the MsgBuf runtime libary dependency to your project + +``` + + de.haumacher.msgbuf + msgbuf-api + 1.1.0 + +``` + +### Add the MsgBuf generator to your pom.xml + +To the `build/plugins` section add: + +``` + + de.haumacher.msgbuf + msgbuf-generator-maven-plugin + 1.1.0 + + + + generate-protocols + + generate + + + + +``` + +Now you are ready to create `*.proto` files in your source folder and build them with `mvn compile`. + ## Usage The `msgbuf` definition language is an extension of the [proto format](https://developers.google.com/protocol-buffers/docs/proto3) from `protobuf`. A defined message can `extend` another message type, or it can be marked `abstract`. @@ -65,16 +100,6 @@ There is an Eclipse plugin providing a project builder that automatically genera * Select your project in the `Package Explorer`. * In the context menu, select `Configure > Enable MsgBuf Builder`. -### Add project dependency to the MsgBuf runtime libary - -``` - - de.haumacher.msgbuf - msgbuf-api - 1.0.3 - -``` - ### Test the installtion * Create a `MyMessage.proto` file in one of your packages in the source folder. From 9427d9db838930c3121027df7c7846bfeec63694 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 6 Nov 2022 19:08:55 +0100 Subject: [PATCH 019/207] Added missing package hint to example. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 2a9ab51c..ebaad52e 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,11 @@ Now you are ready to create `*.proto` files in your source folder and build them The `msgbuf` definition language is an extension of the [proto format](https://developers.google.com/protocol-buffers/docs/proto3) from `protobuf`. A defined message can `extend` another message type, or it can be marked `abstract`. Assume, you want to describe shapes in a graphics application, you could define the data types as follows. You may start with an `abstract` shape class, defining coordinates of the origin of its coordinate system: + +`shape.proto`: ```protobuf +package my.app.model; + syntax = "msgbuf"; abstract message Shape { From 4ce03a640d196e89c7ca1e840235a4989ec336c6 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 6 Nov 2022 19:09:35 +0100 Subject: [PATCH 020/207] Added missing path of proto example file. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ebaad52e..1e7e21ff 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ The `msgbuf` definition language is an extension of the [proto format](https://d Assume, you want to describe shapes in a graphics application, you could define the data types as follows. You may start with an `abstract` shape class, defining coordinates of the origin of its coordinate system: -`shape.proto`: +Add `src/main/java/my/app/model/shape.proto` with the following contents: ```protobuf package my.app.model; From 3965b41b7354cd3536a73c42b49169c763ee6652 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 6 Nov 2022 19:41:17 +0100 Subject: [PATCH 021/207] Updated Eclipse version information. --- .../.settings/org.eclipse.jdt.core.prefs | 10 ++++++---- de.haumacher.msgbuf.eclipse/META-INF/MANIFEST.MF | 6 +++--- de.haumacher.msgbuf.feature/feature.xml | 2 +- de.haumacher.msgbuf.generator/META-INF/MANIFEST.MF | 6 +++--- de.haumacher.msgbuf/META-INF/MANIFEST.MF | 4 ++-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/de.haumacher.msgbuf.eclipse/.settings/org.eclipse.jdt.core.prefs b/de.haumacher.msgbuf.eclipse/.settings/org.eclipse.jdt.core.prefs index ec1937b3..f2525a8b 100644 --- a/de.haumacher.msgbuf.eclipse/.settings/org.eclipse.jdt.core.prefs +++ b/de.haumacher.msgbuf.eclipse/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,14 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.compliance=11 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=1.8 +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=11 diff --git a/de.haumacher.msgbuf.eclipse/META-INF/MANIFEST.MF b/de.haumacher.msgbuf.eclipse/META-INF/MANIFEST.MF index 74c1ce96..0f72a004 100644 --- a/de.haumacher.msgbuf.eclipse/META-INF/MANIFEST.MF +++ b/de.haumacher.msgbuf.eclipse/META-INF/MANIFEST.MF @@ -2,10 +2,10 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: MsgBuf Project Nature Bundle-SymbolicName: de.haumacher.msgbuf.eclipse;singleton:=true -Bundle-Version: 1.0.3.qualifier +Bundle-Version: 1.1.0.qualifier Require-Bundle: org.eclipse.core.resources;bundle-version="3.13.700", org.eclipse.core.runtime, org.eclipse.ui, - de.haumacher.msgbuf.generator;bundle-version="1.0.2" -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 + de.haumacher.msgbuf.generator;bundle-version="1.1.0" +Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-Vendor: haumacher.de diff --git a/de.haumacher.msgbuf.feature/feature.xml b/de.haumacher.msgbuf.feature/feature.xml index 6ac49396..be104c3b 100644 --- a/de.haumacher.msgbuf.feature/feature.xml +++ b/de.haumacher.msgbuf.feature/feature.xml @@ -2,7 +2,7 @@ diff --git a/de.haumacher.msgbuf.generator/META-INF/MANIFEST.MF b/de.haumacher.msgbuf.generator/META-INF/MANIFEST.MF index 19ca3122..9e60e807 100644 --- a/de.haumacher.msgbuf.generator/META-INF/MANIFEST.MF +++ b/de.haumacher.msgbuf.generator/META-INF/MANIFEST.MF @@ -2,10 +2,10 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: MsgBuf Code Generator Bundle-SymbolicName: de.haumacher.msgbuf.generator -Bundle-Version: 1.0.2.qualifier +Bundle-Version: 1.1.0.qualifier Export-Package: de.haumacher.msgbuf.generator, de.haumacher.msgbuf.generator.ast, de.haumacher.msgbuf.generator.parser -Require-Bundle: de.haumacher.msgbuf;bundle-version="1.0.0" -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: de.haumacher.msgbuf;bundle-version="1.1.0" +Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-Vendor: haumacher.de diff --git a/de.haumacher.msgbuf/META-INF/MANIFEST.MF b/de.haumacher.msgbuf/META-INF/MANIFEST.MF index db95f770..1750dd95 100644 --- a/de.haumacher.msgbuf/META-INF/MANIFEST.MF +++ b/de.haumacher.msgbuf/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: MsgBuf API Bundle-SymbolicName: de.haumacher.msgbuf -Bundle-Version: 1.0.2.qualifier +Bundle-Version: 1.1.0.qualifier Export-Package: de.haumacher.msgbuf, de.haumacher.msgbuf.binary, de.haumacher.msgbuf.coder, @@ -14,5 +14,5 @@ Export-Package: de.haumacher.msgbuf, de.haumacher.msgbuf.observer, de.haumacher.msgbuf.server.io, de.haumacher.msgbuf.util -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-Vendor: haumacher.de From 09b6f27671220019924a3b28e676e9abb5817fe8 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 1 Jan 2023 17:47:10 +0100 Subject: [PATCH 022/207] Bugfix: Field constants are required for JSON serialization. Constants must be generated even if no reflective access methods are generated. --- .../msgbuf/generator/MessageGenerator.java | 6 +- .../java/test/noreflection/AtomicShape.java | 50 +++--- .../src/test/java/test/noreflection/Car.java | 146 +++++++++++++----- .../test/java/test/noreflection/Circle.java | 82 +++++++--- .../test/java/test/noreflection/Group.java | 109 +++++++++---- .../java/test/noreflection/Rectangle.java | 105 +++++++++---- .../test/java/test/noreflection/Shape.java | 115 +++++++------- .../java/test/noreflection/noreflection.proto | 4 + 8 files changed, 422 insertions(+), 195 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index d5343db2..f4ad4c0f 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -409,14 +409,16 @@ private void generateConstants() { } if (_json || _reflection) { - if (_reflection == (_interface || _noInterfaces)) { + if (_interface || _noInterfaces) { + String modifier = _reflection ? (_noInterfaces ? "public " : "") : "private "; + for (Field field : getFields()) { if (!_reflection && field.isTransient()) { continue; } nl(); line("/** @see #" + getterCall(field) + " */"); - line((_reflection ? (_noInterfaces ? "public " : "") : "private ") + "static final String " + constant(field) + " = " + getFieldNameString(field) + ";"); + line(modifier + "static final String " + constant(field) + " = " + getFieldNameString(field) + ";"); } } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape.java index 3102c091..b027f9be 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape.java @@ -3,7 +3,7 @@ /** * A {@link Shape} that has no sub-shapes. */ -public interface AtomicShape extends Shape { +public abstract class AtomicShape extends Shape { /** Visitor interface for the {@link AtomicShape} hierarchy.*/ public interface Visitor { @@ -16,17 +16,30 @@ public interface Visitor { } + /** + * Creates a {@link AtomicShape} instance. + */ + protected AtomicShape() { + super(); + } + @Override - AtomicShape setXCoordinate(int value); + public AtomicShape setXCoordinate(int value) { + internalSetXCoordinate(value); + return this; + } @Override - AtomicShape setYCoordinate(int value); + public AtomicShape setYCoordinate(int value) { + internalSetYCoordinate(value); + return this; + } /** The type identifier for this concrete subtype. */ - String jsonType(); + public abstract String jsonType(); /** Reads a new instance from the given reader. */ - static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { AtomicShape result; in.beginArray(); String type = in.nextString(); @@ -39,29 +52,12 @@ static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throw return result; } - /** Reads a new instance from the given reader. */ - static AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - in.beginObject(); - int typeField = in.nextName(); - assert typeField == 0; - int type = in.nextInt(); - AtomicShape result; - switch (type) { - case Circle.CIRCLE__TYPE_ID: result = test.noreflection.Circle_Impl.readCircle_Content(in); break; - case Rectangle.RECTANGLE__TYPE_ID: result = test.noreflection.Rectangle_Impl.readRectangle_Content(in); break; - default: result = null; while (in.hasNext()) {in.skipValue(); } - } - in.endObject(); - return result; - } - - /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static AtomicShape readAtomicShape(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - in.nextTag(); - return test.noreflection.AtomicShape_Impl.readAtomicShape_XmlContent(in); - } - /** Accepts the given visitor. */ public abstract R visit(Visitor v, A arg) throws E; + @Override + public final R visit(Shape.Visitor v, A arg) throws E { + return visit((AtomicShape.Visitor) v, arg); + } + } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car.java index b2026f7b..1e3e2560 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car.java @@ -3,101 +3,177 @@ /** * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. */ -public interface Car extends Shape { +public class Car extends Shape { /** * Creates a {@link Car} instance. */ - static Car create() { - return new test.noreflection.Car_Impl(); + public static Car create() { + return new test.noreflection.Car(); } /** Identifier for the {@link Car} type in JSON format. */ - static final String CAR__TYPE = "Car"; + public static final String CAR__TYPE = "Car"; - /** Identifier for the {@link Car} type in binary format. */ - static final int CAR__TYPE_ID = 4; + /** @see #getWheel1() */ + private static final String WHEEL_1__PROP = "wheel1"; - /** Identifier for the property {@link #getWheel1()} in binary format. */ - static final int WHEEL_1__ID = 3; + /** @see #getWheel2() */ + private static final String WHEEL_2__PROP = "wheel2"; - /** Identifier for the property {@link #getWheel2()} in binary format. */ - static final int WHEEL_2__ID = 4; + /** @see #getBody() */ + private static final String BODY__PROP = "body"; - /** Identifier for the property {@link #getBody()} in binary format. */ - static final int BODY__ID = 5; + private Circle _wheel1 = null; + + private Circle _wheel2 = null; + + private Rectangle _body = null; + + /** + * Creates a {@link Car} instance. + * + * @see Car#create() + */ + protected Car() { + super(); + } /** * The front wheel. */ - Circle getWheel1(); + public final Circle getWheel1() { + return _wheel1; + } /** * @see #getWheel1() */ - Car setWheel1(Circle value); + public Car setWheel1(Circle value) { + internalSetWheel1(value); + return this; + } + + /** Internal setter for {@link #getWheel1()} without chain call utility. */ + protected final void internalSetWheel1(Circle value) { + _wheel1 = value; + } /** * Checks, whether {@link #getWheel1()} has a value. */ - boolean hasWheel1(); + public final boolean hasWheel1() { + return _wheel1 != null; + } /** * The back wheel. */ - Circle getWheel2(); + public final Circle getWheel2() { + return _wheel2; + } /** * @see #getWheel2() */ - Car setWheel2(Circle value); + public Car setWheel2(Circle value) { + internalSetWheel2(value); + return this; + } + + /** Internal setter for {@link #getWheel2()} without chain call utility. */ + protected final void internalSetWheel2(Circle value) { + _wheel2 = value; + } /** * Checks, whether {@link #getWheel2()} has a value. */ - boolean hasWheel2(); + public final boolean hasWheel2() { + return _wheel2 != null; + } /** * The car body. */ - Rectangle getBody(); + public final Rectangle getBody() { + return _body; + } /** * @see #getBody() */ - Car setBody(Rectangle value); + public Car setBody(Rectangle value) { + internalSetBody(value); + return this; + } + + /** Internal setter for {@link #getBody()} without chain call utility. */ + protected final void internalSetBody(Rectangle value) { + _body = value; + } /** * Checks, whether {@link #getBody()} has a value. */ - boolean hasBody(); + public final boolean hasBody() { + return _body != null; + } @Override - Car setXCoordinate(int value); + public Car setXCoordinate(int value) { + internalSetXCoordinate(value); + return this; + } @Override - Car setYCoordinate(int value); + public Car setYCoordinate(int value) { + internalSetYCoordinate(value); + return this; + } + @Override + public String jsonType() { + return CAR__TYPE; + } /** Reads a new instance from the given reader. */ - static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.noreflection.Car_Impl result = new test.noreflection.Car_Impl(); + public static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.noreflection.Car result = new test.noreflection.Car(); result.readContent(in); return result; } - /** Reads a new instance from the given reader. */ - static Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - in.beginObject(); - Car result = test.noreflection.Car_Impl.readCar_Content(in); - in.endObject(); - return result; + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + if (hasWheel1()) { + out.name(WHEEL_1__PROP); + getWheel1().writeContent(out); + } + if (hasWheel2()) { + out.name(WHEEL_2__PROP); + getWheel2().writeContent(out); + } + if (hasBody()) { + out.name(BODY__PROP); + getBody().writeContent(out); + } } - /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static Car readCar(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - in.nextTag(); - return test.noreflection.Car_Impl.readCar_XmlContent(in); + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case WHEEL_1__PROP: setWheel1(test.noreflection.Circle.readCircle(in)); break; + case WHEEL_2__PROP: setWheel2(test.noreflection.Circle.readCircle(in)); break; + case BODY__PROP: setBody(test.noreflection.Rectangle.readRectangle(in)); break; + default: super.readField(in, field); + } + } + + @Override + public R visit(Shape.Visitor v, A arg) throws E { + return v.visit(this, arg); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle.java index 30ffa5f8..328b3f9f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle.java @@ -3,60 +3,94 @@ /** * A circle {@link Shape}. */ -public interface Circle extends AtomicShape { +public class Circle extends AtomicShape { /** * Creates a {@link Circle} instance. */ - static Circle create() { - return new test.noreflection.Circle_Impl(); + public static Circle create() { + return new test.noreflection.Circle(); } /** Identifier for the {@link Circle} type in JSON format. */ - static final String CIRCLE__TYPE = "Circle"; + public static final String CIRCLE__TYPE = "Circle"; - /** Identifier for the {@link Circle} type in binary format. */ - static final int CIRCLE__TYPE_ID = 1; + /** @see #getRadius() */ + private static final String RADIUS__PROP = "r"; - /** Identifier for the property {@link #getRadius()} in binary format. */ - static final int RADIUS__ID = 3; + private int _radius = 0; + + /** + * Creates a {@link Circle} instance. + * + * @see Circle#create() + */ + protected Circle() { + super(); + } /** * The radius of this {@link Circle} around its coordinate origin at ({@link #getXCoordinate()}, {@link #getYCoordinate()}). */ - int getRadius(); + public final int getRadius() { + return _radius; + } /** * @see #getRadius() */ - Circle setRadius(int value); + public Circle setRadius(int value) { + internalSetRadius(value); + return this; + } + + /** Internal setter for {@link #getRadius()} without chain call utility. */ + protected final void internalSetRadius(int value) { + _radius = value; + } @Override - Circle setXCoordinate(int value); + public Circle setXCoordinate(int value) { + internalSetXCoordinate(value); + return this; + } @Override - Circle setYCoordinate(int value); + public Circle setYCoordinate(int value) { + internalSetYCoordinate(value); + return this; + } + @Override + public String jsonType() { + return CIRCLE__TYPE; + } /** Reads a new instance from the given reader. */ - static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.noreflection.Circle_Impl result = new test.noreflection.Circle_Impl(); + public static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.noreflection.Circle result = new test.noreflection.Circle(); result.readContent(in); return result; } - /** Reads a new instance from the given reader. */ - static Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - in.beginObject(); - Circle result = test.noreflection.Circle_Impl.readCircle_Content(in); - in.endObject(); - return result; + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(RADIUS__PROP); + out.value(getRadius()); } - /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static Circle readCircle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - in.nextTag(); - return test.noreflection.Circle_Impl.readCircle_XmlContent(in); + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case RADIUS__PROP: setRadius(in.nextInt()); break; + default: super.readField(in, field); + } + } + + @Override + public R visit(AtomicShape.Visitor v, A arg) throws E { + return v.visit(this, arg); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group.java index bdb85846..f53a3ce8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group.java @@ -3,23 +3,31 @@ /** * A group of shapes. */ -public interface Group extends Shape { +public class Group extends Shape { /** * Creates a {@link Group} instance. */ - static Group create() { - return new test.noreflection.Group_Impl(); + public static Group create() { + return new test.noreflection.Group(); } /** Identifier for the {@link Group} type in JSON format. */ - static final String GROUP__TYPE = "Group"; + public static final String GROUP__TYPE = "Group"; - /** Identifier for the {@link Group} type in binary format. */ - static final int GROUP__TYPE_ID = 3; + /** @see #getShapes() */ + private static final String SHAPES__PROP = "shapes"; - /** Identifier for the property {@link #getShapes()} in binary format. */ - static final int SHAPES__ID = 3; + private final java.util.List _shapes = new java.util.ArrayList<>(); + + /** + * Creates a {@link Group} instance. + * + * @see Group#create() + */ + protected Group() { + super(); + } /** * All {@link Shape}s in this {@link Group}. @@ -28,49 +36,98 @@ static Group create() { * The origins of these {@link Shape}s get a coordinate offset of ({@link #getXCoordinate()}, {@link #getYCoordinate()}). *

*/ - java.util.List getShapes(); + public final java.util.List getShapes() { + return _shapes; + } /** * @see #getShapes() */ - Group setShapes(java.util.List value); + public Group setShapes(java.util.List value) { + internalSetShapes(value); + return this; + } + + /** Internal setter for {@link #getShapes()} without chain call utility. */ + protected final void internalSetShapes(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); + _shapes.clear(); + _shapes.addAll(value); + } /** * Adds a value to the {@link #getShapes()} list. */ - Group addShape(Shape value); + public Group addShape(Shape value) { + internalAddShape(value); + return this; + } + + /** Implementation of {@link #addShape(Shape)} without chain call utility. */ + protected final void internalAddShape(Shape value) { + _shapes.add(value); + } /** * Removes a value from the {@link #getShapes()} list. */ - void removeShape(Shape value); + public final void removeShape(Shape value) { + _shapes.remove(value); + } @Override - Group setXCoordinate(int value); + public Group setXCoordinate(int value) { + internalSetXCoordinate(value); + return this; + } @Override - Group setYCoordinate(int value); + public Group setYCoordinate(int value) { + internalSetYCoordinate(value); + return this; + } + @Override + public String jsonType() { + return GROUP__TYPE; + } /** Reads a new instance from the given reader. */ - static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.noreflection.Group_Impl result = new test.noreflection.Group_Impl(); + public static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.noreflection.Group result = new test.noreflection.Group(); result.readContent(in); return result; } - /** Reads a new instance from the given reader. */ - static Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - in.beginObject(); - Group result = test.noreflection.Group_Impl.readGroup_Content(in); - in.endObject(); - return result; + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(SHAPES__PROP); + out.beginArray(); + for (Shape x : getShapes()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case SHAPES__PROP: { + in.beginArray(); + while (in.hasNext()) { + addShape(test.noreflection.Shape.readShape(in)); + } + in.endArray(); + } + break; + default: super.readField(in, field); + } } - /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static Group readGroup(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - in.nextTag(); - return test.noreflection.Group_Impl.readGroup_XmlContent(in); + @Override + public R visit(Shape.Visitor v, A arg) throws E { + return v.visit(this, arg); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle.java index 764ae0d2..cfe4e7ac 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle.java @@ -3,26 +3,36 @@ /** * A rectangle. */ -public interface Rectangle extends AtomicShape { +public class Rectangle extends AtomicShape { /** * Creates a {@link Rectangle} instance. */ - static Rectangle create() { - return new test.noreflection.Rectangle_Impl(); + public static Rectangle create() { + return new test.noreflection.Rectangle(); } /** Identifier for the {@link Rectangle} type in JSON format. */ - static final String RECTANGLE__TYPE = "Rectangle"; + public static final String RECTANGLE__TYPE = "Rectangle"; - /** Identifier for the {@link Rectangle} type in binary format. */ - static final int RECTANGLE__TYPE_ID = 2; + /** @see #getWidth() */ + private static final String WIDTH__PROP = "w"; - /** Identifier for the property {@link #getWidth()} in binary format. */ - static final int WIDTH__ID = 3; + /** @see #getHeight() */ + private static final String HEIGHT__PROP = "h"; - /** Identifier for the property {@link #getHeight()} in binary format. */ - static final int HEIGHT__ID = 4; + private int _width = 0; + + private int _height = 0; + + /** + * Creates a {@link Rectangle} instance. + * + * @see Rectangle#create() + */ + protected Rectangle() { + super(); + } /** * The width of this {@link Rectangle}. @@ -33,51 +43,90 @@ static Rectangle create() { * * @see #getHeight() */ - int getWidth(); + public final int getWidth() { + return _width; + } /** * @see #getWidth() */ - Rectangle setWidth(int value); + public Rectangle setWidth(int value) { + internalSetWidth(value); + return this; + } + + /** Internal setter for {@link #getWidth()} without chain call utility. */ + protected final void internalSetWidth(int value) { + _width = value; + } /** * The width of this {@link Rectangle}. * * @see #getWidth() */ - int getHeight(); + public final int getHeight() { + return _height; + } /** * @see #getHeight() */ - Rectangle setHeight(int value); + public Rectangle setHeight(int value) { + internalSetHeight(value); + return this; + } + + /** Internal setter for {@link #getHeight()} without chain call utility. */ + protected final void internalSetHeight(int value) { + _height = value; + } @Override - Rectangle setXCoordinate(int value); + public Rectangle setXCoordinate(int value) { + internalSetXCoordinate(value); + return this; + } @Override - Rectangle setYCoordinate(int value); + public Rectangle setYCoordinate(int value) { + internalSetYCoordinate(value); + return this; + } + @Override + public String jsonType() { + return RECTANGLE__TYPE; + } /** Reads a new instance from the given reader. */ - static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.noreflection.Rectangle_Impl result = new test.noreflection.Rectangle_Impl(); + public static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.noreflection.Rectangle result = new test.noreflection.Rectangle(); result.readContent(in); return result; } - /** Reads a new instance from the given reader. */ - static Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - in.beginObject(); - Rectangle result = test.noreflection.Rectangle_Impl.readRectangle_Content(in); - in.endObject(); - return result; + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(WIDTH__PROP); + out.value(getWidth()); + out.name(HEIGHT__PROP); + out.value(getHeight()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case WIDTH__PROP: setWidth(in.nextInt()); break; + case HEIGHT__PROP: setHeight(in.nextInt()); break; + default: super.readField(in, field); + } } - /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static Rectangle readRectangle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - in.nextTag(); - return test.noreflection.Rectangle_Impl.readRectangle_XmlContent(in); + @Override + public R visit(AtomicShape.Visitor v, A arg) throws E { + return v.visit(this, arg); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape.java index 82b7de82..fcc18198 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape.java @@ -3,25 +3,7 @@ /** * An abstract base class for all shapes */ -public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.xml.XmlSerializable { - - /** Type codes for the {@link Shape} hierarchy. */ - public enum TypeKind { - - /** Type literal for {@link Circle}. */ - CIRCLE, - - /** Type literal for {@link Rectangle}. */ - RECTANGLE, - - /** Type literal for {@link Group}. */ - GROUP, - - /** Type literal for {@link Car}. */ - CAR, - ; - - } +public abstract class Shape extends de.haumacher.msgbuf.data.AbstractDataObject { /** Visitor interface for the {@link Shape} hierarchy.*/ public interface Visitor extends AtomicShape.Visitor { @@ -34,40 +16,68 @@ public interface Visitor extends AtomicShape.Visitor Date: Sun, 1 Jan 2023 17:48:01 +0100 Subject: [PATCH 023/207] Removed outdated generated test classes. --- .../test/noreflection/AtomicShape_Impl.java | 84 ------ .../test/java/test/noreflection/Car_Impl.java | 269 ------------------ .../java/test/noreflection/Circle_Impl.java | 164 ----------- .../java/test/noreflection/Group_Impl.java | 218 -------------- .../test/noreflection/Rectangle_Impl.java | 203 ------------- .../java/test/noreflection/Shape_Impl.java | 242 ---------------- 6 files changed, 1180 deletions(-) delete mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape_Impl.java delete mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car_Impl.java delete mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle_Impl.java delete mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group_Impl.java delete mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle_Impl.java delete mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape_Impl.java diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape_Impl.java deleted file mode 100644 index 2c4c0ddc..00000000 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape_Impl.java +++ /dev/null @@ -1,84 +0,0 @@ -package test.noreflection; - -/** - * A {@link Shape} that has no sub-shapes. - */ -abstract class AtomicShape_Impl extends Shape_Impl implements AtomicShape { - - /** - * Creates a {@link AtomicShape_Impl} instance. - */ - protected AtomicShape_Impl() { - super(); - } - - @Override - public AtomicShape setXCoordinate(int value) { - internalSetXCoordinate(value); - return this; - } - - @Override - public AtomicShape setYCoordinate(int value) { - internalSetYCoordinate(value); - return this; - } - - - /** XML element name representing a {@link AtomicShape} type. */ - public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; - - /** Serializes all fields that are written as XML attributes. */ - @Override - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeAttributes(out); - } - - /** Serializes all fields that are written as XML elements. */ - @Override - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeElements(out); - } - - /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static AtomicShape_Impl readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - switch (in.getLocalName()) { - case Circle_Impl.CIRCLE__XML_ELEMENT: { - return test.noreflection.Circle_Impl.readCircle_XmlContent(in); - } - - case Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - return test.noreflection.Rectangle_Impl.readRectangle_XmlContent(in); - } - - default: { - internalSkipUntilMatchingEndElement(in); - return null; - } - } - } - - @Override - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - default: { - super.readFieldXmlAttribute(name, value); - } - } - } - - @Override - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - default: { - super.readFieldXmlElement(in, localName); - } - } - } - - @Override - public final R visit(Shape.Visitor v, A arg) throws E { - return visit((AtomicShape.Visitor) v, arg); - } - -} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car_Impl.java deleted file mode 100644 index 6b7374ab..00000000 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car_Impl.java +++ /dev/null @@ -1,269 +0,0 @@ -package test.noreflection; - -/** - * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. - */ -class Car_Impl extends Shape_Impl implements Car { - - /** @see #getWheel1() */ - private static final String WHEEL_1__PROP = "wheel1"; - - /** @see #getWheel2() */ - private static final String WHEEL_2__PROP = "wheel2"; - - /** @see #getBody() */ - private static final String BODY__PROP = "body"; - - private Circle _wheel1 = null; - - private Circle _wheel2 = null; - - private Rectangle _body = null; - - /** - * Creates a {@link Car_Impl} instance. - * - * @see Car#create() - */ - protected Car_Impl() { - super(); - } - - @Override - public TypeKind kind() { - return TypeKind.CAR; - } - - @Override - public final Circle getWheel1() { - return _wheel1; - } - - @Override - public Car setWheel1(Circle value) { - internalSetWheel1(value); - return this; - } - - /** Internal setter for {@link #getWheel1()} without chain call utility. */ - protected final void internalSetWheel1(Circle value) { - _wheel1 = value; - } - - @Override - public final boolean hasWheel1() { - return _wheel1 != null; - } - - @Override - public final Circle getWheel2() { - return _wheel2; - } - - @Override - public Car setWheel2(Circle value) { - internalSetWheel2(value); - return this; - } - - /** Internal setter for {@link #getWheel2()} without chain call utility. */ - protected final void internalSetWheel2(Circle value) { - _wheel2 = value; - } - - @Override - public final boolean hasWheel2() { - return _wheel2 != null; - } - - @Override - public final Rectangle getBody() { - return _body; - } - - @Override - public Car setBody(Rectangle value) { - internalSetBody(value); - return this; - } - - /** Internal setter for {@link #getBody()} without chain call utility. */ - protected final void internalSetBody(Rectangle value) { - _body = value; - } - - @Override - public final boolean hasBody() { - return _body != null; - } - - @Override - public Car setXCoordinate(int value) { - internalSetXCoordinate(value); - return this; - } - - @Override - public Car setYCoordinate(int value) { - internalSetYCoordinate(value); - return this; - } - - @Override - public String jsonType() { - return CAR__TYPE; - } - - @Override - protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { - super.writeFields(out); - if (hasWheel1()) { - out.name(WHEEL_1__PROP); - getWheel1().writeContent(out); - } - if (hasWheel2()) { - out.name(WHEEL_2__PROP); - getWheel2().writeContent(out); - } - if (hasBody()) { - out.name(BODY__PROP); - getBody().writeContent(out); - } - } - - @Override - protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { - switch (field) { - case WHEEL_1__PROP: setWheel1(test.noreflection.Circle.readCircle(in)); break; - case WHEEL_2__PROP: setWheel2(test.noreflection.Circle.readCircle(in)); break; - case BODY__PROP: setBody(test.noreflection.Rectangle.readRectangle(in)); break; - default: super.readField(in, field); - } - } - - @Override - public int typeId() { - return CAR__TYPE_ID; - } - - @Override - protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { - super.writeFields(out); - if (hasWheel1()) { - out.name(WHEEL_1__ID); - getWheel1().writeTo(out); - } - if (hasWheel2()) { - out.name(WHEEL_2__ID); - getWheel2().writeTo(out); - } - if (hasBody()) { - out.name(BODY__ID); - getBody().writeTo(out); - } - } - - /** Helper for creating an object of type {@link Car} from a polymorphic composition. */ - public static Car readCar_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.noreflection.Car_Impl result = new Car_Impl(); - result.readContent(in); - return result; - } - - @Override - protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { - switch (field) { - case WHEEL_1__ID: setWheel1(test.noreflection.Circle.readCircle(in)); break; - case WHEEL_2__ID: setWheel2(test.noreflection.Circle.readCircle(in)); break; - case BODY__ID: setBody(test.noreflection.Rectangle.readRectangle(in)); break; - default: super.readField(in, field); - } - } - - /** XML element name representing a {@link Car} type. */ - public static final String CAR__XML_ELEMENT = "car"; - - /** XML attribute or element name of a {@link #getWheel1} property. */ - private static final String WHEEL_1__XML_ATTR = "wheel-1"; - - /** XML attribute or element name of a {@link #getWheel2} property. */ - private static final String WHEEL_2__XML_ATTR = "wheel-2"; - - /** XML attribute or element name of a {@link #getBody} property. */ - private static final String BODY__XML_ATTR = "body"; - - @Override - public String getXmlTagName() { - return CAR__XML_ELEMENT; - } - - /** Serializes all fields that are written as XML attributes. */ - @Override - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeAttributes(out); - } - - /** Serializes all fields that are written as XML elements. */ - @Override - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeElements(out); - if (hasWheel1()) { - out.writeStartElement(WHEEL_1__XML_ATTR); - getWheel1().writeContent(out); - out.writeEndElement(); - } - if (hasWheel2()) { - out.writeStartElement(WHEEL_2__XML_ATTR); - getWheel2().writeContent(out); - out.writeEndElement(); - } - if (hasBody()) { - out.writeStartElement(BODY__XML_ATTR); - getBody().writeContent(out); - out.writeEndElement(); - } - } - - /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - Car_Impl result = new Car_Impl(); - result.readContentXml(in); - return result; - } - - @Override - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - default: { - super.readFieldXmlAttribute(name, value); - } - } - } - - @Override - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - case WHEEL_1__XML_ATTR: { - setWheel1(test.noreflection.Circle_Impl.readCircle_XmlContent(in)); - break; - } - case WHEEL_2__XML_ATTR: { - setWheel2(test.noreflection.Circle_Impl.readCircle_XmlContent(in)); - break; - } - case BODY__XML_ATTR: { - setBody(test.noreflection.Rectangle_Impl.readRectangle_XmlContent(in)); - break; - } - default: { - super.readFieldXmlElement(in, localName); - } - } - } - - @Override - public R visit(Shape.Visitor v, A arg) throws E { - return v.visit(this, arg); - } - -} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle_Impl.java deleted file mode 100644 index 4fd33bd0..00000000 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle_Impl.java +++ /dev/null @@ -1,164 +0,0 @@ -package test.noreflection; - -/** - * A circle {@link Shape}. - */ -class Circle_Impl extends AtomicShape_Impl implements Circle { - - /** @see #getRadius() */ - private static final String RADIUS__PROP = "r"; - - private int _radius = 0; - - /** - * Creates a {@link Circle_Impl} instance. - * - * @see Circle#create() - */ - protected Circle_Impl() { - super(); - } - - @Override - public TypeKind kind() { - return TypeKind.CIRCLE; - } - - @Override - public final int getRadius() { - return _radius; - } - - @Override - public Circle setRadius(int value) { - internalSetRadius(value); - return this; - } - - /** Internal setter for {@link #getRadius()} without chain call utility. */ - protected final void internalSetRadius(int value) { - _radius = value; - } - - @Override - public Circle setXCoordinate(int value) { - internalSetXCoordinate(value); - return this; - } - - @Override - public Circle setYCoordinate(int value) { - internalSetYCoordinate(value); - return this; - } - - @Override - public String jsonType() { - return CIRCLE__TYPE; - } - - @Override - protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { - super.writeFields(out); - out.name(RADIUS__PROP); - out.value(getRadius()); - } - - @Override - protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { - switch (field) { - case RADIUS__PROP: setRadius(in.nextInt()); break; - default: super.readField(in, field); - } - } - - @Override - public int typeId() { - return CIRCLE__TYPE_ID; - } - - @Override - protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { - super.writeFields(out); - out.name(RADIUS__ID); - out.value(getRadius()); - } - - /** Helper for creating an object of type {@link Circle} from a polymorphic composition. */ - public static Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.noreflection.Circle_Impl result = new Circle_Impl(); - result.readContent(in); - return result; - } - - @Override - protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { - switch (field) { - case RADIUS__ID: setRadius(in.nextInt()); break; - default: super.readField(in, field); - } - } - - /** XML element name representing a {@link Circle} type. */ - public static final String CIRCLE__XML_ELEMENT = "circle"; - - /** XML attribute or element name of a {@link #getRadius} property. */ - private static final String RADIUS__XML_ATTR = "r"; - - @Override - public String getXmlTagName() { - return CIRCLE__XML_ELEMENT; - } - - /** Serializes all fields that are written as XML attributes. */ - @Override - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeAttributes(out); - out.writeAttribute(RADIUS__XML_ATTR, Integer.toString(getRadius())); - } - - /** Serializes all fields that are written as XML elements. */ - @Override - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeElements(out); - } - - /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - Circle_Impl result = new Circle_Impl(); - result.readContentXml(in); - return result; - } - - @Override - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - case RADIUS__XML_ATTR: { - setRadius(Integer.parseInt(value)); - break; - } - default: { - super.readFieldXmlAttribute(name, value); - } - } - } - - @Override - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - case RADIUS__XML_ATTR: { - setRadius(Integer.parseInt(in.getElementText())); - break; - } - default: { - super.readFieldXmlElement(in, localName); - } - } - } - - @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { - return v.visit(this, arg); - } - -} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group_Impl.java deleted file mode 100644 index 8863dd7a..00000000 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group_Impl.java +++ /dev/null @@ -1,218 +0,0 @@ -package test.noreflection; - -/** - * A group of shapes. - */ -class Group_Impl extends Shape_Impl implements Group { - - /** @see #getShapes() */ - private static final String SHAPES__PROP = "shapes"; - - private final java.util.List _shapes = new java.util.ArrayList<>(); - - /** - * Creates a {@link Group_Impl} instance. - * - * @see Group#create() - */ - protected Group_Impl() { - super(); - } - - @Override - public TypeKind kind() { - return TypeKind.GROUP; - } - - @Override - public final java.util.List getShapes() { - return _shapes; - } - - @Override - public Group setShapes(java.util.List value) { - internalSetShapes(value); - return this; - } - - /** Internal setter for {@link #getShapes()} without chain call utility. */ - protected final void internalSetShapes(java.util.List value) { - if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); - _shapes.clear(); - _shapes.addAll(value); - } - - @Override - public Group addShape(Shape value) { - internalAddShape(value); - return this; - } - - /** Implementation of {@link #addShape(Shape)} without chain call utility. */ - protected final void internalAddShape(Shape value) { - _shapes.add(value); - } - - @Override - public final void removeShape(Shape value) { - _shapes.remove(value); - } - - @Override - public Group setXCoordinate(int value) { - internalSetXCoordinate(value); - return this; - } - - @Override - public Group setYCoordinate(int value) { - internalSetYCoordinate(value); - return this; - } - - @Override - public String jsonType() { - return GROUP__TYPE; - } - - @Override - protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { - super.writeFields(out); - out.name(SHAPES__PROP); - out.beginArray(); - for (Shape x : getShapes()) { - x.writeTo(out); - } - out.endArray(); - } - - @Override - protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { - switch (field) { - case SHAPES__PROP: { - in.beginArray(); - while (in.hasNext()) { - addShape(test.noreflection.Shape.readShape(in)); - } - in.endArray(); - } - break; - default: super.readField(in, field); - } - } - - @Override - public int typeId() { - return GROUP__TYPE_ID; - } - - @Override - protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { - super.writeFields(out); - out.name(SHAPES__ID); - { - java.util.List values = getShapes(); - out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); - for (Shape x : values) { - x.writeTo(out); - } - out.endArray(); - } - } - - /** Helper for creating an object of type {@link Group} from a polymorphic composition. */ - public static Group readGroup_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.noreflection.Group_Impl result = new Group_Impl(); - result.readContent(in); - return result; - } - - @Override - protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { - switch (field) { - case SHAPES__ID: { - in.beginArray(); - while (in.hasNext()) { - addShape(test.noreflection.Shape.readShape(in)); - } - in.endArray(); - } - break; - default: super.readField(in, field); - } - } - - /** XML element name representing a {@link Group} type. */ - public static final String GROUP__XML_ELEMENT = "group"; - - /** XML attribute or element name of a {@link #getShapes} property. */ - private static final String SHAPES__XML_ATTR = "shapes"; - - @Override - public String getXmlTagName() { - return GROUP__XML_ELEMENT; - } - - /** Serializes all fields that are written as XML attributes. */ - @Override - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeAttributes(out); - } - - /** Serializes all fields that are written as XML elements. */ - @Override - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeElements(out); - out.writeStartElement(SHAPES__XML_ATTR); - for (test.noreflection.Shape element : getShapes()) { - element.writeTo(out); - } - out.writeEndElement(); - } - - /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - Group_Impl result = new Group_Impl(); - result.readContentXml(in); - return result; - } - - @Override - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - default: { - super.readFieldXmlAttribute(name, value); - } - } - } - - @Override - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - case SHAPES__XML_ATTR: { - internalReadShapesListXml(in); - break; - } - default: { - super.readFieldXmlElement(in, localName); - } - } - } - - private void internalReadShapesListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - while (true) { - int event = in.nextTag(); - if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { - break; - } - - addShape(test.noreflection.Shape_Impl.readShape_XmlContent(in)); - } - } - - @Override - public R visit(Shape.Visitor v, A arg) throws E { - return v.visit(this, arg); - } - -} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle_Impl.java deleted file mode 100644 index cd4d0d06..00000000 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle_Impl.java +++ /dev/null @@ -1,203 +0,0 @@ -package test.noreflection; - -/** - * A rectangle. - */ -class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { - - /** @see #getWidth() */ - private static final String WIDTH__PROP = "w"; - - /** @see #getHeight() */ - private static final String HEIGHT__PROP = "h"; - - private int _width = 0; - - private int _height = 0; - - /** - * Creates a {@link Rectangle_Impl} instance. - * - * @see Rectangle#create() - */ - protected Rectangle_Impl() { - super(); - } - - @Override - public TypeKind kind() { - return TypeKind.RECTANGLE; - } - - @Override - public final int getWidth() { - return _width; - } - - @Override - public Rectangle setWidth(int value) { - internalSetWidth(value); - return this; - } - - /** Internal setter for {@link #getWidth()} without chain call utility. */ - protected final void internalSetWidth(int value) { - _width = value; - } - - @Override - public final int getHeight() { - return _height; - } - - @Override - public Rectangle setHeight(int value) { - internalSetHeight(value); - return this; - } - - /** Internal setter for {@link #getHeight()} without chain call utility. */ - protected final void internalSetHeight(int value) { - _height = value; - } - - @Override - public Rectangle setXCoordinate(int value) { - internalSetXCoordinate(value); - return this; - } - - @Override - public Rectangle setYCoordinate(int value) { - internalSetYCoordinate(value); - return this; - } - - @Override - public String jsonType() { - return RECTANGLE__TYPE; - } - - @Override - protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { - super.writeFields(out); - out.name(WIDTH__PROP); - out.value(getWidth()); - out.name(HEIGHT__PROP); - out.value(getHeight()); - } - - @Override - protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { - switch (field) { - case WIDTH__PROP: setWidth(in.nextInt()); break; - case HEIGHT__PROP: setHeight(in.nextInt()); break; - default: super.readField(in, field); - } - } - - @Override - public int typeId() { - return RECTANGLE__TYPE_ID; - } - - @Override - protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { - super.writeFields(out); - out.name(WIDTH__ID); - out.value(getWidth()); - out.name(HEIGHT__ID); - out.value(getHeight()); - } - - /** Helper for creating an object of type {@link Rectangle} from a polymorphic composition. */ - public static Rectangle readRectangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.noreflection.Rectangle_Impl result = new Rectangle_Impl(); - result.readContent(in); - return result; - } - - @Override - protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { - switch (field) { - case WIDTH__ID: setWidth(in.nextInt()); break; - case HEIGHT__ID: setHeight(in.nextInt()); break; - default: super.readField(in, field); - } - } - - /** XML element name representing a {@link Rectangle} type. */ - public static final String RECTANGLE__XML_ELEMENT = "rectangle"; - - /** XML attribute or element name of a {@link #getWidth} property. */ - private static final String WIDTH__XML_ATTR = "w"; - - /** XML attribute or element name of a {@link #getHeight} property. */ - private static final String HEIGHT__XML_ATTR = "h"; - - @Override - public String getXmlTagName() { - return RECTANGLE__XML_ELEMENT; - } - - /** Serializes all fields that are written as XML attributes. */ - @Override - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeAttributes(out); - out.writeAttribute(WIDTH__XML_ATTR, Integer.toString(getWidth())); - out.writeAttribute(HEIGHT__XML_ATTR, Integer.toString(getHeight())); - } - - /** Serializes all fields that are written as XML elements. */ - @Override - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeElements(out); - } - - /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - Rectangle_Impl result = new Rectangle_Impl(); - result.readContentXml(in); - return result; - } - - @Override - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - case WIDTH__XML_ATTR: { - setWidth(Integer.parseInt(value)); - break; - } - case HEIGHT__XML_ATTR: { - setHeight(Integer.parseInt(value)); - break; - } - default: { - super.readFieldXmlAttribute(name, value); - } - } - } - - @Override - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - case WIDTH__XML_ATTR: { - setWidth(Integer.parseInt(in.getElementText())); - break; - } - case HEIGHT__XML_ATTR: { - setHeight(Integer.parseInt(in.getElementText())); - break; - } - default: { - super.readFieldXmlElement(in, localName); - } - } - } - - @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { - return v.visit(this, arg); - } - -} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape_Impl.java deleted file mode 100644 index 00873832..00000000 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape_Impl.java +++ /dev/null @@ -1,242 +0,0 @@ -package test.noreflection; - -/** - * An abstract base class for all shapes - */ -abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements Shape { - - /** @see #getXCoordinate() */ - private static final String X_COORDINATE__PROP = "x"; - - /** @see #getYCoordinate() */ - private static final String Y_COORDINATE__PROP = "y"; - - private int _xCoordinate = 0; - - private int _yCoordinate = 0; - - /** - * Creates a {@link Shape_Impl} instance. - */ - protected Shape_Impl() { - super(); - } - - /** The type code of this instance. */ - public abstract TypeKind kind(); - - @Override - public final int getXCoordinate() { - return _xCoordinate; - } - - @Override - public Shape setXCoordinate(int value) { - internalSetXCoordinate(value); - return this; - } - - /** Internal setter for {@link #getXCoordinate()} without chain call utility. */ - protected final void internalSetXCoordinate(int value) { - _xCoordinate = value; - } - - @Override - public final int getYCoordinate() { - return _yCoordinate; - } - - @Override - public Shape setYCoordinate(int value) { - internalSetYCoordinate(value); - return this; - } - - /** Internal setter for {@link #getYCoordinate()} without chain call utility. */ - protected final void internalSetYCoordinate(int value) { - _yCoordinate = value; - } - - - @Override - public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { - out.beginArray(); - out.value(jsonType()); - writeContent(out); - out.endArray(); - } - - @Override - protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { - super.writeFields(out); - out.name(X_COORDINATE__PROP); - out.value(getXCoordinate()); - out.name(Y_COORDINATE__PROP); - out.value(getYCoordinate()); - } - - @Override - protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { - switch (field) { - case X_COORDINATE__PROP: setXCoordinate(in.nextInt()); break; - case Y_COORDINATE__PROP: setYCoordinate(in.nextInt()); break; - default: super.readField(in, field); - } - } - - @Override - public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { - out.beginObject(); - out.name(0); - out.value(typeId()); - writeFields(out); - out.endObject(); - } - - /** - * Serializes all fields of this instance to the given binary output. - * - * @param out - * The binary output to write to. - * @throws java.io.IOException If writing fails. - */ - protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { - out.name(X_COORDINATE__ID); - out.value(getXCoordinate()); - out.name(Y_COORDINATE__ID); - out.value(getYCoordinate()); - } - - /** Helper for reading all fields of this instance. */ - protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - while (in.hasNext()) { - int field = in.nextName(); - readField(in, field); - } - } - - /** Consumes the value for the field with the given ID and assigns its value. */ - protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { - switch (field) { - case X_COORDINATE__ID: setXCoordinate(in.nextInt()); break; - case Y_COORDINATE__ID: setYCoordinate(in.nextInt()); break; - default: in.skipValue(); - } - } - - /** XML element name representing a {@link Shape} type. */ - public static final String SHAPE__XML_ELEMENT = "shape"; - - /** XML attribute or element name of a {@link #getXCoordinate} property. */ - private static final String X_COORDINATE__XML_ATTR = "x"; - - /** XML attribute or element name of a {@link #getYCoordinate} property. */ - private static final String Y_COORDINATE__XML_ATTR = "y"; - - @Override - public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - writeAttributes(out); - writeElements(out); - } - - /** Serializes all fields that are written as XML attributes. */ - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - out.writeAttribute(X_COORDINATE__XML_ATTR, Integer.toString(getXCoordinate())); - out.writeAttribute(Y_COORDINATE__XML_ATTR, Integer.toString(getYCoordinate())); - } - - /** Serializes all fields that are written as XML elements. */ - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - } - - /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - switch (in.getLocalName()) { - case Circle_Impl.CIRCLE__XML_ELEMENT: { - return test.noreflection.Circle_Impl.readCircle_XmlContent(in); - } - - case Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - return test.noreflection.Rectangle_Impl.readRectangle_XmlContent(in); - } - - case Group_Impl.GROUP__XML_ELEMENT: { - return test.noreflection.Group_Impl.readGroup_XmlContent(in); - } - - case Car_Impl.CAR__XML_ELEMENT: { - return test.noreflection.Car_Impl.readCar_XmlContent(in); - } - - default: { - internalSkipUntilMatchingEndElement(in); - return null; - } - } - } - - /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { - String name = in.getAttributeLocalName(n); - String value = in.getAttributeValue(n); - - readFieldXmlAttribute(name, value); - } - while (true) { - int event = in.nextTag(); - if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { - break; - } - assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; - - String localName = in.getLocalName(); - readFieldXmlElement(in, localName); - } - } - - /** Parses the given attribute value and assigns it to the field with the given name. */ - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - case X_COORDINATE__XML_ATTR: { - setXCoordinate(Integer.parseInt(value)); - break; - } - case Y_COORDINATE__XML_ATTR: { - setYCoordinate(Integer.parseInt(value)); - break; - } - default: { - // Skip unknown attribute. - } - } - } - - /** Reads the element under the cursor and assigns its contents to the field with the given name. */ - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - case X_COORDINATE__XML_ATTR: { - setXCoordinate(Integer.parseInt(in.getElementText())); - break; - } - case Y_COORDINATE__XML_ATTR: { - setYCoordinate(Integer.parseInt(in.getElementText())); - break; - } - default: { - internalSkipUntilMatchingEndElement(in); - } - } - } - - protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - int level = 0; - while (true) { - switch (in.next()) { - case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; - case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } - } - } - } - -} From db3432b2269c8db9195e574c1a44a6157ab2605d Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 1 Jan 2023 17:49:54 +0100 Subject: [PATCH 024/207] [maven-release-plugin] prepare release msgbuf-api-1.1.1 --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index eae09095..9abfed0d 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.1-SNAPSHOT + 1.1.1 msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.1-SNAPSHOT + 1.1.1 diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index c3905d3c..880d65ff 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.1-SNAPSHOT + 1.1.1 msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 5f3a00d0..52bf00be 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.1-SNAPSHOT + 1.1.1 msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.1-SNAPSHOT + 1.1.1 diff --git a/pom.xml b/pom.xml index a8330f09..b8db042a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.1-SNAPSHOT + 1.1.1 pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - HEAD + msgbuf-api-1.1.1 From ab941a6e581a397df4da013a509f28829e961acb Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 1 Jan 2023 17:50:34 +0100 Subject: [PATCH 025/207] [maven-release-plugin] prepare for next development iteration --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 9abfed0d..11214beb 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.1 + 1.1.2-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.1 + 1.1.2-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 880d65ff..269cce31 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.1 + 1.1.2-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 52bf00be..00584c22 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.1 + 1.1.2-SNAPSHOT msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.1 + 1.1.2-SNAPSHOT diff --git a/pom.xml b/pom.xml index b8db042a..2df26845 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.1 + 1.1.2-SNAPSHOT pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - msgbuf-api-1.1.1 + HEAD From 530879634fab29da14d503d446eb2ea3e74c263b Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 1 Jan 2023 17:54:24 +0100 Subject: [PATCH 026/207] Updated version on website. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1e7e21ff..c094b3e6 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ In contrast to `protobuf`, `msgbuf` supports: de.haumacher.msgbuf msgbuf-api - 1.1.0 + 1.1.1 ``` @@ -32,7 +32,7 @@ To the `build/plugins` section add: de.haumacher.msgbuf msgbuf-generator-maven-plugin - 1.1.0 + 1.1.1 From 164efd256b9f3fc6277a136d1b6257f22f88468a Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 1 Jan 2023 19:58:04 +0100 Subject: [PATCH 027/207] Fixed @Override annotation on jsonType() Concrete type without generalization declares method but does not override a super-type method, if no reflection access is generated. --- .../msgbuf/generator/MessageGenerator.java | 24 +- .../test/comments/data/SearchRequest.java | 1 - .../test/enumeration/data/SearchRequest.java | 1 - .../src/test/java/test/graph/data/Car.java | 1 - .../src/test/java/test/graph/data/Circle.java | 1 - .../src/test/java/test/graph/data/Group.java | 1 - .../test/java/test/graph/data/Rectangle.java | 1 - .../test/java/test/graph/data/SimpleType.java | 65 ++++ .../java/test/graph/data/SimpleType_Impl.java | 221 ++++++++++++ .../java/test/graph/data/sharedgraph.proto | 11 + .../test/java/test/hierarchy/data/Car.java | 1 - .../test/java/test/hierarchy/data/Circle.java | 1 - .../test/java/test/hierarchy/data/Group.java | 1 - .../java/test/hierarchy/data/Optional.java | 1 - .../java/test/hierarchy/data/Rectangle.java | 1 - .../java/test/hierarchy/data/SimpleType.java | 77 ++++ .../test/hierarchy/data/SimpleType_Impl.java | 278 +++++++++++++++ .../java/test/hierarchy/data/hierarchy.proto | 11 + .../src/test/java/test/innertypeclash/A.java | 2 - .../src/test/java/test/innertypeclash/B.java | 2 - .../test/java/test/lowercasemessage/A.java | 2 - .../java/test/maptype/data/MyMessage.java | 1 - .../test/java/test/maptype/data/Project.java | 1 - .../java/test/nested/data/SearchResponse.java | 2 - .../java/test/nointerfaces/SimpleType.java | 329 ++++++++++++++++++ .../java/test/nointerfaces/nointerfaces.proto | 11 + .../src/test/java/test/nojson/Car.java | 1 - .../src/test/java/test/nojson/Circle.java | 1 - .../src/test/java/test/nojson/Group.java | 1 - .../src/test/java/test/nojson/Rectangle.java | 1 - .../src/test/java/test/nojson/SimpleType.java | 70 ++++ .../java/test/nojson/SimpleType_Impl.java | 255 ++++++++++++++ .../src/test/java/test/nojson/nojson.proto | 11 + .../src/test/java/test/nolistener/Car.java | 1 - .../src/test/java/test/nolistener/Circle.java | 1 - .../src/test/java/test/nolistener/Group.java | 1 - .../test/java/test/nolistener/Rectangle.java | 1 - .../test/java/test/nolistener/SimpleType.java | 71 ++++ .../java/test/nolistener/SimpleType_Impl.java | 254 ++++++++++++++ .../java/test/nolistener/nolistener.proto | 11 + .../java/test/noreflection/SimpleType.java | 111 ++++++ .../java/test/noreflection/noreflection.proto | 11 + .../test/java/test/nothing/SimpleType.java | 35 ++ .../java/test/nothing/SimpleType_Impl.java | 53 +++ .../src/test/java/test/nothing/nothing.proto | 11 + .../src/test/java/test/notypekind/Car.java | 1 - .../src/test/java/test/notypekind/Circle.java | 1 - .../src/test/java/test/notypekind/Group.java | 1 - .../test/java/test/notypekind/Rectangle.java | 1 - .../test/java/test/notypekind/SimpleType.java | 77 ++++ .../java/test/notypekind/SimpleType_Impl.java | 278 +++++++++++++++ .../test/java/test/notypekind/hierarchy.proto | 11 + .../src/test/java/test/novisit/Car.java | 1 - .../src/test/java/test/novisit/Circle.java | 1 - .../src/test/java/test/novisit/Group.java | 1 - .../src/test/java/test/novisit/Rectangle.java | 1 - .../test/java/test/novisit/SimpleType.java | 77 ++++ .../java/test/novisit/SimpleType_Impl.java | 278 +++++++++++++++ .../test/java/test/novisit/hierarchy.proto | 11 + .../test/java/test/novisitexceptions/Car.java | 1 - .../java/test/novisitexceptions/Circle.java | 1 - .../java/test/novisitexceptions/Group.java | 1 - .../test/novisitexceptions/Rectangle.java | 1 - .../test/novisitexceptions/SimpleType.java | 77 ++++ .../novisitexceptions/SimpleType_Impl.java | 278 +++++++++++++++ .../test/novisitexceptions/hierarchy.proto | 11 + .../test/nullable/data/NullableValues.java | 1 - .../test/oneoffield/data/SampleMessage.java | 1 - .../java/test/onlyxml/data/SimpleType.java | 41 +++ .../test/onlyxml/data/SimpleType_Impl.java | 154 ++++++++ .../src/test/java/test/onlyxml/onlyxml.proto | 11 + .../java/test/options/data/MyMessage1.java | 1 - .../java/test/options/data/MyMessage2.java | 1 - .../src/test/java/test/references/data/A.java | 1 - .../src/test/java/test/references/data/B.java | 1 - .../java/test/types/data/SearchRequest.java | 1 - .../test/underscorename/AnnotatedMessage.java | 1 - .../java/test/underscorename/SomeName.java | 1 - 78 files changed, 3214 insertions(+), 60 deletions(-) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/graph/data/SimpleType.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/graph/data/SimpleType_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/SimpleType.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/SimpleType_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nojson/SimpleType.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nojson/SimpleType_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nolistener/SimpleType.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nolistener/SimpleType_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/noreflection/SimpleType.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nothing/SimpleType.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nothing/SimpleType_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/notypekind/SimpleType.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/notypekind/SimpleType_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/SimpleType.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/SimpleType_Impl.java diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index f4ad4c0f..525608b0 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -964,22 +964,26 @@ private void generateReflection() { } private void reflectionType() { - if (!(_reflection && _def.isAbstract())) { - nl(); - if (_def.isAbstract()) { + if (_def.isAbstract()) { + if (!_reflection) { + // Otherwise, the interface is inherited from ReflectiveDataObject. if (_interface || _noInterfaces) { + nl(); jsonTypeDoc(); line((_noInterfaces ? "public abstract " : "") + "String jsonType();"); } - } else { - if (!_interface) { + } + } else { + if (!_interface) { + nl(); + if (_reflection || _def.getExtendedDef() != null) { line("@Override"); - line("public String jsonType() {"); - { - line("return " + jsonTypeConstant(_def) + ";"); - } - line("}"); } + line("public String jsonType() {"); + { + line("return " + jsonTypeConstant(_def) + ";"); + } + line("}"); } } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java index a2df6217..c06d6c3f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java @@ -78,7 +78,6 @@ static SearchRequest create() { @Override public SearchRequest unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static SearchRequest readSearchRequest(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.comments.data.SearchRequest_Impl result = new test.comments.data.SearchRequest_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java index 127bfb93..697ec3b3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java @@ -158,7 +158,6 @@ static SearchRequest create() { @Override public SearchRequest unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static SearchRequest readSearchRequest(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.enumeration.data.SearchRequest_Impl result = new test.enumeration.data.SearchRequest_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java index b74cc835..23d01bb4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java @@ -75,7 +75,6 @@ static Car create() { @Override Car setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Car readCar(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { if (in.peek() == de.haumacher.msgbuf.json.JsonToken.NUMBER) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java index 53e94157..ca741f96 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java @@ -34,7 +34,6 @@ static Circle create() { @Override Circle setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Circle readCircle(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { if (in.peek() == de.haumacher.msgbuf.json.JsonToken.NUMBER) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java index 771b518d..754d7177 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java @@ -48,7 +48,6 @@ static Group create() { @Override Group setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Group readGroup(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { if (in.peek() == de.haumacher.msgbuf.json.JsonToken.NUMBER) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java index 698345f5..a7c643f2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java @@ -55,7 +55,6 @@ static Rectangle create() { @Override Rectangle setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Rectangle readRectangle(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { if (in.peek() == de.haumacher.msgbuf.json.JsonToken.NUMBER) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/SimpleType.java new file mode 100644 index 00000000..93c286bd --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/SimpleType.java @@ -0,0 +1,65 @@ +package test.graph.data; + +/** + * A concrete type without abstract super type. + */ +public interface SimpleType extends de.haumacher.msgbuf.graph.SharedGraphNode, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link SimpleType} instance. + */ + static SimpleType create() { + return new test.graph.data.SimpleType_Impl(); + } + + /** Identifier for the {@link SimpleType} type in JSON format. */ + static final String SIMPLE_TYPE__TYPE = "SimpleType"; + + /** @see #getStr() */ + static final String STR__PROP = "str"; + + /** @see #getX() */ + static final String X__PROP = "x"; + + /** + * A string property + */ + String getStr(); + + /** + * @see #getStr() + */ + SimpleType setStr(String value); + + /** + * An int property + */ + int getX(); + + /** + * @see #getX() + */ + SimpleType setX(int value); + + /** Reads a new instance from the given reader. */ + static SimpleType readSimpleType(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + if (in.peek() == de.haumacher.msgbuf.json.JsonToken.NUMBER) { + return (SimpleType) scope.resolveOrFail(in.nextInt()); + } + in.beginArray(); + String type = in.nextString(); + assert SIMPLE_TYPE__TYPE.equals(type); + int id = in.nextInt(); + test.graph.data.SimpleType_Impl result = new test.graph.data.SimpleType_Impl(); + scope.readData(result, id, in); + in.endArray(); + return result; + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType readSimpleType(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.graph.data.SimpleType_Impl.readSimpleType_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/SimpleType_Impl.java new file mode 100644 index 00000000..cdf549b9 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/SimpleType_Impl.java @@ -0,0 +1,221 @@ +package test.graph.data; + +/** + * A concrete type without abstract super type. + */ +class SimpleType_Impl extends de.haumacher.msgbuf.graph.AbstractSharedGraphNode implements SimpleType { + + private String _str = ""; + + private int _x = 0; + + /** + * Creates a {@link SimpleType_Impl} instance. + * + * @see SimpleType#create() + */ + protected SimpleType_Impl() { + super(); + } + + @Override + public final String getStr() { + return _str; + } + + @Override + public SimpleType setStr(String value) { + internalSetStr(value); + return this; + } + + /** Internal setter for {@link #getStr()} without chain call utility. */ + protected final void internalSetStr(String value) { + _listener.beforeSet(this, STR__PROP, value); + _str = value; + } + + @Override + public final int getX() { + return _x; + } + + @Override + public SimpleType setX(int value) { + internalSetX(value); + return this; + } + + /** Internal setter for {@link #getX()} without chain call utility. */ + protected final void internalSetX(int value) { + _listener.beforeSet(this, X__PROP, value); + _x = value; + } + + @Override + public String jsonType() { + return SIMPLE_TYPE__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + STR__PROP, + X__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case STR__PROP: return getStr(); + case X__PROP: return getX(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case STR__PROP: internalSetStr((String) value); break; + case X__PROP: internalSetX((int) value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(scope, out); + out.name(STR__PROP); + out.value(getStr()); + out.name(X__PROP); + out.value(getX()); + } + + @Override + public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out, String field) throws java.io.IOException { + switch (field) { + case STR__PROP: { + out.value(getStr()); + break; + } + case X__PROP: { + out.value(getX()); + break; + } + default: super.writeFieldValue(scope, out, field); + } + } + + @Override + public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case STR__PROP: setStr(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case X__PROP: setX(in.nextInt()); break; + default: super.readField(scope, in, field); + } + } + + /** XML element name representing a {@link SimpleType} type. */ + public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; + + /** XML attribute or element name of a {@link #getStr} property. */ + private static final String STR__XML_ATTR = "str"; + + /** XML attribute or element name of a {@link #getX} property. */ + private static final String X__XML_ATTR = "x"; + + @Override + public String getXmlTagName() { + return SIMPLE_TYPE__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(STR__XML_ATTR, getStr()); + out.writeAttribute(X__XML_ATTR, Integer.toString(getX())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + SimpleType_Impl result = new SimpleType_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case STR__XML_ATTR: { + setStr(value); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case STR__XML_ATTR: { + setStr(in.getElementText()); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/sharedgraph.proto b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/sharedgraph.proto index d7210f9e..d856d60d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/sharedgraph.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/sharedgraph.proto @@ -4,6 +4,17 @@ package test.graph.data; option SharedGraph; +/** + * A concrete type without abstract super type. + */ +message SimpleType { + /** A string property */ + string str; + + /** An int property */ + int x; +} + /** * An abstract base class for all shapes */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java index 2ceba747..6edeb74c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java @@ -90,7 +90,6 @@ static Car create() { @Override Car setColor(Color value); - /** Reads a new instance from the given reader. */ static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.hierarchy.data.Car_Impl result = new test.hierarchy.data.Car_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java index f407b09d..b32b9ff0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java @@ -43,7 +43,6 @@ static Circle create() { @Override Circle setColor(Color value); - /** Reads a new instance from the given reader. */ static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.hierarchy.data.Circle_Impl result = new test.hierarchy.data.Circle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java index e49c343b..dfddb6a9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java @@ -57,7 +57,6 @@ static Group create() { @Override Group setColor(Color value); - /** Reads a new instance from the given reader. */ static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.hierarchy.data.Group_Impl result = new test.hierarchy.data.Group_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java index 933ccb67..038691d1 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java @@ -64,7 +64,6 @@ static Optional create() { @Override Optional setColor(Color value); - /** Reads a new instance from the given reader. */ static Optional readOptional(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.hierarchy.data.Optional_Impl result = new test.hierarchy.data.Optional_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java index 937d1f8f..8a9c71c2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java @@ -67,7 +67,6 @@ static Rectangle create() { @Override Rectangle setColor(Color value); - /** Reads a new instance from the given reader. */ static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.hierarchy.data.Rectangle_Impl result = new test.hierarchy.data.Rectangle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/SimpleType.java new file mode 100644 index 00000000..2435bb05 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/SimpleType.java @@ -0,0 +1,77 @@ +package test.hierarchy.data; + +/** + * A concrete type without abstract super type. + */ +public interface SimpleType extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link SimpleType} instance. + */ + static SimpleType create() { + return new test.hierarchy.data.SimpleType_Impl(); + } + + /** Identifier for the {@link SimpleType} type in JSON format. */ + static final String SIMPLE_TYPE__TYPE = "SimpleType"; + + /** @see #getStr() */ + static final String STR__PROP = "str"; + + /** @see #getX() */ + static final String X__PROP = "x"; + + /** Identifier for the property {@link #getStr()} in binary format. */ + static final int STR__ID = 1; + + /** Identifier for the property {@link #getX()} in binary format. */ + static final int X__ID = 2; + + /** + * A string property + */ + String getStr(); + + /** + * @see #getStr() + */ + SimpleType setStr(String value); + + /** + * An int property + */ + int getX(); + + /** + * @see #getX() + */ + SimpleType setX(int value); + + @Override + public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.hierarchy.data.SimpleType_Impl result = new test.hierarchy.data.SimpleType_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static SimpleType readSimpleType(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + SimpleType result = test.hierarchy.data.SimpleType_Impl.readSimpleType_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType readSimpleType(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.hierarchy.data.SimpleType_Impl.readSimpleType_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/SimpleType_Impl.java new file mode 100644 index 00000000..2e5418aa --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/SimpleType_Impl.java @@ -0,0 +1,278 @@ +package test.hierarchy.data; + +/** + * A concrete type without abstract super type. + */ +class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements SimpleType { + + private String _str = ""; + + private int _x = 0; + + /** + * Creates a {@link SimpleType_Impl} instance. + * + * @see SimpleType#create() + */ + protected SimpleType_Impl() { + super(); + } + + @Override + public final String getStr() { + return _str; + } + + @Override + public SimpleType setStr(String value) { + internalSetStr(value); + return this; + } + + /** Internal setter for {@link #getStr()} without chain call utility. */ + protected final void internalSetStr(String value) { + _listener.beforeSet(this, STR__PROP, value); + _str = value; + } + + @Override + public final int getX() { + return _x; + } + + @Override + public SimpleType setX(int value) { + internalSetX(value); + return this; + } + + /** Internal setter for {@link #getX()} without chain call utility. */ + protected final void internalSetX(int value) { + _listener.beforeSet(this, X__PROP, value); + _x = value; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return SIMPLE_TYPE__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + STR__PROP, + X__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case STR__PROP: return getStr(); + case X__PROP: return getX(); + default: return SimpleType.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case STR__PROP: internalSetStr((String) value); break; + case X__PROP: internalSetX((int) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(STR__PROP); + out.value(getStr()); + out.name(X__PROP); + out.value(getX()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case STR__PROP: setStr(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case X__PROP: setX(in.nextInt()); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(STR__ID); + out.value(getStr()); + out.name(X__ID); + out.value(getX()); + } + + /** Helper for creating an object of type {@link SimpleType} from a polymorphic composition. */ + public static SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.hierarchy.data.SimpleType_Impl result = new SimpleType_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case STR__ID: setStr(in.nextString()); break; + case X__ID: setX(in.nextInt()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link SimpleType} type. */ + public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; + + /** XML attribute or element name of a {@link #getStr} property. */ + private static final String STR__XML_ATTR = "str"; + + /** XML attribute or element name of a {@link #getX} property. */ + private static final String X__XML_ATTR = "x"; + + @Override + public String getXmlTagName() { + return SIMPLE_TYPE__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(STR__XML_ATTR, getStr()); + out.writeAttribute(X__XML_ATTR, Integer.toString(getX())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + SimpleType_Impl result = new SimpleType_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case STR__XML_ATTR: { + setStr(value); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case STR__XML_ATTR: { + setStr(in.getElementText()); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/hierarchy.proto b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/hierarchy.proto index bbe067b7..ff762422 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/hierarchy.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/hierarchy.proto @@ -13,6 +13,17 @@ enum Color { `magenta`; } +/** + * A concrete type without abstract super type. + */ +message SimpleType { + /** A string property */ + string str; + + /** An int property */ + int x; +} + /** * An abstract base class for all shapes */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java index 953b053a..d545c99f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java @@ -19,7 +19,6 @@ static C create() { @Override public C unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static C readC(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.innertypeclash.A_Impl.C_Impl result = new test.innertypeclash.A_Impl.C_Impl(); @@ -113,7 +112,6 @@ static A create() { @Override public A unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static A readA(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.innertypeclash.A_Impl result = new test.innertypeclash.A_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java index 6b26e52d..4379b64f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java @@ -19,7 +19,6 @@ static C create() { @Override public C unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static C readC(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.innertypeclash.B_Impl.C_Impl result = new test.innertypeclash.B_Impl.C_Impl(); @@ -113,7 +112,6 @@ static B create() { @Override public B unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static B readB(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.innertypeclash.B_Impl result = new test.innertypeclash.B_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java index 747d765b..c009e9cf 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java @@ -55,7 +55,6 @@ static B create() { @Override public B unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static B readb(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.lowercasemessage.A_Impl.B_Impl result = new test.lowercasemessage.A_Impl.B_Impl(); @@ -131,7 +130,6 @@ static A create() { @Override public A unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static A reada(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.lowercasemessage.A_Impl result = new test.lowercasemessage.A_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java index c011403c..c5b265ad 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java @@ -64,7 +64,6 @@ static MyMessage create() { @Override public MyMessage unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static MyMessage readMyMessage(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.maptype.data.MyMessage_Impl result = new test.maptype.data.MyMessage_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java index 819f4853..63aca69f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java @@ -44,7 +44,6 @@ static Project create() { @Override public Project unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static Project readProject(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.maptype.data.Project_Impl result = new test.maptype.data.Project_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java index 7393c571..9d48d138 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java @@ -68,7 +68,6 @@ static Result create() { @Override public Result unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static Result readResult(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.nested.data.SearchResponse_Impl.Result_Impl result = new test.nested.data.SearchResponse_Impl.Result_Impl(); @@ -131,7 +130,6 @@ static SearchResponse create() { @Override public SearchResponse unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static SearchResponse readSearchResponse(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.nested.data.SearchResponse_Impl result = new test.nested.data.SearchResponse_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java new file mode 100644 index 00000000..74c52a91 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java @@ -0,0 +1,329 @@ +package test.nointerfaces; + +/** + * A concrete type without abstract super type. + */ +public class SimpleType extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link SimpleType} instance. + */ + public static SimpleType create() { + return new test.nointerfaces.SimpleType(); + } + + /** Identifier for the {@link SimpleType} type in JSON format. */ + public static final String SIMPLE_TYPE__TYPE = "SimpleType"; + + /** @see #getStr() */ + public static final String STR__PROP = "str"; + + /** @see #getX() */ + public static final String X__PROP = "x"; + + /** Identifier for the property {@link #getStr()} in binary format. */ + static final int STR__ID = 1; + + /** Identifier for the property {@link #getX()} in binary format. */ + static final int X__ID = 2; + + private String _str = ""; + + private int _x = 0; + + /** + * Creates a {@link SimpleType} instance. + * + * @see SimpleType#create() + */ + protected SimpleType() { + super(); + } + + /** + * A string property + */ + public final String getStr() { + return _str; + } + + /** + * @see #getStr() + */ + public SimpleType setStr(String value) { + internalSetStr(value); + return this; + } + + /** Internal setter for {@link #getStr()} without chain call utility. */ + protected final void internalSetStr(String value) { + _listener.beforeSet(this, STR__PROP, value); + _str = value; + } + + /** + * An int property + */ + public final int getX() { + return _x; + } + + /** + * @see #getX() + */ + public SimpleType setX(int value) { + internalSetX(value); + return this; + } + + /** Internal setter for {@link #getX()} without chain call utility. */ + protected final void internalSetX(int value) { + _listener.beforeSet(this, X__PROP, value); + _x = value; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return SIMPLE_TYPE__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + STR__PROP, + X__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case STR__PROP: return getStr(); + case X__PROP: return getX(); + default: return null; + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case STR__PROP: internalSetStr((String) value); break; + case X__PROP: internalSetX((int) value); break; + } + } + + /** Reads a new instance from the given reader. */ + public static SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nointerfaces.SimpleType result = new test.nointerfaces.SimpleType(); + result.readContent(in); + return result; + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(STR__PROP); + out.value(getStr()); + out.name(X__PROP); + out.value(getX()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case STR__PROP: setStr(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case X__PROP: setX(in.nextInt()); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(STR__ID); + out.value(getStr()); + out.name(X__ID); + out.value(getX()); + } + + /** Reads a new instance from the given reader. */ + public static SimpleType readSimpleType(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + SimpleType result = test.nointerfaces.SimpleType.readSimpleType_Content(in); + in.endObject(); + return result; + } + + /** Helper for creating an object of type {@link SimpleType} from a polymorphic composition. */ + public static SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nointerfaces.SimpleType result = new SimpleType(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case STR__ID: setStr(in.nextString()); break; + case X__ID: setX(in.nextInt()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link SimpleType} type. */ + public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; + + /** XML attribute or element name of a {@link #getStr} property. */ + private static final String STR__XML_ATTR = "str"; + + /** XML attribute or element name of a {@link #getX} property. */ + private static final String X__XML_ATTR = "x"; + + @Override + public String getXmlTagName() { + return SIMPLE_TYPE__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(STR__XML_ATTR, getStr()); + out.writeAttribute(X__XML_ATTR, Integer.toString(getX())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + SimpleType result = new SimpleType(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case STR__XML_ATTR: { + setStr(value); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case STR__XML_ATTR: { + setStr(in.getElementText()); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType readSimpleType(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nointerfaces.SimpleType.readSimpleType_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/nointerfaces.proto b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/nointerfaces.proto index 4c3ef659..a57b83f4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/nointerfaces.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/nointerfaces.proto @@ -4,6 +4,17 @@ package test.nointerfaces; option NoInterfaces; +/** + * A concrete type without abstract super type. + */ +message SimpleType { + /** A string property */ + string str; + + /** An int property */ + int x; +} + /** * An abstract base class for all shapes */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java index c553cb8d..2b8dc8f2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java @@ -87,7 +87,6 @@ static Car create() { @Override Car setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java index 1e262fdc..e3f47d1c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java @@ -40,7 +40,6 @@ static Circle create() { @Override Circle setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java index bc6b7b44..93ff9f52 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java @@ -54,7 +54,6 @@ static Group create() { @Override Group setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java index 9f19a9f5..6aa30c12 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java @@ -64,7 +64,6 @@ static Rectangle create() { @Override Rectangle setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/SimpleType.java new file mode 100644 index 00000000..d0879777 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/SimpleType.java @@ -0,0 +1,70 @@ +package test.nojson; + +/** + * A concrete type without abstract super type. + */ +public interface SimpleType extends de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link SimpleType} instance. + */ + static SimpleType create() { + return new test.nojson.SimpleType_Impl(); + } + + /** Identifier for the {@link SimpleType} type in JSON format. */ + static final String SIMPLE_TYPE__TYPE = "SimpleType"; + + /** @see #getStr() */ + static final String STR__PROP = "str"; + + /** @see #getX() */ + static final String X__PROP = "x"; + + /** Identifier for the property {@link #getStr()} in binary format. */ + static final int STR__ID = 1; + + /** Identifier for the property {@link #getX()} in binary format. */ + static final int X__ID = 2; + + /** + * A string property + */ + String getStr(); + + /** + * @see #getStr() + */ + SimpleType setStr(String value); + + /** + * An int property + */ + int getX(); + + /** + * @see #getX() + */ + SimpleType setX(int value); + + @Override + public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static SimpleType readSimpleType(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + SimpleType result = test.nojson.SimpleType_Impl.readSimpleType_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType readSimpleType(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nojson.SimpleType_Impl.readSimpleType_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/SimpleType_Impl.java new file mode 100644 index 00000000..3671c926 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/SimpleType_Impl.java @@ -0,0 +1,255 @@ +package test.nojson; + +/** + * A concrete type without abstract super type. + */ +class SimpleType_Impl implements SimpleType { + + private String _str = ""; + + private int _x = 0; + + /** + * Creates a {@link SimpleType_Impl} instance. + * + * @see SimpleType#create() + */ + protected SimpleType_Impl() { + super(); + } + + @Override + public final String getStr() { + return _str; + } + + @Override + public SimpleType setStr(String value) { + internalSetStr(value); + return this; + } + + /** Internal setter for {@link #getStr()} without chain call utility. */ + protected final void internalSetStr(String value) { + _listener.beforeSet(this, STR__PROP, value); + _str = value; + } + + @Override + public final int getX() { + return _x; + } + + @Override + public SimpleType setX(int value) { + internalSetX(value); + return this; + } + + /** Internal setter for {@link #getX()} without chain call utility. */ + protected final void internalSetX(int value) { + _listener.beforeSet(this, X__PROP, value); + _x = value; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return SIMPLE_TYPE__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + STR__PROP, + X__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case STR__PROP: return getStr(); + case X__PROP: return getX(); + default: return SimpleType.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case STR__PROP: internalSetStr((String) value); break; + case X__PROP: internalSetX((int) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(STR__ID); + out.value(getStr()); + out.name(X__ID); + out.value(getX()); + } + + /** Helper for creating an object of type {@link SimpleType} from a polymorphic composition. */ + public static SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nojson.SimpleType_Impl result = new SimpleType_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case STR__ID: setStr(in.nextString()); break; + case X__ID: setX(in.nextInt()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link SimpleType} type. */ + public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; + + /** XML attribute or element name of a {@link #getStr} property. */ + private static final String STR__XML_ATTR = "str"; + + /** XML attribute or element name of a {@link #getX} property. */ + private static final String X__XML_ATTR = "x"; + + @Override + public String getXmlTagName() { + return SIMPLE_TYPE__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(STR__XML_ATTR, getStr()); + out.writeAttribute(X__XML_ATTR, Integer.toString(getX())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + SimpleType_Impl result = new SimpleType_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case STR__XML_ATTR: { + setStr(value); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case STR__XML_ATTR: { + setStr(in.getElementText()); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/nojson.proto b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/nojson.proto index d0acddda..1967b373 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/nojson.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/nojson.proto @@ -4,6 +4,17 @@ package test.nojson; option NoJson; +/** + * A concrete type without abstract super type. + */ +message SimpleType { + /** A string property */ + string str; + + /** An int property */ + int x; +} + /** * An abstract base class for all shapes */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java index 4adff9e9..204195b2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java @@ -87,7 +87,6 @@ static Car create() { @Override Car setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.nolistener.Car_Impl result = new test.nolistener.Car_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java index 0a55e0a8..457f3585 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java @@ -40,7 +40,6 @@ static Circle create() { @Override Circle setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.nolistener.Circle_Impl result = new test.nolistener.Circle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java index cf875e91..4cd0b74e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java @@ -54,7 +54,6 @@ static Group create() { @Override Group setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.nolistener.Group_Impl result = new test.nolistener.Group_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java index a64424ba..aff71d41 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java @@ -64,7 +64,6 @@ static Rectangle create() { @Override Rectangle setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.nolistener.Rectangle_Impl result = new test.nolistener.Rectangle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/SimpleType.java new file mode 100644 index 00000000..482c9518 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/SimpleType.java @@ -0,0 +1,71 @@ +package test.nolistener; + +/** + * A concrete type without abstract super type. + */ +public interface SimpleType extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.data.ReflectiveDataObject, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link SimpleType} instance. + */ + static SimpleType create() { + return new test.nolistener.SimpleType_Impl(); + } + + /** Identifier for the {@link SimpleType} type in JSON format. */ + static final String SIMPLE_TYPE__TYPE = "SimpleType"; + + /** @see #getStr() */ + static final String STR__PROP = "str"; + + /** @see #getX() */ + static final String X__PROP = "x"; + + /** Identifier for the property {@link #getStr()} in binary format. */ + static final int STR__ID = 1; + + /** Identifier for the property {@link #getX()} in binary format. */ + static final int X__ID = 2; + + /** + * A string property + */ + String getStr(); + + /** + * @see #getStr() + */ + SimpleType setStr(String value); + + /** + * An int property + */ + int getX(); + + /** + * @see #getX() + */ + SimpleType setX(int value); + + /** Reads a new instance from the given reader. */ + static SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nolistener.SimpleType_Impl result = new test.nolistener.SimpleType_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static SimpleType readSimpleType(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + SimpleType result = test.nolistener.SimpleType_Impl.readSimpleType_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType readSimpleType(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nolistener.SimpleType_Impl.readSimpleType_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/SimpleType_Impl.java new file mode 100644 index 00000000..8fe0ca26 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/SimpleType_Impl.java @@ -0,0 +1,254 @@ +package test.nolistener; + +/** + * A concrete type without abstract super type. + */ +class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements SimpleType { + + private String _str = ""; + + private int _x = 0; + + /** + * Creates a {@link SimpleType_Impl} instance. + * + * @see SimpleType#create() + */ + protected SimpleType_Impl() { + super(); + } + + @Override + public final String getStr() { + return _str; + } + + @Override + public SimpleType setStr(String value) { + internalSetStr(value); + return this; + } + + /** Internal setter for {@link #getStr()} without chain call utility. */ + protected final void internalSetStr(String value) { + _str = value; + } + + @Override + public final int getX() { + return _x; + } + + @Override + public SimpleType setX(int value) { + internalSetX(value); + return this; + } + + /** Internal setter for {@link #getX()} without chain call utility. */ + protected final void internalSetX(int value) { + _x = value; + } + + @Override + public String jsonType() { + return SIMPLE_TYPE__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + STR__PROP, + X__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case STR__PROP: return getStr(); + case X__PROP: return getX(); + default: return SimpleType.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case STR__PROP: internalSetStr((String) value); break; + case X__PROP: internalSetX((int) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(STR__PROP); + out.value(getStr()); + out.name(X__PROP); + out.value(getX()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case STR__PROP: setStr(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case X__PROP: setX(in.nextInt()); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(STR__ID); + out.value(getStr()); + out.name(X__ID); + out.value(getX()); + } + + /** Helper for creating an object of type {@link SimpleType} from a polymorphic composition. */ + public static SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nolistener.SimpleType_Impl result = new SimpleType_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case STR__ID: setStr(in.nextString()); break; + case X__ID: setX(in.nextInt()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link SimpleType} type. */ + public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; + + /** XML attribute or element name of a {@link #getStr} property. */ + private static final String STR__XML_ATTR = "str"; + + /** XML attribute or element name of a {@link #getX} property. */ + private static final String X__XML_ATTR = "x"; + + @Override + public String getXmlTagName() { + return SIMPLE_TYPE__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(STR__XML_ATTR, getStr()); + out.writeAttribute(X__XML_ATTR, Integer.toString(getX())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + SimpleType_Impl result = new SimpleType_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case STR__XML_ATTR: { + setStr(value); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case STR__XML_ATTR: { + setStr(in.getElementText()); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/nolistener.proto b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/nolistener.proto index 64b63d8a..9996df77 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/nolistener.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/nolistener.proto @@ -4,6 +4,17 @@ package test.nolistener; option NoListener; +/** + * A concrete type without abstract super type. + */ +message SimpleType { + /** A string property */ + string str; + + /** An int property */ + int x; +} + /** * An abstract base class for all shapes */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/SimpleType.java new file mode 100644 index 00000000..84f72734 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/SimpleType.java @@ -0,0 +1,111 @@ +package test.noreflection; + +/** + * A concrete type without abstract super type. + */ +public class SimpleType extends de.haumacher.msgbuf.data.AbstractDataObject { + + /** + * Creates a {@link SimpleType} instance. + */ + public static SimpleType create() { + return new test.noreflection.SimpleType(); + } + + /** Identifier for the {@link SimpleType} type in JSON format. */ + public static final String SIMPLE_TYPE__TYPE = "SimpleType"; + + /** @see #getStr() */ + private static final String STR__PROP = "str"; + + /** @see #getX() */ + private static final String X__PROP = "x"; + + private String _str = ""; + + private int _x = 0; + + /** + * Creates a {@link SimpleType} instance. + * + * @see SimpleType#create() + */ + protected SimpleType() { + super(); + } + + /** + * A string property + */ + public final String getStr() { + return _str; + } + + /** + * @see #getStr() + */ + public SimpleType setStr(String value) { + internalSetStr(value); + return this; + } + + /** Internal setter for {@link #getStr()} without chain call utility. */ + protected final void internalSetStr(String value) { + _str = value; + } + + /** + * An int property + */ + public final int getX() { + return _x; + } + + /** + * @see #getX() + */ + public SimpleType setX(int value) { + internalSetX(value); + return this; + } + + /** Internal setter for {@link #getX()} without chain call utility. */ + protected final void internalSetX(int value) { + _x = value; + } + + public String jsonType() { + return SIMPLE_TYPE__TYPE; + } + + /** Reads a new instance from the given reader. */ + public static SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.noreflection.SimpleType result = new test.noreflection.SimpleType(); + result.readContent(in); + return result; + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(STR__PROP); + out.value(getStr()); + out.name(X__PROP); + out.value(getX()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case STR__PROP: setStr(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case X__PROP: setX(in.nextInt()); break; + default: super.readField(in, field); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/noreflection.proto b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/noreflection.proto index 51ba079e..5a9359b9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/noreflection.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/noreflection.proto @@ -9,6 +9,17 @@ option NoTypeKind; option NoXml; option NoInterfaces; +/** + * A concrete type without abstract super type. + */ +message SimpleType { + /** A string property */ + string str; + + /** An int property */ + int x; +} + /** * An abstract base class for all shapes */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/SimpleType.java new file mode 100644 index 00000000..ccea0d09 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/SimpleType.java @@ -0,0 +1,35 @@ +package test.nothing; + +/** + * A concrete type without abstract super type. + */ +public interface SimpleType { + + /** + * Creates a {@link SimpleType} instance. + */ + static SimpleType create() { + return new test.nothing.SimpleType_Impl(); + } + + /** + * A string property + */ + String getStr(); + + /** + * @see #getStr() + */ + SimpleType setStr(String value); + + /** + * An int property + */ + int getX(); + + /** + * @see #getX() + */ + SimpleType setX(int value); + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/SimpleType_Impl.java new file mode 100644 index 00000000..c12888b4 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/SimpleType_Impl.java @@ -0,0 +1,53 @@ +package test.nothing; + +/** + * A concrete type without abstract super type. + */ +class SimpleType_Impl implements SimpleType { + + private String _str = ""; + + private int _x = 0; + + /** + * Creates a {@link SimpleType_Impl} instance. + * + * @see SimpleType#create() + */ + protected SimpleType_Impl() { + super(); + } + + @Override + public final String getStr() { + return _str; + } + + @Override + public SimpleType setStr(String value) { + internalSetStr(value); + return this; + } + + /** Internal setter for {@link #getStr()} without chain call utility. */ + protected final void internalSetStr(String value) { + _str = value; + } + + @Override + public final int getX() { + return _x; + } + + @Override + public SimpleType setX(int value) { + internalSetX(value); + return this; + } + + /** Internal setter for {@link #getX()} without chain call utility. */ + protected final void internalSetX(int value) { + _x = value; + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/nothing.proto b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/nothing.proto index 07ad08b7..5e6bccf9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/nothing.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/nothing.proto @@ -10,6 +10,17 @@ option NoVisitor; option NoTypeKind; option NoXml; +/** + * A concrete type without abstract super type. + */ +message SimpleType { + /** A string property */ + string str; + + /** An int property */ + int x; +} + /** * An abstract base class for all shapes */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java index 925d8c33..2294c7e7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java @@ -87,7 +87,6 @@ static Car create() { @Override Car setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.notypekind.Car_Impl result = new test.notypekind.Car_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java index 8d254baf..9532b9ec 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java @@ -40,7 +40,6 @@ static Circle create() { @Override Circle setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.notypekind.Circle_Impl result = new test.notypekind.Circle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java index e1121bfa..ee3e11da 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java @@ -54,7 +54,6 @@ static Group create() { @Override Group setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.notypekind.Group_Impl result = new test.notypekind.Group_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java index 273e9265..b6700f2d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java @@ -64,7 +64,6 @@ static Rectangle create() { @Override Rectangle setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.notypekind.Rectangle_Impl result = new test.notypekind.Rectangle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/SimpleType.java new file mode 100644 index 00000000..6053721b --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/SimpleType.java @@ -0,0 +1,77 @@ +package test.notypekind; + +/** + * A concrete type without abstract super type. + */ +public interface SimpleType extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link SimpleType} instance. + */ + static SimpleType create() { + return new test.notypekind.SimpleType_Impl(); + } + + /** Identifier for the {@link SimpleType} type in JSON format. */ + static final String SIMPLE_TYPE__TYPE = "SimpleType"; + + /** @see #getStr() */ + static final String STR__PROP = "str"; + + /** @see #getX() */ + static final String X__PROP = "x"; + + /** Identifier for the property {@link #getStr()} in binary format. */ + static final int STR__ID = 1; + + /** Identifier for the property {@link #getX()} in binary format. */ + static final int X__ID = 2; + + /** + * A string property + */ + String getStr(); + + /** + * @see #getStr() + */ + SimpleType setStr(String value); + + /** + * An int property + */ + int getX(); + + /** + * @see #getX() + */ + SimpleType setX(int value); + + @Override + public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.notypekind.SimpleType_Impl result = new test.notypekind.SimpleType_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static SimpleType readSimpleType(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + SimpleType result = test.notypekind.SimpleType_Impl.readSimpleType_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType readSimpleType(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.notypekind.SimpleType_Impl.readSimpleType_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/SimpleType_Impl.java new file mode 100644 index 00000000..5bdeab16 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/SimpleType_Impl.java @@ -0,0 +1,278 @@ +package test.notypekind; + +/** + * A concrete type without abstract super type. + */ +class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements SimpleType { + + private String _str = ""; + + private int _x = 0; + + /** + * Creates a {@link SimpleType_Impl} instance. + * + * @see SimpleType#create() + */ + protected SimpleType_Impl() { + super(); + } + + @Override + public final String getStr() { + return _str; + } + + @Override + public SimpleType setStr(String value) { + internalSetStr(value); + return this; + } + + /** Internal setter for {@link #getStr()} without chain call utility. */ + protected final void internalSetStr(String value) { + _listener.beforeSet(this, STR__PROP, value); + _str = value; + } + + @Override + public final int getX() { + return _x; + } + + @Override + public SimpleType setX(int value) { + internalSetX(value); + return this; + } + + /** Internal setter for {@link #getX()} without chain call utility. */ + protected final void internalSetX(int value) { + _listener.beforeSet(this, X__PROP, value); + _x = value; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return SIMPLE_TYPE__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + STR__PROP, + X__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case STR__PROP: return getStr(); + case X__PROP: return getX(); + default: return SimpleType.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case STR__PROP: internalSetStr((String) value); break; + case X__PROP: internalSetX((int) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(STR__PROP); + out.value(getStr()); + out.name(X__PROP); + out.value(getX()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case STR__PROP: setStr(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case X__PROP: setX(in.nextInt()); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(STR__ID); + out.value(getStr()); + out.name(X__ID); + out.value(getX()); + } + + /** Helper for creating an object of type {@link SimpleType} from a polymorphic composition. */ + public static SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.notypekind.SimpleType_Impl result = new SimpleType_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case STR__ID: setStr(in.nextString()); break; + case X__ID: setX(in.nextInt()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link SimpleType} type. */ + public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; + + /** XML attribute or element name of a {@link #getStr} property. */ + private static final String STR__XML_ATTR = "str"; + + /** XML attribute or element name of a {@link #getX} property. */ + private static final String X__XML_ATTR = "x"; + + @Override + public String getXmlTagName() { + return SIMPLE_TYPE__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(STR__XML_ATTR, getStr()); + out.writeAttribute(X__XML_ATTR, Integer.toString(getX())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + SimpleType_Impl result = new SimpleType_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case STR__XML_ATTR: { + setStr(value); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case STR__XML_ATTR: { + setStr(in.getElementText()); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/hierarchy.proto b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/hierarchy.proto index 2fb42ee4..4c0e95c6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/hierarchy.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/hierarchy.proto @@ -4,6 +4,17 @@ package test.notypekind; option NoTypeKind; +/** + * A concrete type without abstract super type. + */ +message SimpleType { + /** A string property */ + string str; + + /** An int property */ + int x; +} + /** * An abstract base class for all shapes */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java index 7a70ad7c..24cb56f4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java @@ -87,7 +87,6 @@ static Car create() { @Override Car setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.novisit.Car_Impl result = new test.novisit.Car_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java index aaab3e92..75345e79 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java @@ -40,7 +40,6 @@ static Circle create() { @Override Circle setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.novisit.Circle_Impl result = new test.novisit.Circle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java index 1ce6e729..02052c7a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java @@ -54,7 +54,6 @@ static Group create() { @Override Group setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.novisit.Group_Impl result = new test.novisit.Group_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java index 5aa86761..2426b492 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java @@ -64,7 +64,6 @@ static Rectangle create() { @Override Rectangle setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.novisit.Rectangle_Impl result = new test.novisit.Rectangle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType.java new file mode 100644 index 00000000..317fdf42 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType.java @@ -0,0 +1,77 @@ +package test.novisit; + +/** + * A concrete type without abstract super type. + */ +public interface SimpleType extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link SimpleType} instance. + */ + static SimpleType create() { + return new test.novisit.SimpleType_Impl(); + } + + /** Identifier for the {@link SimpleType} type in JSON format. */ + static final String SIMPLE_TYPE__TYPE = "SimpleType"; + + /** @see #getStr() */ + static final String STR__PROP = "str"; + + /** @see #getX() */ + static final String X__PROP = "x"; + + /** Identifier for the property {@link #getStr()} in binary format. */ + static final int STR__ID = 1; + + /** Identifier for the property {@link #getX()} in binary format. */ + static final int X__ID = 2; + + /** + * A string property + */ + String getStr(); + + /** + * @see #getStr() + */ + SimpleType setStr(String value); + + /** + * An int property + */ + int getX(); + + /** + * @see #getX() + */ + SimpleType setX(int value); + + @Override + public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisit.SimpleType_Impl result = new test.novisit.SimpleType_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static SimpleType readSimpleType(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + SimpleType result = test.novisit.SimpleType_Impl.readSimpleType_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType readSimpleType(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.novisit.SimpleType_Impl.readSimpleType_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType_Impl.java new file mode 100644 index 00000000..8ced3a3f --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType_Impl.java @@ -0,0 +1,278 @@ +package test.novisit; + +/** + * A concrete type without abstract super type. + */ +class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements SimpleType { + + private String _str = ""; + + private int _x = 0; + + /** + * Creates a {@link SimpleType_Impl} instance. + * + * @see SimpleType#create() + */ + protected SimpleType_Impl() { + super(); + } + + @Override + public final String getStr() { + return _str; + } + + @Override + public SimpleType setStr(String value) { + internalSetStr(value); + return this; + } + + /** Internal setter for {@link #getStr()} without chain call utility. */ + protected final void internalSetStr(String value) { + _listener.beforeSet(this, STR__PROP, value); + _str = value; + } + + @Override + public final int getX() { + return _x; + } + + @Override + public SimpleType setX(int value) { + internalSetX(value); + return this; + } + + /** Internal setter for {@link #getX()} without chain call utility. */ + protected final void internalSetX(int value) { + _listener.beforeSet(this, X__PROP, value); + _x = value; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return SIMPLE_TYPE__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + STR__PROP, + X__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case STR__PROP: return getStr(); + case X__PROP: return getX(); + default: return SimpleType.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case STR__PROP: internalSetStr((String) value); break; + case X__PROP: internalSetX((int) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(STR__PROP); + out.value(getStr()); + out.name(X__PROP); + out.value(getX()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case STR__PROP: setStr(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case X__PROP: setX(in.nextInt()); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(STR__ID); + out.value(getStr()); + out.name(X__ID); + out.value(getX()); + } + + /** Helper for creating an object of type {@link SimpleType} from a polymorphic composition. */ + public static SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.novisit.SimpleType_Impl result = new SimpleType_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case STR__ID: setStr(in.nextString()); break; + case X__ID: setX(in.nextInt()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link SimpleType} type. */ + public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; + + /** XML attribute or element name of a {@link #getStr} property. */ + private static final String STR__XML_ATTR = "str"; + + /** XML attribute or element name of a {@link #getX} property. */ + private static final String X__XML_ATTR = "x"; + + @Override + public String getXmlTagName() { + return SIMPLE_TYPE__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(STR__XML_ATTR, getStr()); + out.writeAttribute(X__XML_ATTR, Integer.toString(getX())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + SimpleType_Impl result = new SimpleType_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case STR__XML_ATTR: { + setStr(value); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case STR__XML_ATTR: { + setStr(in.getElementText()); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/hierarchy.proto b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/hierarchy.proto index 01988ad5..668ce46b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/hierarchy.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/hierarchy.proto @@ -4,6 +4,17 @@ package test.novisit; option NoVisitor; +/** + * A concrete type without abstract super type. + */ +message SimpleType { + /** A string property */ + string str; + + /** An int property */ + int x; +} + /** * An abstract base class for all shapes */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java index 1b338ee4..3dd4f794 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java @@ -87,7 +87,6 @@ static Car create() { @Override Car setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.novisitexceptions.Car_Impl result = new test.novisitexceptions.Car_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java index edfe8040..b2e09609 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java @@ -40,7 +40,6 @@ static Circle create() { @Override Circle setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.novisitexceptions.Circle_Impl result = new test.novisitexceptions.Circle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java index 442ebda7..c9fd4b25 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java @@ -54,7 +54,6 @@ static Group create() { @Override Group setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.novisitexceptions.Group_Impl result = new test.novisitexceptions.Group_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java index 567c1629..85191587 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java @@ -64,7 +64,6 @@ static Rectangle create() { @Override Rectangle setYCoordinate(int value); - /** Reads a new instance from the given reader. */ static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.novisitexceptions.Rectangle_Impl result = new test.novisitexceptions.Rectangle_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType.java new file mode 100644 index 00000000..c3e2030d --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType.java @@ -0,0 +1,77 @@ +package test.novisitexceptions; + +/** + * A concrete type without abstract super type. + */ +public interface SimpleType extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link SimpleType} instance. + */ + static SimpleType create() { + return new test.novisitexceptions.SimpleType_Impl(); + } + + /** Identifier for the {@link SimpleType} type in JSON format. */ + static final String SIMPLE_TYPE__TYPE = "SimpleType"; + + /** @see #getStr() */ + static final String STR__PROP = "str"; + + /** @see #getX() */ + static final String X__PROP = "x"; + + /** Identifier for the property {@link #getStr()} in binary format. */ + static final int STR__ID = 1; + + /** Identifier for the property {@link #getX()} in binary format. */ + static final int X__ID = 2; + + /** + * A string property + */ + String getStr(); + + /** + * @see #getStr() + */ + SimpleType setStr(String value); + + /** + * An int property + */ + int getX(); + + /** + * @see #getX() + */ + SimpleType setX(int value); + + @Override + public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisitexceptions.SimpleType_Impl result = new test.novisitexceptions.SimpleType_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static SimpleType readSimpleType(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + SimpleType result = test.novisitexceptions.SimpleType_Impl.readSimpleType_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType readSimpleType(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.novisitexceptions.SimpleType_Impl.readSimpleType_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType_Impl.java new file mode 100644 index 00000000..7d4a9fc2 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType_Impl.java @@ -0,0 +1,278 @@ +package test.novisitexceptions; + +/** + * A concrete type without abstract super type. + */ +class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements SimpleType { + + private String _str = ""; + + private int _x = 0; + + /** + * Creates a {@link SimpleType_Impl} instance. + * + * @see SimpleType#create() + */ + protected SimpleType_Impl() { + super(); + } + + @Override + public final String getStr() { + return _str; + } + + @Override + public SimpleType setStr(String value) { + internalSetStr(value); + return this; + } + + /** Internal setter for {@link #getStr()} without chain call utility. */ + protected final void internalSetStr(String value) { + _listener.beforeSet(this, STR__PROP, value); + _str = value; + } + + @Override + public final int getX() { + return _x; + } + + @Override + public SimpleType setX(int value) { + internalSetX(value); + return this; + } + + /** Internal setter for {@link #getX()} without chain call utility. */ + protected final void internalSetX(int value) { + _listener.beforeSet(this, X__PROP, value); + _x = value; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return SIMPLE_TYPE__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + STR__PROP, + X__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case STR__PROP: return getStr(); + case X__PROP: return getX(); + default: return SimpleType.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case STR__PROP: internalSetStr((String) value); break; + case X__PROP: internalSetX((int) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(STR__PROP); + out.value(getStr()); + out.name(X__PROP); + out.value(getX()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case STR__PROP: setStr(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case X__PROP: setX(in.nextInt()); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(STR__ID); + out.value(getStr()); + out.name(X__ID); + out.value(getX()); + } + + /** Helper for creating an object of type {@link SimpleType} from a polymorphic composition. */ + public static SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.novisitexceptions.SimpleType_Impl result = new SimpleType_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case STR__ID: setStr(in.nextString()); break; + case X__ID: setX(in.nextInt()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link SimpleType} type. */ + public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; + + /** XML attribute or element name of a {@link #getStr} property. */ + private static final String STR__XML_ATTR = "str"; + + /** XML attribute or element name of a {@link #getX} property. */ + private static final String X__XML_ATTR = "x"; + + @Override + public String getXmlTagName() { + return SIMPLE_TYPE__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(STR__XML_ATTR, getStr()); + out.writeAttribute(X__XML_ATTR, Integer.toString(getX())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + SimpleType_Impl result = new SimpleType_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case STR__XML_ATTR: { + setStr(value); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case STR__XML_ATTR: { + setStr(in.getElementText()); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/hierarchy.proto b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/hierarchy.proto index 20d056fa..5975543c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/hierarchy.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/hierarchy.proto @@ -4,6 +4,17 @@ package test.novisitexceptions; option NoVisitorExceptions; +/** + * A concrete type without abstract super type. + */ +message SimpleType { + /** A string property */ + string str; + + /** An int property */ + int x; +} + /** * An abstract base class for all shapes */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java index b3d4d7a2..202bffd8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java @@ -186,7 +186,6 @@ static NullableValues create() { */ boolean hasOptionalDecision(); - /** Reads a new instance from the given reader. */ static NullableValues readNullableValues(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.nullable.data.NullableValues_Impl result = new test.nullable.data.NullableValues_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java b/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java index 7408248d..5c19d22c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java @@ -18,7 +18,6 @@ static SampleMessage create() { @Override public SampleMessage unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static SampleMessage readSampleMessage(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.oneoffield.data.SampleMessage_Impl result = new test.oneoffield.data.SampleMessage_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/SimpleType.java new file mode 100644 index 00000000..1b759789 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/SimpleType.java @@ -0,0 +1,41 @@ +package test.onlyxml.data; + +/** + * A concrete type without abstract super type. + */ +public interface SimpleType extends de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link SimpleType} instance. + */ + static SimpleType create() { + return new test.onlyxml.data.SimpleType_Impl(); + } + + /** + * A string property + */ + String getStr(); + + /** + * @see #getStr() + */ + SimpleType setStr(String value); + + /** + * An int property + */ + int getX(); + + /** + * @see #getX() + */ + SimpleType setX(int value); + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType readSimpleType(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.onlyxml.data.SimpleType_Impl.readSimpleType_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/SimpleType_Impl.java new file mode 100644 index 00000000..88d82c7a --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/SimpleType_Impl.java @@ -0,0 +1,154 @@ +package test.onlyxml.data; + +/** + * A concrete type without abstract super type. + */ +class SimpleType_Impl implements SimpleType { + + private String _str = ""; + + private int _x = 0; + + /** + * Creates a {@link SimpleType_Impl} instance. + * + * @see SimpleType#create() + */ + protected SimpleType_Impl() { + super(); + } + + @Override + public final String getStr() { + return _str; + } + + @Override + public SimpleType setStr(String value) { + internalSetStr(value); + return this; + } + + /** Internal setter for {@link #getStr()} without chain call utility. */ + protected final void internalSetStr(String value) { + _str = value; + } + + @Override + public final int getX() { + return _x; + } + + @Override + public SimpleType setX(int value) { + internalSetX(value); + return this; + } + + /** Internal setter for {@link #getX()} without chain call utility. */ + protected final void internalSetX(int value) { + _x = value; + } + + /** XML element name representing a {@link SimpleType} type. */ + public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; + + /** XML attribute or element name of a {@link #getStr} property. */ + private static final String STR__XML_ATTR = "str"; + + /** XML attribute or element name of a {@link #getX} property. */ + private static final String X__XML_ATTR = "x"; + + @Override + public String getXmlTagName() { + return SIMPLE_TYPE__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(STR__XML_ATTR, getStr()); + out.writeAttribute(X__XML_ATTR, Integer.toString(getX())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + SimpleType_Impl result = new SimpleType_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case STR__XML_ATTR: { + setStr(value); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case STR__XML_ATTR: { + setStr(in.getElementText()); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/onlyxml.proto b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/onlyxml.proto index 3bfa3b6c..42db8f5d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/onlyxml.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/onlyxml.proto @@ -9,6 +9,17 @@ option NoListener; option NoVisitor; option NoTypeKind; +/** + * A concrete type without abstract super type. + */ +message SimpleType { + /** A string property */ + string str; + + /** An int property */ + int x; +} + /** * An abstract base class for all shapes */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java index efc059aa..2919ee96 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java @@ -85,7 +85,6 @@ static MyMessage1 create() { @Override public MyMessage1 unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static MyMessage1 readMyMessage1(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.options.data.MyMessage1_Impl result = new test.options.data.MyMessage1_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java index 23a49715..8103f108 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java @@ -81,7 +81,6 @@ static MyMessage2 create() { @Override public MyMessage2 unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static MyMessage2 readMyMessage2(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.options.data.MyMessage2_Impl result = new test.options.data.MyMessage2_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java index 4e564293..2eb53d37 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java @@ -164,7 +164,6 @@ static A create() { @Override public A unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static A readA(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.references.data.A_Impl result = new test.references.data.A_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java index 1b269698..85daad9f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java @@ -41,7 +41,6 @@ static B create() { @Override public B unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static B readB(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.references.data.B_Impl result = new test.references.data.B_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java index d089e66f..75be9fdd 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java @@ -57,7 +57,6 @@ static SearchRequest create() { @Override public SearchRequest unregisterListener(de.haumacher.msgbuf.observer.Listener l); - /** Reads a new instance from the given reader. */ static SearchRequest readSearchRequest(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.types.data.SearchRequest_Impl result = new test.types.data.SearchRequest_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java index c30a2f3f..1cb883d2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java @@ -28,7 +28,6 @@ static AnnotatedMessage create() { */ AnnotatedMessage setAnnotatedField(String value); - /** Reads a new instance from the given reader. */ static AnnotatedMessage readannotated_message(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.underscorename.AnnotatedMessage_Impl result = new test.underscorename.AnnotatedMessage_Impl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java index c4e8d81b..fbb34a65 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java @@ -28,7 +28,6 @@ static SomeName create() { */ SomeName setMyField(String value); - /** Reads a new instance from the given reader. */ static SomeName readsome_name(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.underscorename.SomeName_Impl result = new test.underscorename.SomeName_Impl(); From 1a087497a301d32a447a0cb12bcd749ff56e4f2c Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 1 Jan 2023 20:03:45 +0100 Subject: [PATCH 028/207] Do not generate jsonType() on simple types without hierarchy. --- .../msgbuf/generator/MessageGenerator.java | 22 +++++++++++-------- .../java/test/noreflection/SimpleType.java | 4 ---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 525608b0..63f0bc26 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -974,16 +974,20 @@ private void reflectionType() { } } } else { - if (!_interface) { - nl(); - if (_reflection || _def.getExtendedDef() != null) { - line("@Override"); - } - line("public String jsonType() {"); - { - line("return " + jsonTypeConstant(_def) + ";"); + if (_reflection || _def.hasExtendedDef() || !_def.getSpecializations().isEmpty()) { + if (!_interface) { + nl(); + if (_reflection || _def.hasExtendedDef()) { + line("@Override"); + } else { + jsonTypeDoc(); + } + line("public String jsonType() {"); + { + line("return " + jsonTypeConstant(_def) + ";"); + } + line("}"); } - line("}"); } } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/SimpleType.java index 84f72734..76d8b95a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/SimpleType.java @@ -74,10 +74,6 @@ protected final void internalSetX(int value) { _x = value; } - public String jsonType() { - return SIMPLE_TYPE__TYPE; - } - /** Reads a new instance from the given reader. */ public static SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.noreflection.SimpleType result = new test.noreflection.SimpleType(); From 7f1478951923b8d512f44b90d983f794583e18fb Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 1 Jan 2023 20:16:17 +0100 Subject: [PATCH 029/207] Do not re-declare redundant jsonType() method on abstract non-base types --- .../java/de/haumacher/msgbuf/generator/MessageGenerator.java | 2 +- .../src/test/java/test/noreflection/AtomicShape.java | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 63f0bc26..7ed51e5b 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -965,7 +965,7 @@ private void generateReflection() { private void reflectionType() { if (_def.isAbstract()) { - if (!_reflection) { + if (!_def.hasExtendedDef() && !_reflection) { // Otherwise, the interface is inherited from ReflectiveDataObject. if (_interface || _noInterfaces) { nl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape.java index b027f9be..a1bff701 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape.java @@ -35,9 +35,6 @@ public AtomicShape setYCoordinate(int value) { return this; } - /** The type identifier for this concrete subtype. */ - public abstract String jsonType(); - /** Reads a new instance from the given reader. */ public static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { AtomicShape result; From 9f0a5b5329ab09203090209f3f55c752350cf001 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 1 Jan 2023 22:05:40 +0100 Subject: [PATCH 030/207] Moved generated implementation classes to separate sub-package. --- .../generator/AbstractMessageGenerator.java | 14 +- .../msgbuf/generator/CodeConvention.java | 17 +- .../haumacher/msgbuf/generator/Generator.java | 20 +- .../msgbuf/generator/MessageGenerator.java | 55 ++--- .../msgbuf/generator/TypeGenerator.java | 11 +- .../generator/plugins/XmlStreamingPlugin.java | 12 +- .../test/comments/data/SearchRequest.java | 28 +-- .../data/impl}/SearchRequest_Impl.java | 35 +-- .../test/enumeration/data/SearchRequest.java | 32 +-- .../data/{ => impl}/SearchRequest_Impl.java | 41 ++-- .../java/test/graph/data/AtomicShape.java | 26 +-- .../src/test/java/test/graph/data/Car.java | 32 +-- .../src/test/java/test/graph/data/Circle.java | 22 +- .../src/test/java/test/graph/data/Group.java | 28 +-- .../test/java/test/graph/data/Rectangle.java | 24 +- .../src/test/java/test/graph/data/Shape.java | 42 ++-- .../test/java/test/graph/data/SimpleType.java | 20 +- .../data/impl}/AtomicShape_Impl.java | 23 +- .../test/graph/data/{ => impl}/Car_Impl.java | 54 ++--- .../graph/data/{ => impl}/Circle_Impl.java | 21 +- .../graph/data/{ => impl}/Group_Impl.java | 48 ++-- .../graph/data/{ => impl}/Rectangle_Impl.java | 23 +- .../graph/data/{ => impl}/Shape_Impl.java | 23 +- .../data/{ => impl}/SimpleType_Impl.java | 17 +- .../java/test/hierarchy/data/AtomicShape.java | 30 +-- .../test/java/test/hierarchy/data/Car.java | 38 ++-- .../test/java/test/hierarchy/data/Circle.java | 28 +-- .../test/java/test/hierarchy/data/Group.java | 34 +-- .../java/test/hierarchy/data/Optional.java | 32 +-- .../java/test/hierarchy/data/Rectangle.java | 30 +-- .../test/java/test/hierarchy/data/Shape.java | 62 ++--- .../java/test/hierarchy/data/SimpleType.java | 26 +-- .../hierarchy/data/impl/AtomicShape_Impl.java | 90 ++++++++ .../hierarchy/data/{ => impl}/Car_Impl.java | 62 ++--- .../data/{ => impl}/Circle_Impl.java | 29 +-- .../hierarchy/data/{ => impl}/Group_Impl.java | 76 +++---- .../data/{ => impl}/Optional_Impl.java | 60 ++--- .../data/impl}/Rectangle_Impl.java | 38 ++-- .../hierarchy/data/{ => impl}/Shape_Impl.java | 41 ++-- .../data/impl}/SimpleType_Impl.java | 29 +-- .../src/test/java/test/innertypeclash/A.java | 56 ++--- .../src/test/java/test/innertypeclash/B.java | 56 ++--- .../innertypeclash/{ => impl}/A_Impl.java | 81 +++---- .../innertypeclash/{ => impl}/B_Impl.java | 81 +++---- .../test/java/test/lowercasemessage/A.java | 60 ++--- .../lowercasemessage/{ => impl}/A_Impl.java | 94 ++++---- .../java/test/maptype/data/MyMessage.java | 32 +-- .../test/java/test/maptype/data/Project.java | 26 +-- .../data/{ => impl}/MyMessage_Impl.java | 49 ++-- .../maptype/data/{ => impl}/Project_Impl.java | 29 +-- .../java/test/nested/data/SearchResponse.java | 60 ++--- .../data/{ => impl}/SearchResponse_Impl.java | 85 +++---- .../java/test/nointerfaces/AtomicShape.java | 35 +-- .../src/test/java/test/nointerfaces/Car.java | 62 ++--- .../test/java/test/nointerfaces/Circle.java | 35 +-- .../test/java/test/nointerfaces/Group.java | 60 ++--- .../java/test/nointerfaces/Rectangle.java | 37 +-- .../test/java/test/nointerfaces/Shape.java | 53 ++--- .../java/test/nointerfaces/SimpleType.java | 31 +-- .../test/java/test/nojson/AtomicShape.java | 24 +- .../src/test/java/test/nojson/Car.java | 32 +-- .../src/test/java/test/nojson/Circle.java | 22 +- .../src/test/java/test/nojson/Group.java | 28 +-- .../src/test/java/test/nojson/Rectangle.java | 24 +- .../src/test/java/test/nojson/Shape.java | 46 ++-- .../src/test/java/test/nojson/SimpleType.java | 22 +- .../impl}/AtomicShape_Impl.java | 29 +-- .../java/test/nojson/{ => impl}/Car_Impl.java | 60 ++--- .../test/nojson/{ => impl}/Circle_Impl.java | 27 +-- .../test/nojson/{ => impl}/Group_Impl.java | 52 ++--- .../nojson/{ => impl}/Rectangle_Impl.java | 29 +-- .../test/nojson/{ => impl}/Shape_Impl.java | 29 +-- .../nojson/{ => impl}/SimpleType_Impl.java | 29 +-- .../java/test/nolistener/AtomicShape.java | 28 +-- .../src/test/java/test/nolistener/Car.java | 36 +-- .../src/test/java/test/nolistener/Circle.java | 26 +-- .../src/test/java/test/nolistener/Group.java | 32 +-- .../test/java/test/nolistener/Rectangle.java | 28 +-- .../src/test/java/test/nolistener/Shape.java | 46 ++-- .../test/java/test/nolistener/SimpleType.java | 22 +- .../impl}/AtomicShape_Impl.java | 23 +- .../test/nolistener/{ => impl}/Car_Impl.java | 60 ++--- .../nolistener/{ => impl}/Circle_Impl.java | 27 +-- .../nolistener/{ => impl}/Group_Impl.java | 50 ++--- .../nolistener/{ => impl}/Rectangle_Impl.java | 29 +-- .../nolistener/{ => impl}/Shape_Impl.java | 25 ++- .../{ => impl}/SimpleType_Impl.java | 25 ++- .../java/test/noreflection/AtomicShape.java | 22 +- .../src/test/java/test/noreflection/Car.java | 40 ++-- .../test/java/test/noreflection/Circle.java | 18 +- .../test/java/test/noreflection/Group.java | 34 +-- .../java/test/noreflection/Rectangle.java | 20 +- .../test/java/test/noreflection/Shape.java | 20 +- .../java/test/noreflection/SimpleType.java | 14 +- .../test/java/test/nothing/AtomicShape.java | 4 +- .../java/test/nothing/AtomicShape_Impl.java | 27 --- .../src/test/java/test/nothing/Car.java | 22 +- .../src/test/java/test/nothing/Circle.java | 12 +- .../src/test/java/test/nothing/Group.java | 18 +- .../test/java/test/nothing/Group_Impl.java | 65 ------ .../src/test/java/test/nothing/Rectangle.java | 14 +- .../src/test/java/test/nothing/Shape.java | 4 +- .../test/java/test/nothing/SimpleType.java | 10 +- .../test/nothing/impl/AtomicShape_Impl.java | 27 +++ .../test/nothing/{ => impl}/Car_Impl.java | 36 +-- .../test/nothing/{ => impl}/Circle_Impl.java | 14 +- .../java/test/nothing/impl/Group_Impl.java | 65 ++++++ .../nothing/{ => impl}/Rectangle_Impl.java | 16 +- .../test/nothing/{ => impl}/Shape_Impl.java | 10 +- .../nothing/{ => impl}/SimpleType_Impl.java | 12 +- .../java/test/notypekind/AtomicShape.java | 28 +-- .../test/notypekind/AtomicShape_Impl.java | 83 ------- .../src/test/java/test/notypekind/Car.java | 36 +-- .../src/test/java/test/notypekind/Circle.java | 26 +-- .../src/test/java/test/notypekind/Group.java | 32 +-- .../test/java/test/notypekind/Rectangle.java | 28 +-- .../src/test/java/test/notypekind/Shape.java | 40 ++-- .../test/java/test/notypekind/SimpleType.java | 26 +-- .../impl}/AtomicShape_Impl.java | 23 +- .../test/notypekind/{ => impl}/Car_Impl.java | 60 ++--- .../notypekind/{ => impl}/Circle_Impl.java | 27 +-- .../notypekind/{ => impl}/Group_Impl.java | 54 ++--- .../notypekind/{ => impl}/Rectangle_Impl.java | 29 +-- .../impl}/Shape_Impl.java | 32 ++- .../impl}/SimpleType_Impl.java | 29 +-- .../test/java/test/novisit/AtomicShape.java | 18 +- .../java/test/novisit/AtomicShape_Impl.java | 78 ------- .../src/test/java/test/novisit/Car.java | 36 +-- .../src/test/java/test/novisit/Circle.java | 26 +-- .../src/test/java/test/novisit/Group.java | 32 +-- .../src/test/java/test/novisit/Rectangle.java | 28 +-- .../src/test/java/test/novisit/Shape.java | 38 ++-- .../test/java/test/novisit/SimpleType.java | 26 +-- .../impl}/AtomicShape_Impl.java | 19 +- .../test/novisit/{ => impl}/Car_Impl.java | 58 ++--- .../impl}/Circle_Impl.java | 30 ++- .../test/novisit/{ => impl}/Group_Impl.java | 52 ++--- .../impl}/Rectangle_Impl.java | 32 ++- .../impl}/Shape_Impl.java | 29 +-- .../novisit/{ => impl}/SimpleType_Impl.java | 29 +-- .../test/novisitexceptions/AtomicShape.java | 28 +-- .../test/java/test/novisitexceptions/Car.java | 36 +-- .../java/test/novisitexceptions/Circle.java | 26 +-- .../java/test/novisitexceptions/Group.java | 32 +-- .../test/novisitexceptions/Rectangle.java | 28 +-- .../java/test/novisitexceptions/Shape.java | 50 ++--- .../test/novisitexceptions/SimpleType.java | 26 +-- .../impl/AtomicShape_Impl.java | 84 +++++++ .../{ => impl}/Car_Impl.java | 60 ++--- .../impl}/Circle_Impl.java | 30 ++- .../{ => impl}/Group_Impl.java | 54 ++--- .../impl}/Rectangle_Impl.java | 35 ++- .../impl}/Shape_Impl.java | 32 +-- .../{ => impl}/SimpleType_Impl.java | 29 +-- .../test/nullable/data/NullableValues.java | 42 ++-- .../data/{ => impl}/NullableValues_Impl.java | 51 ++--- .../test/oneoffield/data/SampleMessage.java | 22 +- .../data/{ => impl}/SampleMessage_Impl.java | 23 +- .../java/test/onlyxml/data/AtomicShape.java | 6 +- .../src/test/java/test/onlyxml/data/Car.java | 24 +- .../test/java/test/onlyxml/data/Circle.java | 14 +- .../test/java/test/onlyxml/data/Group.java | 20 +- .../test/java/test/onlyxml/data/Optional.java | 18 +- .../java/test/onlyxml/data/Rectangle.java | 16 +- .../test/java/test/onlyxml/data/Shape.java | 6 +- .../java/test/onlyxml/data/SimpleType.java | 12 +- .../data/impl}/AtomicShape_Impl.java | 24 +- .../onlyxml/data/{ => impl}/Car_Impl.java | 46 ++-- .../onlyxml/data/{ => impl}/Circle_Impl.java | 19 +- .../onlyxml/data/{ => impl}/Group_Impl.java | 54 ++--- .../data/{ => impl}/Optional_Impl.java | 48 ++-- .../data/{ => impl}/Rectangle_Impl.java | 21 +- .../onlyxml/data/{ => impl}/Shape_Impl.java | 25 ++- .../data/{ => impl}/SimpleType_Impl.java | 17 +- .../java/test/options/data/MyMessage1.java | 22 +- .../java/test/options/data/MyMessage2.java | 22 +- .../data/{ => impl}/MyMessage1_Impl.java | 23 +- .../data/{ => impl}/MyMessage2_Impl.java | 23 +- .../src/test/java/test/references/data/A.java | 64 +++--- .../src/test/java/test/references/data/B.java | 28 +-- .../references/data/{ => impl}/A_Impl.java | 212 +++++++++--------- .../references/data/{ => impl}/B_Impl.java | 70 +++--- .../java/test/types/data/SearchRequest.java | 28 +-- .../data/impl}/SearchRequest_Impl.java | 35 ++- .../test/underscorename/AnnotatedMessage.java | 22 +- .../java/test/underscorename/BaseMsg.java | 36 +-- .../java/test/underscorename/SomeName.java | 22 +- .../{ => impl}/AnnotatedMessage_Impl.java | 23 +- .../{ => impl}/BaseMsg_Impl.java | 19 +- .../{ => impl}/SomeName_Impl.java | 23 +- 190 files changed, 3369 insertions(+), 3274 deletions(-) rename de.haumacher.msgbuf.generator/src/test/java/test/{types/data => comments/data/impl}/SearchRequest_Impl.java (85%) rename de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/{ => impl}/SearchRequest_Impl.java (83%) rename de.haumacher.msgbuf.generator/src/test/java/test/{nolistener => graph/data/impl}/AtomicShape_Impl.java (62%) rename de.haumacher.msgbuf.generator/src/test/java/test/graph/data/{ => impl}/Car_Impl.java (75%) rename de.haumacher.msgbuf.generator/src/test/java/test/graph/data/{ => impl}/Circle_Impl.java (82%) rename de.haumacher.msgbuf.generator/src/test/java/test/graph/data/{ => impl}/Group_Impl.java (74%) rename de.haumacher.msgbuf.generator/src/test/java/test/graph/data/{ => impl}/Rectangle_Impl.java (84%) rename de.haumacher.msgbuf.generator/src/test/java/test/graph/data/{ => impl}/Shape_Impl.java (87%) rename de.haumacher.msgbuf.generator/src/test/java/test/graph/data/{ => impl}/SimpleType_Impl.java (89%) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/AtomicShape_Impl.java rename de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/{ => impl}/Car_Impl.java (71%) rename de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/{ => impl}/Circle_Impl.java (76%) rename de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/{ => impl}/Group_Impl.java (62%) rename de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/{ => impl}/Optional_Impl.java (68%) rename de.haumacher.msgbuf.generator/src/test/java/test/{novisit => hierarchy/data/impl}/Rectangle_Impl.java (77%) rename de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/{ => impl}/Shape_Impl.java (84%) rename de.haumacher.msgbuf.generator/src/test/java/test/{notypekind => hierarchy/data/impl}/SimpleType_Impl.java (84%) rename de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/{ => impl}/A_Impl.java (80%) rename de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/{ => impl}/B_Impl.java (80%) rename de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/{ => impl}/A_Impl.java (79%) rename de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/{ => impl}/MyMessage_Impl.java (82%) rename de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/{ => impl}/Project_Impl.java (85%) rename de.haumacher.msgbuf.generator/src/test/java/test/nested/data/{ => impl}/SearchResponse_Impl.java (81%) rename de.haumacher.msgbuf.generator/src/test/java/test/{hierarchy/data => nojson/impl}/AtomicShape_Impl.java (63%) rename de.haumacher.msgbuf.generator/src/test/java/test/nojson/{ => impl}/Car_Impl.java (71%) rename de.haumacher.msgbuf.generator/src/test/java/test/nojson/{ => impl}/Circle_Impl.java (77%) rename de.haumacher.msgbuf.generator/src/test/java/test/nojson/{ => impl}/Group_Impl.java (69%) rename de.haumacher.msgbuf.generator/src/test/java/test/nojson/{ => impl}/Rectangle_Impl.java (79%) rename de.haumacher.msgbuf.generator/src/test/java/test/nojson/{ => impl}/Shape_Impl.java (87%) rename de.haumacher.msgbuf.generator/src/test/java/test/nojson/{ => impl}/SimpleType_Impl.java (85%) rename de.haumacher.msgbuf.generator/src/test/java/test/{graph/data => nolistener/impl}/AtomicShape_Impl.java (62%) rename de.haumacher.msgbuf.generator/src/test/java/test/nolistener/{ => impl}/Car_Impl.java (72%) rename de.haumacher.msgbuf.generator/src/test/java/test/nolistener/{ => impl}/Circle_Impl.java (78%) rename de.haumacher.msgbuf.generator/src/test/java/test/nolistener/{ => impl}/Group_Impl.java (71%) rename de.haumacher.msgbuf.generator/src/test/java/test/nolistener/{ => impl}/Rectangle_Impl.java (80%) rename de.haumacher.msgbuf.generator/src/test/java/test/nolistener/{ => impl}/Shape_Impl.java (88%) rename de.haumacher.msgbuf.generator/src/test/java/test/nolistener/{ => impl}/SimpleType_Impl.java (86%) delete mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nothing/AtomicShape_Impl.java delete mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nothing/Group_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/AtomicShape_Impl.java rename de.haumacher.msgbuf.generator/src/test/java/test/nothing/{ => impl}/Car_Impl.java (53%) rename de.haumacher.msgbuf.generator/src/test/java/test/nothing/{ => impl}/Circle_Impl.java (60%) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Group_Impl.java rename de.haumacher.msgbuf.generator/src/test/java/test/nothing/{ => impl}/Rectangle_Impl.java (66%) rename de.haumacher.msgbuf.generator/src/test/java/test/nothing/{ => impl}/Shape_Impl.java (77%) rename de.haumacher.msgbuf.generator/src/test/java/test/nothing/{ => impl}/SimpleType_Impl.java (72%) delete mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/notypekind/AtomicShape_Impl.java rename de.haumacher.msgbuf.generator/src/test/java/test/{nojson => notypekind/impl}/AtomicShape_Impl.java (62%) rename de.haumacher.msgbuf.generator/src/test/java/test/notypekind/{ => impl}/Car_Impl.java (72%) rename de.haumacher.msgbuf.generator/src/test/java/test/notypekind/{ => impl}/Circle_Impl.java (77%) rename de.haumacher.msgbuf.generator/src/test/java/test/notypekind/{ => impl}/Group_Impl.java (69%) rename de.haumacher.msgbuf.generator/src/test/java/test/notypekind/{ => impl}/Rectangle_Impl.java (80%) rename de.haumacher.msgbuf.generator/src/test/java/test/{novisit => notypekind/impl}/Shape_Impl.java (87%) rename de.haumacher.msgbuf.generator/src/test/java/test/{hierarchy/data => notypekind/impl}/SimpleType_Impl.java (85%) delete mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/novisit/AtomicShape_Impl.java rename de.haumacher.msgbuf.generator/src/test/java/test/{onlyxml/data => novisit/impl}/AtomicShape_Impl.java (68%) rename de.haumacher.msgbuf.generator/src/test/java/test/novisit/{ => impl}/Car_Impl.java (74%) rename de.haumacher.msgbuf.generator/src/test/java/test/{novisitexceptions => novisit/impl}/Circle_Impl.java (80%) rename de.haumacher.msgbuf.generator/src/test/java/test/novisit/{ => impl}/Group_Impl.java (71%) rename de.haumacher.msgbuf.generator/src/test/java/test/{novisitexceptions => novisit/impl}/Rectangle_Impl.java (82%) rename de.haumacher.msgbuf.generator/src/test/java/test/{novisitexceptions => novisit/impl}/Shape_Impl.java (87%) rename de.haumacher.msgbuf.generator/src/test/java/test/novisit/{ => impl}/SimpleType_Impl.java (85%) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/AtomicShape_Impl.java rename de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/{ => impl}/Car_Impl.java (71%) rename de.haumacher.msgbuf.generator/src/test/java/test/{novisit => novisitexceptions/impl}/Circle_Impl.java (76%) rename de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/{ => impl}/Group_Impl.java (68%) rename de.haumacher.msgbuf.generator/src/test/java/test/{hierarchy/data => novisitexceptions/impl}/Rectangle_Impl.java (79%) rename de.haumacher.msgbuf.generator/src/test/java/test/{notypekind => novisitexceptions/impl}/Shape_Impl.java (85%) rename de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/{ => impl}/SimpleType_Impl.java (84%) rename de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/{ => impl}/NullableValues_Impl.java (89%) rename de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/{ => impl}/SampleMessage_Impl.java (80%) rename de.haumacher.msgbuf.generator/src/test/java/test/{novisitexceptions => onlyxml/data/impl}/AtomicShape_Impl.java (67%) rename de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/{ => impl}/Car_Impl.java (67%) rename de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/{ => impl}/Circle_Impl.java (75%) rename de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/{ => impl}/Group_Impl.java (57%) rename de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/{ => impl}/Optional_Impl.java (62%) rename de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/{ => impl}/Rectangle_Impl.java (78%) rename de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/{ => impl}/Shape_Impl.java (82%) rename de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/{ => impl}/SimpleType_Impl.java (86%) rename de.haumacher.msgbuf.generator/src/test/java/test/options/data/{ => impl}/MyMessage1_Impl.java (81%) rename de.haumacher.msgbuf.generator/src/test/java/test/options/data/{ => impl}/MyMessage2_Impl.java (81%) rename de.haumacher.msgbuf.generator/src/test/java/test/references/data/{ => impl}/A_Impl.java (69%) rename de.haumacher.msgbuf.generator/src/test/java/test/references/data/{ => impl}/B_Impl.java (75%) rename de.haumacher.msgbuf.generator/src/test/java/test/{comments/data => types/data/impl}/SearchRequest_Impl.java (86%) rename de.haumacher.msgbuf.generator/src/test/java/test/underscorename/{ => impl}/AnnotatedMessage_Impl.java (78%) rename de.haumacher.msgbuf.generator/src/test/java/test/underscorename/{ => impl}/BaseMsg_Impl.java (84%) rename de.haumacher.msgbuf.generator/src/test/java/test/underscorename/{ => impl}/SomeName_Impl.java (78%) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/AbstractMessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/AbstractMessageGenerator.java index a3a20a98..291729e8 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/AbstractMessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/AbstractMessageGenerator.java @@ -23,12 +23,22 @@ public abstract class AbstractMessageGenerator extends AbstractJavaGenerator { protected final boolean _noInterfaces; + protected final String _packageSuffix; + /** * Creates a {@link AbstractMessageGenerator}. */ - public AbstractMessageGenerator(Map options) { + public AbstractMessageGenerator(Map options, String packageSuffix) { _options = options; _noInterfaces = isTrue(options.get("NoInterfaces"), false); + _packageSuffix = packageSuffix; + } + + /** + * Creates a {@link AbstractMessageGenerator} that does not create top-level file contents. + */ + protected AbstractMessageGenerator(Map options) { + this(options, null); } public Map getOptions() { @@ -51,7 +61,7 @@ protected String qImplName(MessageDef def) { if (_noInterfaces) { return qTypeName(def); } else { - return CodeConvention.qImplName(def); + return CodeConvention.qImplName(CodeConvention.IMPL_PACKAGE_SUFFIX, def); } } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java index 0dd91dfa..42bdc020 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java @@ -39,22 +39,22 @@ public static String qTypeName(CustomType def) { } public static String qTypeName(Definition def) { - return qName(def, CodeConvention::typeName); + return qName(null, def, CodeConvention::typeName); } - public static String qImplName(Definition def) { - return qName(def, CodeConvention::implName); + public static String qImplName(String packageSuffix, Definition def) { + return qName(packageSuffix, def, CodeConvention::implName); } - public static String qName(Definition def, Function localNameConvention) { + public static String qName(String packageSuffix, Definition def, Function localNameConvention) { String scope; DefinitionFile file = def.getFile(); if (file == null) { - scope = qName(def.getOuter(), localNameConvention) + "."; + scope = qName(packageSuffix, def.getOuter(), localNameConvention) + "."; } else { QName pkg = file.getPackage(); - scope = pkg.getNames().size() == 0 ? "" : qName(pkg) + "."; + scope = pkg.getNames().size() == 0 ? (packageSuffix == null ? "" : packageSuffix + ".") : qName(pkg) + "." + (packageSuffix == null ? "" : packageSuffix + "."); } return scope + localNameConvention.apply(def.getName()); @@ -258,4 +258,9 @@ public static String classifierName(Constant constant) { */ public static final String ENUM_PROTOCOL_NAME_FUN = "protocolName"; + /** + * The sub-package where to place implementations. + */ + public static final String IMPL_PACKAGE_SUFFIX = "impl"; + } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java index b88ff1bd..2b3eb9a1 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java @@ -191,20 +191,30 @@ public PackageGenerator(File dir, Map options, GeneratorPlugin p @Override public Void visit(EnumDef def, Void arg) { - return generateJava(CodeConvention.typeName(def), new EnumGenerator(def)); + return generateJava(CodeConvention.typeName(def), null, new EnumGenerator(def)); } @Override public Void visit(MessageDef def, Void arg) { boolean noInterfaces = MessageGenerator.isTrue(_options.get("NoInterfaces"), false); if (!noInterfaces) { - generateJava(CodeConvention.typeName(def), new MessageGenerator(_table, _options, true, def, _plugin)); + generateJava(CodeConvention.typeName(def), null, new MessageGenerator(_table, _options, true, null, def, _plugin)); } - return generateJava(noInterfaces ? CodeConvention.typeName(def) : CodeConvention.implName(def), new MessageGenerator(_table, _options, false, def, _plugin)); + String packageSuffix = noInterfaces ? null : CodeConvention.IMPL_PACKAGE_SUFFIX; + return generateJava(noInterfaces ? CodeConvention.typeName(def) : CodeConvention.implName(def), packageSuffix, new MessageGenerator(_table, _options, false, packageSuffix, def, _plugin)); } - private Void generateJava(String name, FileGenerator generator) { - File out = new File(_dir, name + ".java"); + private Void generateJava(String name, String packageSuffix, FileGenerator generator) { + File dir = _dir; + if (packageSuffix != null) { + // Delete legacy file. + File old = new File(_dir, name + ".java"); + old.delete(); + + dir = new File(dir, packageSuffix); + } + dir.mkdirs(); + File out = new File(dir, name + ".java"); try (FileOutputStream os = new FileOutputStream(out)) { try (PrintWriter w = new PrintWriter(new OutputStreamWriter(os, "utf-8"))) { System.out.println("Generating '" + out + "'."); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 7ed51e5b..6cb3d76e 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -56,9 +56,10 @@ public class MessageGenerator extends AbstractMessageGenerator implements Defini /** * Creates a {@link MessageGenerator}. + * @param packageSuffix */ - public MessageGenerator(NameTable table, Map options, boolean isInterface, MessageDef def, GeneratorPlugin plugin) { - super(options); + public MessageGenerator(NameTable table, Map options, boolean isInterface, String packageSuffix, MessageDef def, GeneratorPlugin plugin) { + super(options, packageSuffix); _table = table; _options = options; _interface = isInterface; @@ -122,7 +123,7 @@ protected void generate() { if (_def.getFile() != null) { QName packageName = _def.getFile().getPackage(); if (packageName != null) { - line("package " + packageName(packageName) + ";"); + line("package " + packageName(packageName) + (_packageSuffix == null ? "" : "." + _packageSuffix) + ";"); nl(); } modifier = ""; @@ -130,7 +131,7 @@ protected void generate() { modifier = _interface ? "" : "static"; } docComment(_def.getComment()); - line((_interface || _noInterfaces ? "public" : ""), modifier, mkAbstract(), (_interface ? "interface" : "class"), (_interface || _noInterfaces ? typeName(_def) : implName(_def)), getExtends(), getImplements(), "{"); + line("public", modifier, mkAbstract(), (_interface ? "interface" : "class"), (_interface || _noInterfaces ? typeName(_def) : implName(_def)), getExtends(), getImplements(), "{"); generateClassContents(); nl(); line("}"); @@ -155,7 +156,7 @@ private String getExtends() { } } } else { - generalizations.add(_interface || _noInterfaces ? qTypeName(_def.getExtends()) : implName(_def.getExtendedDef())); + generalizations.add(_interface || _noInterfaces ? qTypeName(_def.getExtends()) : qImplName(_def.getExtendedDef())); } if (_interface) { @@ -180,7 +181,7 @@ private String getImplements() { } addMixins(generalizations); } else { - generalizations.add(typeName(_def)); + generalizations.add(qTypeName(_def)); } return generalizationList("implements", generalizations); @@ -308,11 +309,11 @@ private void generateClassContents() { private void generateTypeCodeEnum() { if (!_def.getSpecializations().isEmpty() && _def == getRoot(_def)) { nl(); - line("/** Type codes for the {@link " + typeName(_def) + "} hierarchy. */"); + line("/** Type codes for the {@link " + qTypeName(_def) + "} hierarchy. */"); line("public enum " + TYPE_KIND_NAME + " {"); for (MessageDef caseDef : concreteSpecializations(_def)) { nl(); - line("/** Type literal for {@link " + typeName(caseDef) + "}. */"); + line("/** Type literal for {@link " + qTypeName(caseDef) + "}. */"); line(typeKindConstant(caseDef) + ","); } line(";"); @@ -324,7 +325,7 @@ private void generateTypeCodeEnum() { private void generateVisitorInterface() { if (_def.isAbstract()) { nl(); - line("/** Visitor interface for the {@link " + typeName(_def) + "} hierarchy.*/"); + line("/** Visitor interface for the {@link " + qTypeName(_def) + "} hierarchy.*/"); lineStart("public interface Visitor"); boolean first = true; for (MessageDef specialization : _def.getSpecializations()) { @@ -337,7 +338,7 @@ private void generateVisitorInterface() { } else { append(", "); } - append(typeName(specialization) + ".Visitor"); + append(qTypeName(specialization) + ".Visitor"); } append(" {"); nl(); @@ -349,8 +350,8 @@ private void generateVisitorInterface() { } nl(); - line("/** Visit case for {@link " + typeName(specialization) + "}.*/"); - line("R visit(" + typeName(specialization) + " self, A arg)" + onVisitEx(" throws E") + ";"); + line("/** Visit case for {@link " + qTypeName(specialization) + "}.*/"); + line("R visit(" + qTypeName(specialization) + " self, A arg)" + onVisitEx(" throws E") + ";"); hasCase = true; } @@ -381,7 +382,7 @@ public Void visit(EnumDef def, Void arg) { @Override public Void visit(MessageDef def, Void arg) { - include(new MessageGenerator(_table, _options, _interface, def, _plugin)); + include(new MessageGenerator(_table, _options, _interface, _packageSuffix, def, _plugin)); return null; } @@ -389,9 +390,9 @@ private void generateFactoryMethod() { if (!_def.isAbstract()) { nl(); line("/**"); - line(" * Creates a {@link " + typeName(_def) + "} instance."); + line(" * Creates a {@link " + qTypeName(_def) + "} instance."); line(" */"); - line((_noInterfaces ? "public " : "") + "static " + typeName(_def) + " " + factoryName(_def) + "() {"); + line((_noInterfaces ? "public " : "") + "static " + qTypeName(_def) + " " + factoryName(_def) + "() {"); { line("return new " + qImplName(_def) + "();"); } @@ -403,7 +404,7 @@ private void generateConstants() { if (_interface || _noInterfaces) { if ((_json || _reflection) && !_def.isAbstract()) { nl(); - line("/** Identifier for the {@link " + typeName(_def) + "} type in JSON format. */"); + line("/** Identifier for the {@link " + qTypeName(_def) + "} type in JSON format. */"); line((_noInterfaces ? "public " : "") + "static final String " + jsonTypeConstant(_def) + " = " + jsonTypeID(_def) + ";"); } } @@ -426,7 +427,7 @@ private void generateConstants() { if (_binary && (_interface || _noInterfaces)) { if (!_def.isAbstract() && getRoot(_def).isAbstract()) { nl(); - line("/** Identifier for the {@link " + typeName(_def) + "} type in binary format. */"); + line("/** Identifier for the {@link " + qTypeName(_def) + "} type in binary format. */"); line("static final int " + mkBinaryTypeConstant(_def) + " = " + _def.getId() + ";"); } @@ -452,10 +453,10 @@ private void generateConstructor() { line(" * Creates a {@link " + implName(_def) + "} instance."); if (!_def.isAbstract()) { line(" *"); - line(" * @see " + typeName(_def) + "#" + factoryName(_def) + "()"); + line(" * @see " + qTypeName(_def) + "#" + factoryName(_def) + "()"); } line(" */"); - line("protected " + implName(_def) + "() {"); + line((_noInterfaces ? "protected " : "public ") + implName(_def) + "() {"); { line("super();"); } @@ -1042,7 +1043,7 @@ private void reflectionGet() { // To complicated to select the correct super type. line("default: return null;"); } else { - line("default: return " + typeName(_def) + ".super.get(field);"); + line("default: return " + qTypeName(_def) + ".super.get(field);"); } } else { line("default: return super.get(field);"); @@ -1098,7 +1099,7 @@ private void generateJson() { line("switch (type) {"); for (MessageDef specialization : Util.concreteTransitiveSpecializations(_def)) { if (_graph) { - line("case " + jsonTypeConstantRef(specialization) + ": result = " + typeName(specialization) + ".create(); break;"); + line("case " + jsonTypeConstantRef(specialization) + ": result = " + qTypeName(specialization) + ".create(); break;"); } else { line("case " + jsonTypeConstantRef(specialization) + ": result = " + qTypeName(specialization) + "." + readerName(specialization) + "(in); break;"); } @@ -1515,7 +1516,7 @@ private void binaryTypeId() { } private void typeIdDoc() { - line("/** The binary identifier for this concrete type in the polymorphic {@link " + typeName(_def) + "} hierarchy. */"); + line("/** The binary identifier for this concrete type in the polymorphic {@link " + qTypeName(_def) + "} hierarchy. */"); } private void binaryWrite() { @@ -1684,11 +1685,11 @@ private void binaryRead() { } private String thisType() { - return typeName(_def); + return qTypeName(_def); } private String myType() { - return typeName(_def); + return qTypeName(_def); } private void generateChain() { @@ -1765,7 +1766,7 @@ else if (type instanceof CustomType) { } private String mkBinaryTypeConstantRef(MessageDef def) { - return typeName(def) + "." + mkBinaryTypeConstant(def); + return qTypeName(def) + "." + mkBinaryTypeConstant(def); } private String mkBinaryReadValue(Kind kind) { @@ -1873,10 +1874,10 @@ private void generateVisitMethods() { if (!_interface) { nl(); line("@Override"); - line("public" + (_def.isAbstract() ? " final" : "") + " R visit(" + typeName(gen) + ".Visitor v, A arg) " + onVisitEx("throws E ") + "{"); + line("public" + (_def.isAbstract() ? " final" : "") + " R visit(" + qTypeName(gen) + ".Visitor v, A arg) " + onVisitEx("throws E ") + "{"); { if (_def.isAbstract()) { - line("return visit((" + typeName(_def) + ".Visitor) v, arg);"); + line("return visit((" + qTypeName(_def) + ".Visitor) v, arg);"); } else { line("return v.visit(this, arg);"); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/TypeGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/TypeGenerator.java index 458a35a9..4f1004e5 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/TypeGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/TypeGenerator.java @@ -24,16 +24,19 @@ public class TypeGenerator implements Type.Visitor { /** * Singleton {@link TypeGenerator} instance. */ - public static final TypeGenerator INSTANCE = new TypeGenerator(CodeConvention::typeName); + public static final TypeGenerator INSTANCE = new TypeGenerator(null, CodeConvention::typeName); /** * Singleton {@link TypeGenerator} instance. */ - public static final TypeGenerator IMPL_INSTANCE = new TypeGenerator(CodeConvention::implName); + public static final TypeGenerator IMPL_INSTANCE = new TypeGenerator(CodeConvention.IMPL_PACKAGE_SUFFIX, CodeConvention::implName); private Function _typeNameConvention; - private TypeGenerator(Function typeNameConvention) { + private String _packageSuffix; + + private TypeGenerator(String packageSuffix, Function typeNameConvention) { + _packageSuffix = packageSuffix; _typeNameConvention = typeNameConvention; } @@ -72,7 +75,7 @@ public String visit(MapType type, Boolean wrapped) { @Override public String visit(CustomType type, Boolean wrapped) { - return qName(type.getName(), _typeNameConvention); + return qName(_packageSuffix, type.getDefinition(), _typeNameConvention); } @Override diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java index 212ffb3f..27fb53b9 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java @@ -82,7 +82,7 @@ public FileGenerator messageImplContents(Map options, MessageDef @Override protected void generate() { nl(); - line("/** XML element name representing a {@link " + typeName(def) + "} type. */"); + line("/** XML element name representing a {@link " + qTypeName(def) + "} type. */"); line("public static final String " + xmlTypeNameConstant(def) + " = \"" + xmlTypeName(def) + "\";"); for (Field field : def.getFields()) { @@ -140,7 +140,8 @@ protected void generate() { if (def.hasExtends()) { line("super.writeElements(out);"); } - + + boolean hasElementFields = false; for (Field field : def.getFields()) { Type type = field.getType(); switch (type.kind()) { @@ -154,6 +155,7 @@ protected void generate() { continue; } + hasElementFields = true; boolean nullable = Util.isNullable(field); if (nullable) { line("if (" + CodeConvention.hasName(field) + "()" + ") {"); @@ -183,11 +185,15 @@ protected void generate() { } } } + + if (!hasElementFields) { + line("// No element fields."); + } } line("}"); nl(); - line("/** Creates a new {@link " + typeName(def) + "} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */"); + line("/** Creates a new {@link " + qTypeName(def) + "} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */"); line("public static " + implName(def) + " " + readXmlContent(def) + "(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException {"); { if (def.isAbstract()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java index c06d6c3f..0e43b6bb 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java @@ -7,13 +7,13 @@ public interface SearchRequest extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link SearchRequest} instance. + * Creates a {@link test.comments.data.SearchRequest} instance. */ - static SearchRequest create() { - return new test.comments.data.SearchRequest_Impl(); + static test.comments.data.SearchRequest create() { + return new test.comments.data.impl.SearchRequest_Impl(); } - /** Identifier for the {@link SearchRequest} type in JSON format. */ + /** Identifier for the {@link test.comments.data.SearchRequest} type in JSON format. */ static final String SEARCH_REQUEST__TYPE = "SearchRequest"; /** @see #getQuery() */ @@ -42,7 +42,7 @@ static SearchRequest create() { /** * @see #getQuery() */ - SearchRequest setQuery(String value); + test.comments.data.SearchRequest setQuery(String value); /** * The page of results to return. @@ -58,7 +58,7 @@ static SearchRequest create() { /** * @see #getPageNumber() */ - SearchRequest setPageNumber(int value); + test.comments.data.SearchRequest setPageNumber(int value); /** * The number of results to return at once. @@ -70,25 +70,25 @@ static SearchRequest create() { /** * @see #getResultPerPage() */ - SearchRequest setResultPerPage(int value); + test.comments.data.SearchRequest setResultPerPage(int value); @Override - public SearchRequest registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.comments.data.SearchRequest registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public SearchRequest unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.comments.data.SearchRequest unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static SearchRequest readSearchRequest(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.comments.data.SearchRequest_Impl result = new test.comments.data.SearchRequest_Impl(); + static test.comments.data.SearchRequest readSearchRequest(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.comments.data.impl.SearchRequest_Impl result = new test.comments.data.impl.SearchRequest_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static SearchRequest readSearchRequest(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.comments.data.SearchRequest readSearchRequest(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - SearchRequest result = test.comments.data.SearchRequest_Impl.readSearchRequest_Content(in); + test.comments.data.SearchRequest result = test.comments.data.impl.SearchRequest_Impl.readSearchRequest_Content(in); in.endObject(); return result; } @@ -96,7 +96,7 @@ static SearchRequest readSearchRequest(de.haumacher.msgbuf.binary.DataReader in) /** Creates a new {@link SearchRequest} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SearchRequest readSearchRequest(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.comments.data.SearchRequest_Impl.readSearchRequest_XmlContent(in); + return test.comments.data.impl.SearchRequest_Impl.readSearchRequest_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java similarity index 85% rename from de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java index 7d300582..f838e71a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java @@ -1,6 +1,10 @@ -package test.types.data; +package test.comments.data.impl; -class SearchRequest_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements SearchRequest { +/** + * SearchRequest represents a search query, with {@link #getPageNumber() pagination options} to + * indicate which results to include in the response. + */ +public class SearchRequest_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.comments.data.SearchRequest { private String _query = ""; @@ -11,9 +15,9 @@ class SearchRequest_Impl extends de.haumacher.msgbuf.data.AbstractDataObject imp /** * Creates a {@link SearchRequest_Impl} instance. * - * @see SearchRequest#create() + * @see test.comments.data.SearchRequest#create() */ - protected SearchRequest_Impl() { + public SearchRequest_Impl() { super(); } @@ -23,7 +27,7 @@ public final String getQuery() { } @Override - public SearchRequest setQuery(String value) { + public test.comments.data.SearchRequest setQuery(String value) { internalSetQuery(value); return this; } @@ -40,7 +44,7 @@ public final int getPageNumber() { } @Override - public SearchRequest setPageNumber(int value) { + public test.comments.data.SearchRequest setPageNumber(int value) { internalSetPageNumber(value); return this; } @@ -57,7 +61,7 @@ public final int getResultPerPage() { } @Override - public SearchRequest setResultPerPage(int value) { + public test.comments.data.SearchRequest setResultPerPage(int value) { internalSetResultPerPage(value); return this; } @@ -71,7 +75,7 @@ protected final void internalSetResultPerPage(int value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public SearchRequest registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.comments.data.SearchRequest registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -81,7 +85,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public SearchRequest unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.comments.data.SearchRequest unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -112,7 +116,7 @@ public Object get(String field) { case QUERY__PROP: return getQuery(); case PAGE_NUMBER__PROP: return getPageNumber(); case RESULT_PER_PAGE__PROP: return getResultPerPage(); - default: return SearchRequest.super.get(field); + default: return test.comments.data.SearchRequest.super.get(field); } } @@ -174,9 +178,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getResultPerPage()); } - /** Helper for creating an object of type {@link SearchRequest} from a polymorphic composition. */ - public static SearchRequest readSearchRequest_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.types.data.SearchRequest_Impl result = new SearchRequest_Impl(); + /** Helper for creating an object of type {@link test.comments.data.SearchRequest} from a polymorphic composition. */ + public static test.comments.data.SearchRequest readSearchRequest_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.comments.data.impl.SearchRequest_Impl result = new SearchRequest_Impl(); result.readContent(in); return result; } @@ -199,7 +203,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link SearchRequest} type. */ + /** XML element name representing a {@link test.comments.data.SearchRequest} type. */ public static final String SEARCH_REQUEST__XML_ELEMENT = "search-request"; /** XML attribute or element name of a {@link #getQuery} property. */ @@ -231,9 +235,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link SearchRequest} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.comments.data.SearchRequest} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SearchRequest_Impl readSearchRequest_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SearchRequest_Impl result = new SearchRequest_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java index 697ec3b3..d06e0883 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java @@ -91,13 +91,13 @@ public static Corpus readCorpus(de.haumacher.msgbuf.binary.DataReader in) throws } /** - * Creates a {@link SearchRequest} instance. + * Creates a {@link test.enumeration.data.SearchRequest} instance. */ - static SearchRequest create() { - return new test.enumeration.data.SearchRequest_Impl(); + static test.enumeration.data.SearchRequest create() { + return new test.enumeration.data.impl.SearchRequest_Impl(); } - /** Identifier for the {@link SearchRequest} type in JSON format. */ + /** Identifier for the {@link test.enumeration.data.SearchRequest} type in JSON format. */ static final String SEARCH_REQUEST__TYPE = "SearchRequest"; /** @see #getQuery() */ @@ -129,46 +129,46 @@ static SearchRequest create() { /** * @see #getQuery() */ - SearchRequest setQuery(String value); + test.enumeration.data.SearchRequest setQuery(String value); int getPageNumber(); /** * @see #getPageNumber() */ - SearchRequest setPageNumber(int value); + test.enumeration.data.SearchRequest setPageNumber(int value); int getResultPerPage(); /** * @see #getResultPerPage() */ - SearchRequest setResultPerPage(int value); + test.enumeration.data.SearchRequest setResultPerPage(int value); - Corpus getCorpus(); + test.enumeration.data.SearchRequest.Corpus getCorpus(); /** * @see #getCorpus() */ - SearchRequest setCorpus(Corpus value); + test.enumeration.data.SearchRequest setCorpus(test.enumeration.data.SearchRequest.Corpus value); @Override - public SearchRequest registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.enumeration.data.SearchRequest registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public SearchRequest unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.enumeration.data.SearchRequest unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static SearchRequest readSearchRequest(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.enumeration.data.SearchRequest_Impl result = new test.enumeration.data.SearchRequest_Impl(); + static test.enumeration.data.SearchRequest readSearchRequest(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.enumeration.data.impl.SearchRequest_Impl result = new test.enumeration.data.impl.SearchRequest_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static SearchRequest readSearchRequest(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.enumeration.data.SearchRequest readSearchRequest(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - SearchRequest result = test.enumeration.data.SearchRequest_Impl.readSearchRequest_Content(in); + test.enumeration.data.SearchRequest result = test.enumeration.data.impl.SearchRequest_Impl.readSearchRequest_Content(in); in.endObject(); return result; } @@ -176,7 +176,7 @@ static SearchRequest readSearchRequest(de.haumacher.msgbuf.binary.DataReader in) /** Creates a new {@link SearchRequest} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SearchRequest readSearchRequest(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.enumeration.data.SearchRequest_Impl.readSearchRequest_XmlContent(in); + return test.enumeration.data.impl.SearchRequest_Impl.readSearchRequest_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java similarity index 83% rename from de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java index 51f7f300..d1a395b9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java @@ -1,6 +1,6 @@ -package test.enumeration.data; +package test.enumeration.data.impl; -class SearchRequest_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements SearchRequest { +public class SearchRequest_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.enumeration.data.SearchRequest { private String _query = ""; @@ -8,14 +8,14 @@ class SearchRequest_Impl extends de.haumacher.msgbuf.data.AbstractDataObject imp private int _resultPerPage = 0; - private Corpus _corpus = test.enumeration.data.SearchRequest.Corpus.UNIVERSAL; + private test.enumeration.data.SearchRequest.Corpus _corpus = test.enumeration.data.SearchRequest.Corpus.UNIVERSAL; /** * Creates a {@link SearchRequest_Impl} instance. * - * @see SearchRequest#create() + * @see test.enumeration.data.SearchRequest#create() */ - protected SearchRequest_Impl() { + public SearchRequest_Impl() { super(); } @@ -25,7 +25,7 @@ public final String getQuery() { } @Override - public SearchRequest setQuery(String value) { + public test.enumeration.data.SearchRequest setQuery(String value) { internalSetQuery(value); return this; } @@ -42,7 +42,7 @@ public final int getPageNumber() { } @Override - public SearchRequest setPageNumber(int value) { + public test.enumeration.data.SearchRequest setPageNumber(int value) { internalSetPageNumber(value); return this; } @@ -59,7 +59,7 @@ public final int getResultPerPage() { } @Override - public SearchRequest setResultPerPage(int value) { + public test.enumeration.data.SearchRequest setResultPerPage(int value) { internalSetResultPerPage(value); return this; } @@ -71,18 +71,18 @@ protected final void internalSetResultPerPage(int value) { } @Override - public final Corpus getCorpus() { + public final test.enumeration.data.SearchRequest.Corpus getCorpus() { return _corpus; } @Override - public SearchRequest setCorpus(Corpus value) { + public test.enumeration.data.SearchRequest setCorpus(test.enumeration.data.SearchRequest.Corpus value) { internalSetCorpus(value); return this; } /** Internal setter for {@link #getCorpus()} without chain call utility. */ - protected final void internalSetCorpus(Corpus value) { + protected final void internalSetCorpus(test.enumeration.data.SearchRequest.Corpus value) { if (value == null) throw new IllegalArgumentException("Property 'corpus' cannot be null."); _listener.beforeSet(this, CORPUS__PROP, value); _corpus = value; @@ -91,7 +91,7 @@ protected final void internalSetCorpus(Corpus value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public SearchRequest registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.enumeration.data.SearchRequest registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -101,7 +101,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public SearchRequest unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.enumeration.data.SearchRequest unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -134,7 +134,7 @@ public Object get(String field) { case PAGE_NUMBER__PROP: return getPageNumber(); case RESULT_PER_PAGE__PROP: return getResultPerPage(); case CORPUS__PROP: return getCorpus(); - default: return SearchRequest.super.get(field); + default: return test.enumeration.data.SearchRequest.super.get(field); } } @@ -144,7 +144,7 @@ public void set(String field, Object value) { case QUERY__PROP: internalSetQuery((String) value); break; case PAGE_NUMBER__PROP: internalSetPageNumber((int) value); break; case RESULT_PER_PAGE__PROP: internalSetResultPerPage((int) value); break; - case CORPUS__PROP: internalSetCorpus((Corpus) value); break; + case CORPUS__PROP: internalSetCorpus((test.enumeration.data.SearchRequest.Corpus) value); break; } } @@ -202,9 +202,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav getCorpus().writeTo(out); } - /** Helper for creating an object of type {@link SearchRequest} from a polymorphic composition. */ - public static SearchRequest readSearchRequest_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.enumeration.data.SearchRequest_Impl result = new SearchRequest_Impl(); + /** Helper for creating an object of type {@link test.enumeration.data.SearchRequest} from a polymorphic composition. */ + public static test.enumeration.data.SearchRequest readSearchRequest_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.enumeration.data.impl.SearchRequest_Impl result = new SearchRequest_Impl(); result.readContent(in); return result; } @@ -228,7 +228,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link SearchRequest} type. */ + /** XML element name representing a {@link test.enumeration.data.SearchRequest} type. */ public static final String SEARCH_REQUEST__XML_ELEMENT = "search-request"; /** XML attribute or element name of a {@link #getQuery} property. */ @@ -264,9 +264,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link SearchRequest} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.enumeration.data.SearchRequest} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SearchRequest_Impl readSearchRequest_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SearchRequest_Impl result = new SearchRequest_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/AtomicShape.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/AtomicShape.java index 2ac614a4..0eabc431 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/AtomicShape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/AtomicShape.java @@ -5,35 +5,35 @@ */ public interface AtomicShape extends Shape { - /** Visitor interface for the {@link AtomicShape} hierarchy.*/ + /** Visitor interface for the {@link test.graph.data.AtomicShape} hierarchy.*/ public interface Visitor { - /** Visit case for {@link Circle}.*/ - R visit(Circle self, A arg) throws E; + /** Visit case for {@link test.graph.data.Circle}.*/ + R visit(test.graph.data.Circle self, A arg) throws E; - /** Visit case for {@link Rectangle}.*/ - R visit(Rectangle self, A arg) throws E; + /** Visit case for {@link test.graph.data.Rectangle}.*/ + R visit(test.graph.data.Rectangle self, A arg) throws E; } @Override - AtomicShape setXCoordinate(int value); + test.graph.data.AtomicShape setXCoordinate(int value); @Override - AtomicShape setYCoordinate(int value); + test.graph.data.AtomicShape setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static AtomicShape readAtomicShape(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + static test.graph.data.AtomicShape readAtomicShape(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { if (in.peek() == de.haumacher.msgbuf.json.JsonToken.NUMBER) { - return (AtomicShape) scope.resolveOrFail(in.nextInt()); + return (test.graph.data.AtomicShape) scope.resolveOrFail(in.nextInt()); } - AtomicShape result; + test.graph.data.AtomicShape result; in.beginArray(); String type = in.nextString(); int id = in.nextInt(); switch (type) { - case Circle.CIRCLE__TYPE: result = Circle.create(); break; - case Rectangle.RECTANGLE__TYPE: result = Rectangle.create(); break; + case Circle.CIRCLE__TYPE: result = test.graph.data.Circle.create(); break; + case Rectangle.RECTANGLE__TYPE: result = test.graph.data.Rectangle.create(); break; default: in.skipValue(); result = null; break; } if (result != null) { @@ -46,7 +46,7 @@ static AtomicShape readAtomicShape(de.haumacher.msgbuf.graph.Scope scope, de.hau /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape readAtomicShape(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.graph.data.AtomicShape_Impl.readAtomicShape_XmlContent(in); + return test.graph.data.impl.AtomicShape_Impl.readAtomicShape_XmlContent(in); } /** Accepts the given visitor. */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java index 23d01bb4..f48eb2e5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java @@ -6,13 +6,13 @@ public interface Car extends Shape { /** - * Creates a {@link Car} instance. + * Creates a {@link test.graph.data.Car} instance. */ - static Car create() { - return new test.graph.data.Car_Impl(); + static test.graph.data.Car create() { + return new test.graph.data.impl.Car_Impl(); } - /** Identifier for the {@link Car} type in JSON format. */ + /** Identifier for the {@link test.graph.data.Car} type in JSON format. */ static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ @@ -27,12 +27,12 @@ static Car create() { /** * The front wheel. */ - Circle getWheel1(); + test.graph.data.Circle getWheel1(); /** * @see #getWheel1() */ - Car setWheel1(Circle value); + test.graph.data.Car setWheel1(test.graph.data.Circle value); /** * Checks, whether {@link #getWheel1()} has a value. @@ -42,12 +42,12 @@ static Car create() { /** * The back wheel. */ - Circle getWheel2(); + test.graph.data.Circle getWheel2(); /** * @see #getWheel2() */ - Car setWheel2(Circle value); + test.graph.data.Car setWheel2(test.graph.data.Circle value); /** * Checks, whether {@link #getWheel2()} has a value. @@ -57,12 +57,12 @@ static Car create() { /** * The car body. */ - Rectangle getBody(); + test.graph.data.Rectangle getBody(); /** * @see #getBody() */ - Car setBody(Rectangle value); + test.graph.data.Car setBody(test.graph.data.Rectangle value); /** * Checks, whether {@link #getBody()} has a value. @@ -70,21 +70,21 @@ static Car create() { boolean hasBody(); @Override - Car setXCoordinate(int value); + test.graph.data.Car setXCoordinate(int value); @Override - Car setYCoordinate(int value); + test.graph.data.Car setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Car readCar(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + static test.graph.data.Car readCar(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { if (in.peek() == de.haumacher.msgbuf.json.JsonToken.NUMBER) { - return (Car) scope.resolveOrFail(in.nextInt()); + return (test.graph.data.Car) scope.resolveOrFail(in.nextInt()); } in.beginArray(); String type = in.nextString(); assert CAR__TYPE.equals(type); int id = in.nextInt(); - test.graph.data.Car_Impl result = new test.graph.data.Car_Impl(); + test.graph.data.impl.Car_Impl result = new test.graph.data.impl.Car_Impl(); scope.readData(result, id, in); in.endArray(); return result; @@ -93,7 +93,7 @@ static Car readCar(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.js /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car readCar(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.graph.data.Car_Impl.readCar_XmlContent(in); + return test.graph.data.impl.Car_Impl.readCar_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java index ca741f96..48002eac 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java @@ -6,13 +6,13 @@ public interface Circle extends AtomicShape { /** - * Creates a {@link Circle} instance. + * Creates a {@link test.graph.data.Circle} instance. */ - static Circle create() { - return new test.graph.data.Circle_Impl(); + static test.graph.data.Circle create() { + return new test.graph.data.impl.Circle_Impl(); } - /** Identifier for the {@link Circle} type in JSON format. */ + /** Identifier for the {@link test.graph.data.Circle} type in JSON format. */ static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ @@ -26,24 +26,24 @@ static Circle create() { /** * @see #getRadius() */ - Circle setRadius(int value); + test.graph.data.Circle setRadius(int value); @Override - Circle setXCoordinate(int value); + test.graph.data.Circle setXCoordinate(int value); @Override - Circle setYCoordinate(int value); + test.graph.data.Circle setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Circle readCircle(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + static test.graph.data.Circle readCircle(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { if (in.peek() == de.haumacher.msgbuf.json.JsonToken.NUMBER) { - return (Circle) scope.resolveOrFail(in.nextInt()); + return (test.graph.data.Circle) scope.resolveOrFail(in.nextInt()); } in.beginArray(); String type = in.nextString(); assert CIRCLE__TYPE.equals(type); int id = in.nextInt(); - test.graph.data.Circle_Impl result = new test.graph.data.Circle_Impl(); + test.graph.data.impl.Circle_Impl result = new test.graph.data.impl.Circle_Impl(); scope.readData(result, id, in); in.endArray(); return result; @@ -52,7 +52,7 @@ static Circle readCircle(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msg /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle readCircle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.graph.data.Circle_Impl.readCircle_XmlContent(in); + return test.graph.data.impl.Circle_Impl.readCircle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java index 754d7177..5794c8f6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java @@ -6,13 +6,13 @@ public interface Group extends Shape { /** - * Creates a {@link Group} instance. + * Creates a {@link test.graph.data.Group} instance. */ - static Group create() { - return new test.graph.data.Group_Impl(); + static test.graph.data.Group create() { + return new test.graph.data.impl.Group_Impl(); } - /** Identifier for the {@link Group} type in JSON format. */ + /** Identifier for the {@link test.graph.data.Group} type in JSON format. */ static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ @@ -25,39 +25,39 @@ static Group create() { * The origins of these {@link Shape}s get a coordinate offset of ({@link #getXCoordinate()}, {@link #getYCoordinate()}). *

*/ - java.util.List getShapes(); + java.util.List getShapes(); /** * @see #getShapes() */ - Group setShapes(java.util.List value); + test.graph.data.Group setShapes(java.util.List value); /** * Adds a value to the {@link #getShapes()} list. */ - Group addShape(Shape value); + test.graph.data.Group addShape(test.graph.data.Shape value); /** * Removes a value from the {@link #getShapes()} list. */ - void removeShape(Shape value); + void removeShape(test.graph.data.Shape value); @Override - Group setXCoordinate(int value); + test.graph.data.Group setXCoordinate(int value); @Override - Group setYCoordinate(int value); + test.graph.data.Group setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Group readGroup(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + static test.graph.data.Group readGroup(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { if (in.peek() == de.haumacher.msgbuf.json.JsonToken.NUMBER) { - return (Group) scope.resolveOrFail(in.nextInt()); + return (test.graph.data.Group) scope.resolveOrFail(in.nextInt()); } in.beginArray(); String type = in.nextString(); assert GROUP__TYPE.equals(type); int id = in.nextInt(); - test.graph.data.Group_Impl result = new test.graph.data.Group_Impl(); + test.graph.data.impl.Group_Impl result = new test.graph.data.impl.Group_Impl(); scope.readData(result, id, in); in.endArray(); return result; @@ -66,7 +66,7 @@ static Group readGroup(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbu /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group readGroup(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.graph.data.Group_Impl.readGroup_XmlContent(in); + return test.graph.data.impl.Group_Impl.readGroup_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java index a7c643f2..a16060a9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java @@ -6,13 +6,13 @@ public interface Rectangle extends AtomicShape { /** - * Creates a {@link Rectangle} instance. + * Creates a {@link test.graph.data.Rectangle} instance. */ - static Rectangle create() { - return new test.graph.data.Rectangle_Impl(); + static test.graph.data.Rectangle create() { + return new test.graph.data.impl.Rectangle_Impl(); } - /** Identifier for the {@link Rectangle} type in JSON format. */ + /** Identifier for the {@link test.graph.data.Rectangle} type in JSON format. */ static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ @@ -35,7 +35,7 @@ static Rectangle create() { /** * @see #getWidth() */ - Rectangle setWidth(int value); + test.graph.data.Rectangle setWidth(int value); /** * The width of this {@link Rectangle}. @@ -47,24 +47,24 @@ static Rectangle create() { /** * @see #getHeight() */ - Rectangle setHeight(int value); + test.graph.data.Rectangle setHeight(int value); @Override - Rectangle setXCoordinate(int value); + test.graph.data.Rectangle setXCoordinate(int value); @Override - Rectangle setYCoordinate(int value); + test.graph.data.Rectangle setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Rectangle readRectangle(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + static test.graph.data.Rectangle readRectangle(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { if (in.peek() == de.haumacher.msgbuf.json.JsonToken.NUMBER) { - return (Rectangle) scope.resolveOrFail(in.nextInt()); + return (test.graph.data.Rectangle) scope.resolveOrFail(in.nextInt()); } in.beginArray(); String type = in.nextString(); assert RECTANGLE__TYPE.equals(type); int id = in.nextInt(); - test.graph.data.Rectangle_Impl result = new test.graph.data.Rectangle_Impl(); + test.graph.data.impl.Rectangle_Impl result = new test.graph.data.impl.Rectangle_Impl(); scope.readData(result, id, in); in.endArray(); return result; @@ -73,7 +73,7 @@ static Rectangle readRectangle(de.haumacher.msgbuf.graph.Scope scope, de.haumach /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle readRectangle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.graph.data.Rectangle_Impl.readRectangle_XmlContent(in); + return test.graph.data.impl.Rectangle_Impl.readRectangle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java index 86290181..9d2bfcf3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java @@ -5,32 +5,32 @@ */ public interface Shape extends de.haumacher.msgbuf.graph.SharedGraphNode, de.haumacher.msgbuf.xml.XmlSerializable { - /** Type codes for the {@link Shape} hierarchy. */ + /** Type codes for the {@link test.graph.data.Shape} hierarchy. */ public enum TypeKind { - /** Type literal for {@link Circle}. */ + /** Type literal for {@link test.graph.data.Circle}. */ CIRCLE, - /** Type literal for {@link Rectangle}. */ + /** Type literal for {@link test.graph.data.Rectangle}. */ RECTANGLE, - /** Type literal for {@link Group}. */ + /** Type literal for {@link test.graph.data.Group}. */ GROUP, - /** Type literal for {@link Car}. */ + /** Type literal for {@link test.graph.data.Car}. */ CAR, ; } - /** Visitor interface for the {@link Shape} hierarchy.*/ - public interface Visitor extends AtomicShape.Visitor { + /** Visitor interface for the {@link test.graph.data.Shape} hierarchy.*/ + public interface Visitor extends test.graph.data.AtomicShape.Visitor { - /** Visit case for {@link Group}.*/ - R visit(Group self, A arg) throws E; + /** Visit case for {@link test.graph.data.Group}.*/ + R visit(test.graph.data.Group self, A arg) throws E; - /** Visit case for {@link Car}.*/ - R visit(Car self, A arg) throws E; + /** Visit case for {@link test.graph.data.Car}.*/ + R visit(test.graph.data.Car self, A arg) throws E; } @@ -51,7 +51,7 @@ public interface Visitor extends AtomicShape.Visitor extends AtomicShape.Visitor R visit(Shape.Visitor v, A arg) throws E { - return visit((AtomicShape.Visitor) v, arg); + public final R visit(test.graph.data.Shape.Visitor v, A arg) throws E { + return visit((test.graph.data.AtomicShape.Visitor) v, arg); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java similarity index 75% rename from de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java index f7ebd464..321ebac3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java @@ -1,22 +1,22 @@ -package test.graph.data; +package test.graph.data.impl; /** * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. */ -class Car_Impl extends Shape_Impl implements Car { +public class Car_Impl extends test.graph.data.impl.Shape_Impl implements test.graph.data.Car { - private Circle _wheel1 = null; + private test.graph.data.Circle _wheel1 = null; - private Circle _wheel2 = null; + private test.graph.data.Circle _wheel2 = null; - private Rectangle _body = null; + private test.graph.data.Rectangle _body = null; /** * Creates a {@link Car_Impl} instance. * - * @see Car#create() + * @see test.graph.data.Car#create() */ - protected Car_Impl() { + public Car_Impl() { super(); } @@ -26,18 +26,18 @@ public TypeKind kind() { } @Override - public final Circle getWheel1() { + public final test.graph.data.Circle getWheel1() { return _wheel1; } @Override - public Car setWheel1(Circle value) { + public test.graph.data.Car setWheel1(test.graph.data.Circle value) { internalSetWheel1(value); return this; } /** Internal setter for {@link #getWheel1()} without chain call utility. */ - protected final void internalSetWheel1(Circle value) { + protected final void internalSetWheel1(test.graph.data.Circle value) { _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; } @@ -48,18 +48,18 @@ public final boolean hasWheel1() { } @Override - public final Circle getWheel2() { + public final test.graph.data.Circle getWheel2() { return _wheel2; } @Override - public Car setWheel2(Circle value) { + public test.graph.data.Car setWheel2(test.graph.data.Circle value) { internalSetWheel2(value); return this; } /** Internal setter for {@link #getWheel2()} without chain call utility. */ - protected final void internalSetWheel2(Circle value) { + protected final void internalSetWheel2(test.graph.data.Circle value) { _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; } @@ -70,18 +70,18 @@ public final boolean hasWheel2() { } @Override - public final Rectangle getBody() { + public final test.graph.data.Rectangle getBody() { return _body; } @Override - public Car setBody(Rectangle value) { + public test.graph.data.Car setBody(test.graph.data.Rectangle value) { internalSetBody(value); return this; } /** Internal setter for {@link #getBody()} without chain call utility. */ - protected final void internalSetBody(Rectangle value) { + protected final void internalSetBody(test.graph.data.Rectangle value) { _listener.beforeSet(this, BODY__PROP, value); _body = value; } @@ -92,13 +92,13 @@ public final boolean hasBody() { } @Override - public Car setXCoordinate(int value) { + public test.graph.data.Car setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Car setYCoordinate(int value) { + public test.graph.data.Car setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -132,9 +132,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; - case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; - case BODY__PROP: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((test.graph.data.Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((test.graph.data.Circle) value); break; + case BODY__PROP: internalSetBody((test.graph.data.Rectangle) value); break; default: super.set(field, value); break; } } @@ -197,7 +197,7 @@ public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf } } - /** XML element name representing a {@link Car} type. */ + /** XML element name representing a {@link test.graph.data.Car} type. */ public static final String CAR__XML_ELEMENT = "car"; /** XML attribute or element name of a {@link #getWheel1} property. */ @@ -241,7 +241,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. } } - /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.graph.data.Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); result.readContentXml(in); @@ -261,15 +261,15 @@ protected void readFieldXmlAttribute(String name, String value) { protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { case WHEEL_1__XML_ATTR: { - setWheel1(test.graph.data.Circle_Impl.readCircle_XmlContent(in)); + setWheel1(test.graph.data.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case WHEEL_2__XML_ATTR: { - setWheel2(test.graph.data.Circle_Impl.readCircle_XmlContent(in)); + setWheel2(test.graph.data.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case BODY__XML_ATTR: { - setBody(test.graph.data.Rectangle_Impl.readRectangle_XmlContent(in)); + setBody(test.graph.data.impl.Rectangle_Impl.readRectangle_XmlContent(in)); break; } default: { @@ -279,7 +279,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(Shape.Visitor v, A arg) throws E { + public R visit(test.graph.data.Shape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java similarity index 82% rename from de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java index 811e0380..01b9d1af 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java @@ -1,18 +1,18 @@ -package test.graph.data; +package test.graph.data.impl; /** * A circle {@link Shape}. */ -class Circle_Impl extends AtomicShape_Impl implements Circle { +public class Circle_Impl extends test.graph.data.impl.AtomicShape_Impl implements test.graph.data.Circle { private int _radius = 0; /** * Creates a {@link Circle_Impl} instance. * - * @see Circle#create() + * @see test.graph.data.Circle#create() */ - protected Circle_Impl() { + public Circle_Impl() { super(); } @@ -27,7 +27,7 @@ public final int getRadius() { } @Override - public Circle setRadius(int value) { + public test.graph.data.Circle setRadius(int value) { internalSetRadius(value); return this; } @@ -39,13 +39,13 @@ protected final void internalSetRadius(int value) { } @Override - public Circle setXCoordinate(int value) { + public test.graph.data.Circle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Circle setYCoordinate(int value) { + public test.graph.data.Circle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -106,7 +106,7 @@ public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf } } - /** XML element name representing a {@link Circle} type. */ + /** XML element name representing a {@link test.graph.data.Circle} type. */ public static final String CIRCLE__XML_ELEMENT = "circle"; /** XML attribute or element name of a {@link #getRadius} property. */ @@ -128,9 +128,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.graph.data.Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); result.readContentXml(in); @@ -164,7 +165,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { + public R visit(test.graph.data.AtomicShape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java similarity index 74% rename from de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java index e29e6c93..4af09d5a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java @@ -1,18 +1,18 @@ -package test.graph.data; +package test.graph.data.impl; /** * A group of shapes. */ -class Group_Impl extends Shape_Impl implements Group { +public class Group_Impl extends test.graph.data.impl.Shape_Impl implements test.graph.data.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override - protected void beforeAdd(int index, Shape element) { + protected void beforeAdd(int index, test.graph.data.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); } @Override - protected void afterRemove(int index, Shape element) { + protected void afterRemove(int index, test.graph.data.Shape element) { _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } }; @@ -20,9 +20,9 @@ protected void afterRemove(int index, Shape element) { /** * Creates a {@link Group_Impl} instance. * - * @see Group#create() + * @see test.graph.data.Group#create() */ - protected Group_Impl() { + public Group_Impl() { super(); } @@ -32,47 +32,47 @@ public TypeKind kind() { } @Override - public final java.util.List getShapes() { + public final java.util.List getShapes() { return _shapes; } @Override - public Group setShapes(java.util.List value) { + public test.graph.data.Group setShapes(java.util.List value) { internalSetShapes(value); return this; } /** Internal setter for {@link #getShapes()} without chain call utility. */ - protected final void internalSetShapes(java.util.List value) { + protected final void internalSetShapes(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); _shapes.clear(); _shapes.addAll(value); } @Override - public Group addShape(Shape value) { + public test.graph.data.Group addShape(test.graph.data.Shape value) { internalAddShape(value); return this; } - /** Implementation of {@link #addShape(Shape)} without chain call utility. */ - protected final void internalAddShape(Shape value) { + /** Implementation of {@link #addShape(test.graph.data.Shape)} without chain call utility. */ + protected final void internalAddShape(test.graph.data.Shape value) { _shapes.add(value); } @Override - public final void removeShape(Shape value) { + public final void removeShape(test.graph.data.Shape value) { _shapes.remove(value); } @Override - public Group setXCoordinate(int value) { + public test.graph.data.Group setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Group setYCoordinate(int value) { + public test.graph.data.Group setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -102,7 +102,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(test.graph.data.Shape.class, value)); break; default: super.set(field, value); break; } } @@ -112,7 +112,7 @@ protected void writeFields(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.m super.writeFields(scope, out); out.name(SHAPES__PROP); out.beginArray(); - for (Shape x : getShapes()) { + for (test.graph.data.Shape x : getShapes()) { x.writeTo(scope, out); } out.endArray(); @@ -123,7 +123,7 @@ public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher. switch (field) { case SHAPES__PROP: { out.beginArray(); - for (Shape x : getShapes()) { + for (test.graph.data.Shape x : getShapes()) { x.writeTo(scope, out); } out.endArray(); @@ -152,7 +152,7 @@ public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf public void writeElement(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out, String field, Object element) throws java.io.IOException { switch (field) { case SHAPES__PROP: { - ((Shape) element).writeTo(scope, out); + ((test.graph.data.Shape) element).writeTo(scope, out); break; } default: super.writeElement(scope, out, field, element); @@ -169,7 +169,7 @@ public Object readElement(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.ms } } - /** XML element name representing a {@link Group} type. */ + /** XML element name representing a {@link test.graph.data.Group} type. */ public static final String GROUP__XML_ELEMENT = "group"; /** XML attribute or element name of a {@link #getShapes} property. */ @@ -197,7 +197,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. out.writeEndElement(); } - /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.graph.data.Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); result.readContentXml(in); @@ -233,12 +233,12 @@ private void internalReadShapesListXml(javax.xml.stream.XMLStreamReader in) thro break; } - addShape(test.graph.data.Shape_Impl.readShape_XmlContent(in)); + addShape(test.graph.data.impl.Shape_Impl.readShape_XmlContent(in)); } } @Override - public R visit(Shape.Visitor v, A arg) throws E { + public R visit(test.graph.data.Shape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java similarity index 84% rename from de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java index f0217112..90438389 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java @@ -1,9 +1,9 @@ -package test.graph.data; +package test.graph.data.impl; /** * A rectangle. */ -class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { +public class Rectangle_Impl extends test.graph.data.impl.AtomicShape_Impl implements test.graph.data.Rectangle { private int _width = 0; @@ -12,9 +12,9 @@ class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { /** * Creates a {@link Rectangle_Impl} instance. * - * @see Rectangle#create() + * @see test.graph.data.Rectangle#create() */ - protected Rectangle_Impl() { + public Rectangle_Impl() { super(); } @@ -29,7 +29,7 @@ public final int getWidth() { } @Override - public Rectangle setWidth(int value) { + public test.graph.data.Rectangle setWidth(int value) { internalSetWidth(value); return this; } @@ -46,7 +46,7 @@ public final int getHeight() { } @Override - public Rectangle setHeight(int value) { + public test.graph.data.Rectangle setHeight(int value) { internalSetHeight(value); return this; } @@ -58,13 +58,13 @@ protected final void internalSetHeight(int value) { } @Override - public Rectangle setXCoordinate(int value) { + public test.graph.data.Rectangle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Rectangle setYCoordinate(int value) { + public test.graph.data.Rectangle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -135,7 +135,7 @@ public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf } } - /** XML element name representing a {@link Rectangle} type. */ + /** XML element name representing a {@link test.graph.data.Rectangle} type. */ public static final String RECTANGLE__XML_ELEMENT = "rectangle"; /** XML attribute or element name of a {@link #getWidth} property. */ @@ -161,9 +161,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.graph.data.Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); result.readContentXml(in); @@ -205,7 +206,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { + public R visit(test.graph.data.AtomicShape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java similarity index 87% rename from de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java index fe28aaa9..ccbf5426 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java @@ -1,9 +1,9 @@ -package test.graph.data; +package test.graph.data.impl; /** * An abstract base class for all shapes */ -abstract class Shape_Impl extends de.haumacher.msgbuf.graph.AbstractSharedGraphNode implements Shape { +public abstract class Shape_Impl extends de.haumacher.msgbuf.graph.AbstractSharedGraphNode implements test.graph.data.Shape { private int _xCoordinate = 0; @@ -12,7 +12,7 @@ abstract class Shape_Impl extends de.haumacher.msgbuf.graph.AbstractSharedGraphN /** * Creates a {@link Shape_Impl} instance. */ - protected Shape_Impl() { + public Shape_Impl() { super(); } @@ -25,7 +25,7 @@ public final int getXCoordinate() { } @Override - public Shape setXCoordinate(int value) { + public test.graph.data.Shape setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @@ -42,7 +42,7 @@ public final int getYCoordinate() { } @Override - public Shape setYCoordinate(int value) { + public test.graph.data.Shape setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -113,7 +113,7 @@ public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf } } - /** XML element name representing a {@link Shape} type. */ + /** XML element name representing a {@link test.graph.data.Shape} type. */ public static final String SHAPE__XML_ELEMENT = "shape"; /** XML attribute or element name of a {@link #getXCoordinate} property. */ @@ -136,25 +136,26 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.graph.data.Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { case Circle_Impl.CIRCLE__XML_ELEMENT: { - return test.graph.data.Circle_Impl.readCircle_XmlContent(in); + return test.graph.data.impl.Circle_Impl.readCircle_XmlContent(in); } case Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - return test.graph.data.Rectangle_Impl.readRectangle_XmlContent(in); + return test.graph.data.impl.Rectangle_Impl.readRectangle_XmlContent(in); } case Group_Impl.GROUP__XML_ELEMENT: { - return test.graph.data.Group_Impl.readGroup_XmlContent(in); + return test.graph.data.impl.Group_Impl.readGroup_XmlContent(in); } case Car_Impl.CAR__XML_ELEMENT: { - return test.graph.data.Car_Impl.readCar_XmlContent(in); + return test.graph.data.impl.Car_Impl.readCar_XmlContent(in); } default: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java similarity index 89% rename from de.haumacher.msgbuf.generator/src/test/java/test/graph/data/SimpleType_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java index cdf549b9..d4a5ad2a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java @@ -1,9 +1,9 @@ -package test.graph.data; +package test.graph.data.impl; /** * A concrete type without abstract super type. */ -class SimpleType_Impl extends de.haumacher.msgbuf.graph.AbstractSharedGraphNode implements SimpleType { +public class SimpleType_Impl extends de.haumacher.msgbuf.graph.AbstractSharedGraphNode implements test.graph.data.SimpleType { private String _str = ""; @@ -12,9 +12,9 @@ class SimpleType_Impl extends de.haumacher.msgbuf.graph.AbstractSharedGraphNode /** * Creates a {@link SimpleType_Impl} instance. * - * @see SimpleType#create() + * @see test.graph.data.SimpleType#create() */ - protected SimpleType_Impl() { + public SimpleType_Impl() { super(); } @@ -24,7 +24,7 @@ public final String getStr() { } @Override - public SimpleType setStr(String value) { + public test.graph.data.SimpleType setStr(String value) { internalSetStr(value); return this; } @@ -41,7 +41,7 @@ public final int getX() { } @Override - public SimpleType setX(int value) { + public test.graph.data.SimpleType setX(int value) { internalSetX(value); return this; } @@ -117,7 +117,7 @@ public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf } } - /** XML element name representing a {@link SimpleType} type. */ + /** XML element name representing a {@link test.graph.data.SimpleType} type. */ public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; /** XML attribute or element name of a {@link #getStr} property. */ @@ -145,9 +145,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.graph.data.SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SimpleType_Impl result = new SimpleType_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape.java index dc8060e1..4030e984 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/AtomicShape.java @@ -5,29 +5,29 @@ */ public interface AtomicShape extends Shape { - /** Visitor interface for the {@link AtomicShape} hierarchy.*/ + /** Visitor interface for the {@link test.hierarchy.data.AtomicShape} hierarchy.*/ public interface Visitor { - /** Visit case for {@link Circle}.*/ - R visit(Circle self, A arg) throws E; + /** Visit case for {@link test.hierarchy.data.Circle}.*/ + R visit(test.hierarchy.data.Circle self, A arg) throws E; - /** Visit case for {@link Rectangle}.*/ - R visit(Rectangle self, A arg) throws E; + /** Visit case for {@link test.hierarchy.data.Rectangle}.*/ + R visit(test.hierarchy.data.Rectangle self, A arg) throws E; } @Override - AtomicShape setXCoordinate(int value); + test.hierarchy.data.AtomicShape setXCoordinate(int value); @Override - AtomicShape setYCoordinate(int value); + test.hierarchy.data.AtomicShape setYCoordinate(int value); @Override - AtomicShape setColor(Color value); + test.hierarchy.data.AtomicShape setColor(test.hierarchy.data.Color value); /** Reads a new instance from the given reader. */ - static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - AtomicShape result; + static test.hierarchy.data.AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.hierarchy.data.AtomicShape result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -40,15 +40,15 @@ static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throw } /** Reads a new instance from the given reader. */ - static AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.hierarchy.data.AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); int typeField = in.nextName(); assert typeField == 0; int type = in.nextInt(); - AtomicShape result; + test.hierarchy.data.AtomicShape result; switch (type) { - case Circle.CIRCLE__TYPE_ID: result = test.hierarchy.data.Circle_Impl.readCircle_Content(in); break; - case Rectangle.RECTANGLE__TYPE_ID: result = test.hierarchy.data.Rectangle_Impl.readRectangle_Content(in); break; + case test.hierarchy.data.Circle.CIRCLE__TYPE_ID: result = test.hierarchy.data.impl.Circle_Impl.readCircle_Content(in); break; + case test.hierarchy.data.Rectangle.RECTANGLE__TYPE_ID: result = test.hierarchy.data.impl.Rectangle_Impl.readRectangle_Content(in); break; default: result = null; while (in.hasNext()) {in.skipValue(); } } in.endObject(); @@ -58,7 +58,7 @@ static AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) thr /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape readAtomicShape(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.hierarchy.data.AtomicShape_Impl.readAtomicShape_XmlContent(in); + return test.hierarchy.data.impl.AtomicShape_Impl.readAtomicShape_XmlContent(in); } /** Accepts the given visitor. */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java index 6edeb74c..a5572a6e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java @@ -6,13 +6,13 @@ public interface Car extends Shape { /** - * Creates a {@link Car} instance. + * Creates a {@link test.hierarchy.data.Car} instance. */ - static Car create() { - return new test.hierarchy.data.Car_Impl(); + static test.hierarchy.data.Car create() { + return new test.hierarchy.data.impl.Car_Impl(); } - /** Identifier for the {@link Car} type in JSON format. */ + /** Identifier for the {@link test.hierarchy.data.Car} type in JSON format. */ static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ @@ -24,7 +24,7 @@ static Car create() { /** @see #getBody() */ static final String BODY__PROP = "body"; - /** Identifier for the {@link Car} type in binary format. */ + /** Identifier for the {@link test.hierarchy.data.Car} type in binary format. */ static final int CAR__TYPE_ID = 5; /** Identifier for the property {@link #getWheel1()} in binary format. */ @@ -39,12 +39,12 @@ static Car create() { /** * The front wheel. */ - Circle getWheel1(); + test.hierarchy.data.Circle getWheel1(); /** * @see #getWheel1() */ - Car setWheel1(Circle value); + test.hierarchy.data.Car setWheel1(test.hierarchy.data.Circle value); /** * Checks, whether {@link #getWheel1()} has a value. @@ -54,12 +54,12 @@ static Car create() { /** * The back wheel. */ - Circle getWheel2(); + test.hierarchy.data.Circle getWheel2(); /** * @see #getWheel2() */ - Car setWheel2(Circle value); + test.hierarchy.data.Car setWheel2(test.hierarchy.data.Circle value); /** * Checks, whether {@link #getWheel2()} has a value. @@ -69,12 +69,12 @@ static Car create() { /** * The car body. */ - Rectangle getBody(); + test.hierarchy.data.Rectangle getBody(); /** * @see #getBody() */ - Car setBody(Rectangle value); + test.hierarchy.data.Car setBody(test.hierarchy.data.Rectangle value); /** * Checks, whether {@link #getBody()} has a value. @@ -82,25 +82,25 @@ static Car create() { boolean hasBody(); @Override - Car setXCoordinate(int value); + test.hierarchy.data.Car setXCoordinate(int value); @Override - Car setYCoordinate(int value); + test.hierarchy.data.Car setYCoordinate(int value); @Override - Car setColor(Color value); + test.hierarchy.data.Car setColor(test.hierarchy.data.Color value); /** Reads a new instance from the given reader. */ - static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.hierarchy.data.Car_Impl result = new test.hierarchy.data.Car_Impl(); + static test.hierarchy.data.Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.hierarchy.data.impl.Car_Impl result = new test.hierarchy.data.impl.Car_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.hierarchy.data.Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Car result = test.hierarchy.data.Car_Impl.readCar_Content(in); + test.hierarchy.data.Car result = test.hierarchy.data.impl.Car_Impl.readCar_Content(in); in.endObject(); return result; } @@ -108,7 +108,7 @@ static Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOEx /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car readCar(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.hierarchy.data.Car_Impl.readCar_XmlContent(in); + return test.hierarchy.data.impl.Car_Impl.readCar_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java index b32b9ff0..7d2a80ca 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java @@ -6,19 +6,19 @@ public interface Circle extends AtomicShape { /** - * Creates a {@link Circle} instance. + * Creates a {@link test.hierarchy.data.Circle} instance. */ - static Circle create() { - return new test.hierarchy.data.Circle_Impl(); + static test.hierarchy.data.Circle create() { + return new test.hierarchy.data.impl.Circle_Impl(); } - /** Identifier for the {@link Circle} type in JSON format. */ + /** Identifier for the {@link test.hierarchy.data.Circle} type in JSON format. */ static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ static final String RADIUS__PROP = "r"; - /** Identifier for the {@link Circle} type in binary format. */ + /** Identifier for the {@link test.hierarchy.data.Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; /** Identifier for the property {@link #getRadius()} in binary format. */ @@ -32,28 +32,28 @@ static Circle create() { /** * @see #getRadius() */ - Circle setRadius(int value); + test.hierarchy.data.Circle setRadius(int value); @Override - Circle setXCoordinate(int value); + test.hierarchy.data.Circle setXCoordinate(int value); @Override - Circle setYCoordinate(int value); + test.hierarchy.data.Circle setYCoordinate(int value); @Override - Circle setColor(Color value); + test.hierarchy.data.Circle setColor(test.hierarchy.data.Color value); /** Reads a new instance from the given reader. */ - static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.hierarchy.data.Circle_Impl result = new test.hierarchy.data.Circle_Impl(); + static test.hierarchy.data.Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.hierarchy.data.impl.Circle_Impl result = new test.hierarchy.data.impl.Circle_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.hierarchy.data.Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Circle result = test.hierarchy.data.Circle_Impl.readCircle_Content(in); + test.hierarchy.data.Circle result = test.hierarchy.data.impl.Circle_Impl.readCircle_Content(in); in.endObject(); return result; } @@ -61,7 +61,7 @@ static Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.i /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle readCircle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.hierarchy.data.Circle_Impl.readCircle_XmlContent(in); + return test.hierarchy.data.impl.Circle_Impl.readCircle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java index dfddb6a9..5873171e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java @@ -6,19 +6,19 @@ public interface Group extends Shape { /** - * Creates a {@link Group} instance. + * Creates a {@link test.hierarchy.data.Group} instance. */ - static Group create() { - return new test.hierarchy.data.Group_Impl(); + static test.hierarchy.data.Group create() { + return new test.hierarchy.data.impl.Group_Impl(); } - /** Identifier for the {@link Group} type in JSON format. */ + /** Identifier for the {@link test.hierarchy.data.Group} type in JSON format. */ static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ static final String SHAPES__PROP = "shapes"; - /** Identifier for the {@link Group} type in binary format. */ + /** Identifier for the {@link test.hierarchy.data.Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; /** Identifier for the property {@link #getShapes()} in binary format. */ @@ -31,43 +31,43 @@ static Group create() { * The origins of these {@link Shape}s get a coordinate offset of ({@link #getXCoordinate()}, {@link #getYCoordinate()}). *

*/ - java.util.List getShapes(); + java.util.List getShapes(); /** * @see #getShapes() */ - Group setShapes(java.util.List value); + test.hierarchy.data.Group setShapes(java.util.List value); /** * Adds a value to the {@link #getShapes()} list. */ - Group addShape(Shape value); + test.hierarchy.data.Group addShape(test.hierarchy.data.Shape value); /** * Removes a value from the {@link #getShapes()} list. */ - void removeShape(Shape value); + void removeShape(test.hierarchy.data.Shape value); @Override - Group setXCoordinate(int value); + test.hierarchy.data.Group setXCoordinate(int value); @Override - Group setYCoordinate(int value); + test.hierarchy.data.Group setYCoordinate(int value); @Override - Group setColor(Color value); + test.hierarchy.data.Group setColor(test.hierarchy.data.Color value); /** Reads a new instance from the given reader. */ - static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.hierarchy.data.Group_Impl result = new test.hierarchy.data.Group_Impl(); + static test.hierarchy.data.Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.hierarchy.data.impl.Group_Impl result = new test.hierarchy.data.impl.Group_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.hierarchy.data.Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Group result = test.hierarchy.data.Group_Impl.readGroup_Content(in); + test.hierarchy.data.Group result = test.hierarchy.data.impl.Group_Impl.readGroup_Content(in); in.endObject(); return result; } @@ -75,7 +75,7 @@ static Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io. /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group readGroup(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.hierarchy.data.Group_Impl.readGroup_XmlContent(in); + return test.hierarchy.data.impl.Group_Impl.readGroup_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java index 038691d1..40205f40 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java @@ -6,13 +6,13 @@ public interface Optional extends Shape { /** - * Creates a {@link Optional} instance. + * Creates a {@link test.hierarchy.data.Optional} instance. */ - static Optional create() { - return new test.hierarchy.data.Optional_Impl(); + static test.hierarchy.data.Optional create() { + return new test.hierarchy.data.impl.Optional_Impl(); } - /** Identifier for the {@link Optional} type in JSON format. */ + /** Identifier for the {@link test.hierarchy.data.Optional} type in JSON format. */ static final String OPTIONAL__TYPE = "Optional"; /** @see #isHidden() */ @@ -21,7 +21,7 @@ static Optional create() { /** @see #getShape() */ static final String SHAPE__PROP = "shape"; - /** Identifier for the {@link Optional} type in binary format. */ + /** Identifier for the {@link test.hierarchy.data.Optional} type in binary format. */ static final int OPTIONAL__TYPE_ID = 4; /** Identifier for the property {@link #isHidden()} in binary format. */ @@ -38,17 +38,17 @@ static Optional create() { /** * @see #isHidden() */ - Optional setHidden(boolean value); + test.hierarchy.data.Optional setHidden(boolean value); /** * A {@link Shape} that can be dynamically hidden.. */ - Shape getShape(); + test.hierarchy.data.Shape getShape(); /** * @see #getShape() */ - Optional setShape(Shape value); + test.hierarchy.data.Optional setShape(test.hierarchy.data.Shape value); /** * Checks, whether {@link #getShape()} has a value. @@ -56,25 +56,25 @@ static Optional create() { boolean hasShape(); @Override - Optional setXCoordinate(int value); + test.hierarchy.data.Optional setXCoordinate(int value); @Override - Optional setYCoordinate(int value); + test.hierarchy.data.Optional setYCoordinate(int value); @Override - Optional setColor(Color value); + test.hierarchy.data.Optional setColor(test.hierarchy.data.Color value); /** Reads a new instance from the given reader. */ - static Optional readOptional(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.hierarchy.data.Optional_Impl result = new test.hierarchy.data.Optional_Impl(); + static test.hierarchy.data.Optional readOptional(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.hierarchy.data.impl.Optional_Impl result = new test.hierarchy.data.impl.Optional_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Optional readOptional(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.hierarchy.data.Optional readOptional(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Optional result = test.hierarchy.data.Optional_Impl.readOptional_Content(in); + test.hierarchy.data.Optional result = test.hierarchy.data.impl.Optional_Impl.readOptional_Content(in); in.endObject(); return result; } @@ -82,7 +82,7 @@ static Optional readOptional(de.haumacher.msgbuf.binary.DataReader in) throws ja /** Creates a new {@link Optional} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Optional readOptional(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.hierarchy.data.Optional_Impl.readOptional_XmlContent(in); + return test.hierarchy.data.impl.Optional_Impl.readOptional_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java index 8a9c71c2..c8d22b31 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java @@ -6,13 +6,13 @@ public interface Rectangle extends AtomicShape { /** - * Creates a {@link Rectangle} instance. + * Creates a {@link test.hierarchy.data.Rectangle} instance. */ - static Rectangle create() { - return new test.hierarchy.data.Rectangle_Impl(); + static test.hierarchy.data.Rectangle create() { + return new test.hierarchy.data.impl.Rectangle_Impl(); } - /** Identifier for the {@link Rectangle} type in JSON format. */ + /** Identifier for the {@link test.hierarchy.data.Rectangle} type in JSON format. */ static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ @@ -21,7 +21,7 @@ static Rectangle create() { /** @see #getHeight() */ static final String HEIGHT__PROP = "h"; - /** Identifier for the {@link Rectangle} type in binary format. */ + /** Identifier for the {@link test.hierarchy.data.Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; /** Identifier for the property {@link #getWidth()} in binary format. */ @@ -44,7 +44,7 @@ static Rectangle create() { /** * @see #getWidth() */ - Rectangle setWidth(int value); + test.hierarchy.data.Rectangle setWidth(int value); /** * The width of this {@link Rectangle}. @@ -56,28 +56,28 @@ static Rectangle create() { /** * @see #getHeight() */ - Rectangle setHeight(int value); + test.hierarchy.data.Rectangle setHeight(int value); @Override - Rectangle setXCoordinate(int value); + test.hierarchy.data.Rectangle setXCoordinate(int value); @Override - Rectangle setYCoordinate(int value); + test.hierarchy.data.Rectangle setYCoordinate(int value); @Override - Rectangle setColor(Color value); + test.hierarchy.data.Rectangle setColor(test.hierarchy.data.Color value); /** Reads a new instance from the given reader. */ - static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.hierarchy.data.Rectangle_Impl result = new test.hierarchy.data.Rectangle_Impl(); + static test.hierarchy.data.Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.hierarchy.data.impl.Rectangle_Impl result = new test.hierarchy.data.impl.Rectangle_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.hierarchy.data.Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Rectangle result = test.hierarchy.data.Rectangle_Impl.readRectangle_Content(in); + test.hierarchy.data.Rectangle result = test.hierarchy.data.impl.Rectangle_Impl.readRectangle_Content(in); in.endObject(); return result; } @@ -85,7 +85,7 @@ static Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle readRectangle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.hierarchy.data.Rectangle_Impl.readRectangle_XmlContent(in); + return test.hierarchy.data.impl.Rectangle_Impl.readRectangle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java index 5b3efd11..57711305 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java @@ -5,38 +5,38 @@ */ public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { - /** Type codes for the {@link Shape} hierarchy. */ + /** Type codes for the {@link test.hierarchy.data.Shape} hierarchy. */ public enum TypeKind { - /** Type literal for {@link Circle}. */ + /** Type literal for {@link test.hierarchy.data.Circle}. */ CIRCLE, - /** Type literal for {@link Rectangle}. */ + /** Type literal for {@link test.hierarchy.data.Rectangle}. */ RECTANGLE, - /** Type literal for {@link Group}. */ + /** Type literal for {@link test.hierarchy.data.Group}. */ GROUP, - /** Type literal for {@link Optional}. */ + /** Type literal for {@link test.hierarchy.data.Optional}. */ OPTIONAL, - /** Type literal for {@link Car}. */ + /** Type literal for {@link test.hierarchy.data.Car}. */ CAR, ; } - /** Visitor interface for the {@link Shape} hierarchy.*/ - public interface Visitor extends AtomicShape.Visitor { + /** Visitor interface for the {@link test.hierarchy.data.Shape} hierarchy.*/ + public interface Visitor extends test.hierarchy.data.AtomicShape.Visitor { - /** Visit case for {@link Group}.*/ - R visit(Group self, A arg) throws E; + /** Visit case for {@link test.hierarchy.data.Group}.*/ + R visit(test.hierarchy.data.Group self, A arg) throws E; - /** Visit case for {@link Optional}.*/ - R visit(Optional self, A arg) throws E; + /** Visit case for {@link test.hierarchy.data.Optional}.*/ + R visit(test.hierarchy.data.Optional self, A arg) throws E; - /** Visit case for {@link Car}.*/ - R visit(Car self, A arg) throws E; + /** Visit case for {@link test.hierarchy.data.Car}.*/ + R visit(test.hierarchy.data.Car self, A arg) throws E; } @@ -69,7 +69,7 @@ public interface Visitor extends AtomicShape.Visitor extends AtomicShape.Visitor R visit(test.hierarchy.data.Shape.Visitor v, A arg) throws E { + return visit((test.hierarchy.data.AtomicShape.Visitor) v, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java similarity index 71% rename from de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java index cf9c97c9..4c7ee58e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java @@ -1,22 +1,22 @@ -package test.hierarchy.data; +package test.hierarchy.data.impl; /** * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. */ -class Car_Impl extends Shape_Impl implements Car { +public class Car_Impl extends test.hierarchy.data.impl.Shape_Impl implements test.hierarchy.data.Car { - private Circle _wheel1 = null; + private test.hierarchy.data.Circle _wheel1 = null; - private Circle _wheel2 = null; + private test.hierarchy.data.Circle _wheel2 = null; - private Rectangle _body = null; + private test.hierarchy.data.Rectangle _body = null; /** * Creates a {@link Car_Impl} instance. * - * @see Car#create() + * @see test.hierarchy.data.Car#create() */ - protected Car_Impl() { + public Car_Impl() { super(); } @@ -26,18 +26,18 @@ public TypeKind kind() { } @Override - public final Circle getWheel1() { + public final test.hierarchy.data.Circle getWheel1() { return _wheel1; } @Override - public Car setWheel1(Circle value) { + public test.hierarchy.data.Car setWheel1(test.hierarchy.data.Circle value) { internalSetWheel1(value); return this; } /** Internal setter for {@link #getWheel1()} without chain call utility. */ - protected final void internalSetWheel1(Circle value) { + protected final void internalSetWheel1(test.hierarchy.data.Circle value) { _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; } @@ -48,18 +48,18 @@ public final boolean hasWheel1() { } @Override - public final Circle getWheel2() { + public final test.hierarchy.data.Circle getWheel2() { return _wheel2; } @Override - public Car setWheel2(Circle value) { + public test.hierarchy.data.Car setWheel2(test.hierarchy.data.Circle value) { internalSetWheel2(value); return this; } /** Internal setter for {@link #getWheel2()} without chain call utility. */ - protected final void internalSetWheel2(Circle value) { + protected final void internalSetWheel2(test.hierarchy.data.Circle value) { _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; } @@ -70,18 +70,18 @@ public final boolean hasWheel2() { } @Override - public final Rectangle getBody() { + public final test.hierarchy.data.Rectangle getBody() { return _body; } @Override - public Car setBody(Rectangle value) { + public test.hierarchy.data.Car setBody(test.hierarchy.data.Rectangle value) { internalSetBody(value); return this; } /** Internal setter for {@link #getBody()} without chain call utility. */ - protected final void internalSetBody(Rectangle value) { + protected final void internalSetBody(test.hierarchy.data.Rectangle value) { _listener.beforeSet(this, BODY__PROP, value); _body = value; } @@ -92,19 +92,19 @@ public final boolean hasBody() { } @Override - public Car setXCoordinate(int value) { + public test.hierarchy.data.Car setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Car setYCoordinate(int value) { + public test.hierarchy.data.Car setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @Override - public Car setColor(Color value) { + public test.hierarchy.data.Car setColor(test.hierarchy.data.Color value) { internalSetColor(value); return this; } @@ -138,9 +138,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; - case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; - case BODY__PROP: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((test.hierarchy.data.Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((test.hierarchy.data.Circle) value); break; + case BODY__PROP: internalSetBody((test.hierarchy.data.Rectangle) value); break; default: super.set(field, value); break; } } @@ -194,9 +194,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } } - /** Helper for creating an object of type {@link Car} from a polymorphic composition. */ - public static Car readCar_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.hierarchy.data.Car_Impl result = new Car_Impl(); + /** Helper for creating an object of type {@link test.hierarchy.data.Car} from a polymorphic composition. */ + public static test.hierarchy.data.Car readCar_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.hierarchy.data.impl.Car_Impl result = new Car_Impl(); result.readContent(in); return result; } @@ -211,7 +211,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Car} type. */ + /** XML element name representing a {@link test.hierarchy.data.Car} type. */ public static final String CAR__XML_ELEMENT = "car"; /** XML attribute or element name of a {@link #getWheel1} property. */ @@ -255,7 +255,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. } } - /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.hierarchy.data.Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); result.readContentXml(in); @@ -275,15 +275,15 @@ protected void readFieldXmlAttribute(String name, String value) { protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { case WHEEL_1__XML_ATTR: { - setWheel1(test.hierarchy.data.Circle_Impl.readCircle_XmlContent(in)); + setWheel1(test.hierarchy.data.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case WHEEL_2__XML_ATTR: { - setWheel2(test.hierarchy.data.Circle_Impl.readCircle_XmlContent(in)); + setWheel2(test.hierarchy.data.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case BODY__XML_ATTR: { - setBody(test.hierarchy.data.Rectangle_Impl.readRectangle_XmlContent(in)); + setBody(test.hierarchy.data.impl.Rectangle_Impl.readRectangle_XmlContent(in)); break; } default: { @@ -293,7 +293,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(Shape.Visitor v, A arg) throws E { + public R visit(test.hierarchy.data.Shape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java similarity index 76% rename from de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java index 48606990..a9ad8679 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java @@ -1,18 +1,18 @@ -package test.hierarchy.data; +package test.hierarchy.data.impl; /** * A circle {@link Shape}. */ -class Circle_Impl extends AtomicShape_Impl implements Circle { +public class Circle_Impl extends test.hierarchy.data.impl.AtomicShape_Impl implements test.hierarchy.data.Circle { private int _radius = 0; /** * Creates a {@link Circle_Impl} instance. * - * @see Circle#create() + * @see test.hierarchy.data.Circle#create() */ - protected Circle_Impl() { + public Circle_Impl() { super(); } @@ -27,7 +27,7 @@ public final int getRadius() { } @Override - public Circle setRadius(int value) { + public test.hierarchy.data.Circle setRadius(int value) { internalSetRadius(value); return this; } @@ -39,19 +39,19 @@ protected final void internalSetRadius(int value) { } @Override - public Circle setXCoordinate(int value) { + public test.hierarchy.data.Circle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Circle setYCoordinate(int value) { + public test.hierarchy.data.Circle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @Override - public Circle setColor(Color value) { + public test.hierarchy.data.Circle setColor(test.hierarchy.data.Color value) { internalSetColor(value); return this; } @@ -113,9 +113,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getRadius()); } - /** Helper for creating an object of type {@link Circle} from a polymorphic composition. */ - public static Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.hierarchy.data.Circle_Impl result = new Circle_Impl(); + /** Helper for creating an object of type {@link test.hierarchy.data.Circle} from a polymorphic composition. */ + public static test.hierarchy.data.Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.hierarchy.data.impl.Circle_Impl result = new Circle_Impl(); result.readContent(in); return result; } @@ -128,7 +128,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Circle} type. */ + /** XML element name representing a {@link test.hierarchy.data.Circle} type. */ public static final String CIRCLE__XML_ELEMENT = "circle"; /** XML attribute or element name of a {@link #getRadius} property. */ @@ -150,9 +150,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.hierarchy.data.Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); result.readContentXml(in); @@ -186,7 +187,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { + public R visit(test.hierarchy.data.AtomicShape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java similarity index 62% rename from de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java index cedd5d0b..80072c80 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java @@ -1,18 +1,18 @@ -package test.hierarchy.data; +package test.hierarchy.data.impl; /** * A group of shapes. */ -class Group_Impl extends Shape_Impl implements Group { +public class Group_Impl extends test.hierarchy.data.impl.Shape_Impl implements test.hierarchy.data.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override - protected void beforeAdd(int index, Shape element) { + protected void beforeAdd(int index, test.hierarchy.data.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); } @Override - protected void afterRemove(int index, Shape element) { + protected void afterRemove(int index, test.hierarchy.data.Shape element) { _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } }; @@ -20,9 +20,9 @@ protected void afterRemove(int index, Shape element) { /** * Creates a {@link Group_Impl} instance. * - * @see Group#create() + * @see test.hierarchy.data.Group#create() */ - protected Group_Impl() { + public Group_Impl() { super(); } @@ -32,53 +32,53 @@ public TypeKind kind() { } @Override - public final java.util.List getShapes() { + public final java.util.List getShapes() { return _shapes; } @Override - public Group setShapes(java.util.List value) { + public test.hierarchy.data.Group setShapes(java.util.List value) { internalSetShapes(value); return this; } /** Internal setter for {@link #getShapes()} without chain call utility. */ - protected final void internalSetShapes(java.util.List value) { + protected final void internalSetShapes(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); _shapes.clear(); _shapes.addAll(value); } @Override - public Group addShape(Shape value) { + public test.hierarchy.data.Group addShape(test.hierarchy.data.Shape value) { internalAddShape(value); return this; } - /** Implementation of {@link #addShape(Shape)} without chain call utility. */ - protected final void internalAddShape(Shape value) { + /** Implementation of {@link #addShape(test.hierarchy.data.Shape)} without chain call utility. */ + protected final void internalAddShape(test.hierarchy.data.Shape value) { _shapes.add(value); } @Override - public final void removeShape(Shape value) { + public final void removeShape(test.hierarchy.data.Shape value) { _shapes.remove(value); } @Override - public Group setXCoordinate(int value) { + public test.hierarchy.data.Group setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Group setYCoordinate(int value) { + public test.hierarchy.data.Group setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @Override - public Group setColor(Color value) { + public test.hierarchy.data.Group setColor(test.hierarchy.data.Color value) { internalSetColor(value); return this; } @@ -108,7 +108,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(test.hierarchy.data.Shape.class, value)); break; default: super.set(field, value); break; } } @@ -118,7 +118,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. super.writeFields(out); out.name(SHAPES__PROP); out.beginArray(); - for (Shape x : getShapes()) { + for (test.hierarchy.data.Shape x : getShapes()) { x.writeTo(out); } out.endArray(); @@ -149,18 +149,18 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav super.writeFields(out); out.name(SHAPES__ID); { - java.util.List values = getShapes(); + java.util.List values = getShapes(); out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); - for (Shape x : values) { + for (test.hierarchy.data.Shape x : values) { x.writeTo(out); } out.endArray(); } } - /** Helper for creating an object of type {@link Group} from a polymorphic composition. */ - public static Group readGroup_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.hierarchy.data.Group_Impl result = new Group_Impl(); + /** Helper for creating an object of type {@link test.hierarchy.data.Group} from a polymorphic composition. */ + public static test.hierarchy.data.Group readGroup_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.hierarchy.data.impl.Group_Impl result = new Group_Impl(); result.readContent(in); return result; } @@ -180,7 +180,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Group} type. */ + /** XML element name representing a {@link test.hierarchy.data.Group} type. */ public static final String GROUP__XML_ELEMENT = "group"; /** XML attribute or element name of a {@link #getShapes} property. */ @@ -208,7 +208,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. out.writeEndElement(); } - /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.hierarchy.data.Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); result.readContentXml(in); @@ -227,24 +227,24 @@ protected void readFieldXmlAttribute(String name, String value) { @Override protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { - case test.hierarchy.data.Circle_Impl.CIRCLE__XML_ELEMENT: { - addShape(test.hierarchy.data.Circle_Impl.readCircle_XmlContent(in)); + case test.hierarchy.data.impl.Circle_Impl.CIRCLE__XML_ELEMENT: { + addShape(test.hierarchy.data.impl.Circle_Impl.readCircle_XmlContent(in)); break; } - case test.hierarchy.data.Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - addShape(test.hierarchy.data.Rectangle_Impl.readRectangle_XmlContent(in)); + case test.hierarchy.data.impl.Rectangle_Impl.RECTANGLE__XML_ELEMENT: { + addShape(test.hierarchy.data.impl.Rectangle_Impl.readRectangle_XmlContent(in)); break; } - case test.hierarchy.data.Group_Impl.GROUP__XML_ELEMENT: { - addShape(test.hierarchy.data.Group_Impl.readGroup_XmlContent(in)); + case test.hierarchy.data.impl.Group_Impl.GROUP__XML_ELEMENT: { + addShape(test.hierarchy.data.impl.Group_Impl.readGroup_XmlContent(in)); break; } - case test.hierarchy.data.Optional_Impl.OPTIONAL__XML_ELEMENT: { - addShape(test.hierarchy.data.Optional_Impl.readOptional_XmlContent(in)); + case test.hierarchy.data.impl.Optional_Impl.OPTIONAL__XML_ELEMENT: { + addShape(test.hierarchy.data.impl.Optional_Impl.readOptional_XmlContent(in)); break; } - case test.hierarchy.data.Car_Impl.CAR__XML_ELEMENT: { - addShape(test.hierarchy.data.Car_Impl.readCar_XmlContent(in)); + case test.hierarchy.data.impl.Car_Impl.CAR__XML_ELEMENT: { + addShape(test.hierarchy.data.impl.Car_Impl.readCar_XmlContent(in)); break; } case SHAPES__XML_ATTR: { @@ -264,12 +264,12 @@ private void internalReadShapesListXml(javax.xml.stream.XMLStreamReader in) thro break; } - addShape(test.hierarchy.data.Shape_Impl.readShape_XmlContent(in)); + addShape(test.hierarchy.data.impl.Shape_Impl.readShape_XmlContent(in)); } } @Override - public R visit(Shape.Visitor v, A arg) throws E { + public R visit(test.hierarchy.data.Shape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java similarity index 68% rename from de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java index 4209d530..10b1ed9c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java @@ -1,20 +1,20 @@ -package test.hierarchy.data; +package test.hierarchy.data.impl; /** * A shape that can be dynamically hidden. */ -class Optional_Impl extends Shape_Impl implements Optional { +public class Optional_Impl extends test.hierarchy.data.impl.Shape_Impl implements test.hierarchy.data.Optional { private boolean _hidden = false; - private Shape _shape = null; + private test.hierarchy.data.Shape _shape = null; /** * Creates a {@link Optional_Impl} instance. * - * @see Optional#create() + * @see test.hierarchy.data.Optional#create() */ - protected Optional_Impl() { + public Optional_Impl() { super(); } @@ -29,7 +29,7 @@ public final boolean isHidden() { } @Override - public Optional setHidden(boolean value) { + public test.hierarchy.data.Optional setHidden(boolean value) { internalSetHidden(value); return this; } @@ -41,18 +41,18 @@ protected final void internalSetHidden(boolean value) { } @Override - public final Shape getShape() { + public final test.hierarchy.data.Shape getShape() { return _shape; } @Override - public Optional setShape(Shape value) { + public test.hierarchy.data.Optional setShape(test.hierarchy.data.Shape value) { internalSetShape(value); return this; } /** Internal setter for {@link #getShape()} without chain call utility. */ - protected final void internalSetShape(Shape value) { + protected final void internalSetShape(test.hierarchy.data.Shape value) { _listener.beforeSet(this, SHAPE__PROP, value); _shape = value; } @@ -63,19 +63,19 @@ public final boolean hasShape() { } @Override - public Optional setXCoordinate(int value) { + public test.hierarchy.data.Optional setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Optional setYCoordinate(int value) { + public test.hierarchy.data.Optional setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @Override - public Optional setColor(Color value) { + public test.hierarchy.data.Optional setColor(test.hierarchy.data.Color value) { internalSetColor(value); return this; } @@ -108,7 +108,7 @@ public Object get(String field) { public void set(String field, Object value) { switch (field) { case HIDDEN__PROP: internalSetHidden((boolean) value); break; - case SHAPE__PROP: internalSetShape((Shape) value); break; + case SHAPE__PROP: internalSetShape((test.hierarchy.data.Shape) value); break; default: super.set(field, value); break; } } @@ -149,9 +149,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } } - /** Helper for creating an object of type {@link Optional} from a polymorphic composition. */ - public static Optional readOptional_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.hierarchy.data.Optional_Impl result = new Optional_Impl(); + /** Helper for creating an object of type {@link test.hierarchy.data.Optional} from a polymorphic composition. */ + public static test.hierarchy.data.Optional readOptional_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.hierarchy.data.impl.Optional_Impl result = new Optional_Impl(); result.readContent(in); return result; } @@ -165,7 +165,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Optional} type. */ + /** XML element name representing a {@link test.hierarchy.data.Optional} type. */ public static final String OPTIONAL__XML_ELEMENT = "optional"; /** XML attribute or element name of a {@link #isHidden} property. */ @@ -197,7 +197,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. } } - /** Creates a new {@link Optional} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.hierarchy.data.Optional} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Optional_Impl readOptional_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Optional_Impl result = new Optional_Impl(); result.readContentXml(in); @@ -224,29 +224,29 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l setHidden(Boolean.parseBoolean(in.getElementText())); break; } - case test.hierarchy.data.Circle_Impl.CIRCLE__XML_ELEMENT: { - setShape(test.hierarchy.data.Circle_Impl.readCircle_XmlContent(in)); + case test.hierarchy.data.impl.Circle_Impl.CIRCLE__XML_ELEMENT: { + setShape(test.hierarchy.data.impl.Circle_Impl.readCircle_XmlContent(in)); break; } - case test.hierarchy.data.Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - setShape(test.hierarchy.data.Rectangle_Impl.readRectangle_XmlContent(in)); + case test.hierarchy.data.impl.Rectangle_Impl.RECTANGLE__XML_ELEMENT: { + setShape(test.hierarchy.data.impl.Rectangle_Impl.readRectangle_XmlContent(in)); break; } - case test.hierarchy.data.Group_Impl.GROUP__XML_ELEMENT: { - setShape(test.hierarchy.data.Group_Impl.readGroup_XmlContent(in)); + case test.hierarchy.data.impl.Group_Impl.GROUP__XML_ELEMENT: { + setShape(test.hierarchy.data.impl.Group_Impl.readGroup_XmlContent(in)); break; } - case test.hierarchy.data.Optional_Impl.OPTIONAL__XML_ELEMENT: { - setShape(test.hierarchy.data.Optional_Impl.readOptional_XmlContent(in)); + case test.hierarchy.data.impl.Optional_Impl.OPTIONAL__XML_ELEMENT: { + setShape(test.hierarchy.data.impl.Optional_Impl.readOptional_XmlContent(in)); break; } - case test.hierarchy.data.Car_Impl.CAR__XML_ELEMENT: { - setShape(test.hierarchy.data.Car_Impl.readCar_XmlContent(in)); + case test.hierarchy.data.impl.Car_Impl.CAR__XML_ELEMENT: { + setShape(test.hierarchy.data.impl.Car_Impl.readCar_XmlContent(in)); break; } case SHAPE__XML_ATTR: { in.nextTag(); - setShape(test.hierarchy.data.Shape_Impl.readShape_XmlContent(in)); + setShape(test.hierarchy.data.impl.Shape_Impl.readShape_XmlContent(in)); internalSkipUntilMatchingEndElement(in); break; } @@ -257,7 +257,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(Shape.Visitor v, A arg) throws E { + public R visit(test.hierarchy.data.Shape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java similarity index 77% rename from de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java index e1b53215..d7ed4e34 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java @@ -1,9 +1,9 @@ -package test.novisit; +package test.hierarchy.data.impl; /** * A rectangle. */ -class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { +public class Rectangle_Impl extends test.hierarchy.data.impl.AtomicShape_Impl implements test.hierarchy.data.Rectangle { private int _width = 0; @@ -12,9 +12,9 @@ class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { /** * Creates a {@link Rectangle_Impl} instance. * - * @see Rectangle#create() + * @see test.hierarchy.data.Rectangle#create() */ - protected Rectangle_Impl() { + public Rectangle_Impl() { super(); } @@ -29,7 +29,7 @@ public final int getWidth() { } @Override - public Rectangle setWidth(int value) { + public test.hierarchy.data.Rectangle setWidth(int value) { internalSetWidth(value); return this; } @@ -46,7 +46,7 @@ public final int getHeight() { } @Override - public Rectangle setHeight(int value) { + public test.hierarchy.data.Rectangle setHeight(int value) { internalSetHeight(value); return this; } @@ -58,17 +58,23 @@ protected final void internalSetHeight(int value) { } @Override - public Rectangle setXCoordinate(int value) { + public test.hierarchy.data.Rectangle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Rectangle setYCoordinate(int value) { + public test.hierarchy.data.Rectangle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } + @Override + public test.hierarchy.data.Rectangle setColor(test.hierarchy.data.Color value) { + internalSetColor(value); + return this; + } + @Override public String jsonType() { return RECTANGLE__TYPE; @@ -134,9 +140,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getHeight()); } - /** Helper for creating an object of type {@link Rectangle} from a polymorphic composition. */ - public static Rectangle readRectangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.novisit.Rectangle_Impl result = new Rectangle_Impl(); + /** Helper for creating an object of type {@link test.hierarchy.data.Rectangle} from a polymorphic composition. */ + public static test.hierarchy.data.Rectangle readRectangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.hierarchy.data.impl.Rectangle_Impl result = new Rectangle_Impl(); result.readContent(in); return result; } @@ -150,7 +156,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Rectangle} type. */ + /** XML element name representing a {@link test.hierarchy.data.Rectangle} type. */ public static final String RECTANGLE__XML_ELEMENT = "rectangle"; /** XML attribute or element name of a {@link #getWidth} property. */ @@ -176,9 +182,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.hierarchy.data.Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); result.readContentXml(in); @@ -219,4 +226,9 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } } + @Override + public R visit(test.hierarchy.data.AtomicShape.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java similarity index 84% rename from de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java index b6a7660f..4ac5b1d6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java @@ -1,20 +1,20 @@ -package test.hierarchy.data; +package test.hierarchy.data.impl; /** * An abstract base class for all shapes */ -abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements Shape { +public abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.hierarchy.data.Shape { private int _xCoordinate = 0; private int _yCoordinate = 0; - private Color _color = test.hierarchy.data.Color.RED; + private test.hierarchy.data.Color _color = test.hierarchy.data.Color.RED; /** * Creates a {@link Shape_Impl} instance. */ - protected Shape_Impl() { + public Shape_Impl() { super(); } @@ -27,7 +27,7 @@ public final int getXCoordinate() { } @Override - public Shape setXCoordinate(int value) { + public test.hierarchy.data.Shape setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @@ -44,7 +44,7 @@ public final int getYCoordinate() { } @Override - public Shape setYCoordinate(int value) { + public test.hierarchy.data.Shape setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -56,18 +56,18 @@ protected final void internalSetYCoordinate(int value) { } @Override - public final Color getColor() { + public final test.hierarchy.data.Color getColor() { return _color; } @Override - public Shape setColor(Color value) { + public test.hierarchy.data.Shape setColor(test.hierarchy.data.Color value) { internalSetColor(value); return this; } /** Internal setter for {@link #getColor()} without chain call utility. */ - protected final void internalSetColor(Color value) { + protected final void internalSetColor(test.hierarchy.data.Color value) { if (value == null) throw new IllegalArgumentException("Property 'color' cannot be null."); _listener.beforeSet(this, COLOR__PROP, value); _color = value; @@ -76,7 +76,7 @@ protected final void internalSetColor(Color value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public Shape registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.hierarchy.data.Shape registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -86,7 +86,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.hierarchy.data.Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -112,7 +112,7 @@ public Object get(String field) { case X_COORDINATE__PROP: return getXCoordinate(); case Y_COORDINATE__PROP: return getYCoordinate(); case COLOR__PROP: return getColor(); - default: return Shape.super.get(field); + default: return test.hierarchy.data.Shape.super.get(field); } } @@ -121,7 +121,7 @@ public void set(String field, Object value) { switch (field) { case X_COORDINATE__PROP: internalSetXCoordinate((int) value); break; case Y_COORDINATE__PROP: internalSetYCoordinate((int) value); break; - case COLOR__PROP: internalSetColor((Color) value); break; + case COLOR__PROP: internalSetColor((test.hierarchy.data.Color) value); break; } } @@ -197,7 +197,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Shape} type. */ + /** XML element name representing a {@link test.hierarchy.data.Shape} type. */ public static final String SHAPE__XML_ELEMENT = "shape"; /** XML attribute or element name of a {@link #getXCoordinate} property. */ @@ -224,29 +224,30 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.hierarchy.data.Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { case Circle_Impl.CIRCLE__XML_ELEMENT: { - return test.hierarchy.data.Circle_Impl.readCircle_XmlContent(in); + return test.hierarchy.data.impl.Circle_Impl.readCircle_XmlContent(in); } case Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - return test.hierarchy.data.Rectangle_Impl.readRectangle_XmlContent(in); + return test.hierarchy.data.impl.Rectangle_Impl.readRectangle_XmlContent(in); } case Group_Impl.GROUP__XML_ELEMENT: { - return test.hierarchy.data.Group_Impl.readGroup_XmlContent(in); + return test.hierarchy.data.impl.Group_Impl.readGroup_XmlContent(in); } case Optional_Impl.OPTIONAL__XML_ELEMENT: { - return test.hierarchy.data.Optional_Impl.readOptional_XmlContent(in); + return test.hierarchy.data.impl.Optional_Impl.readOptional_XmlContent(in); } case Car_Impl.CAR__XML_ELEMENT: { - return test.hierarchy.data.Car_Impl.readCar_XmlContent(in); + return test.hierarchy.data.impl.Car_Impl.readCar_XmlContent(in); } default: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java similarity index 84% rename from de.haumacher.msgbuf.generator/src/test/java/test/notypekind/SimpleType_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java index 5bdeab16..f38cfdbe 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java @@ -1,9 +1,9 @@ -package test.notypekind; +package test.hierarchy.data.impl; /** * A concrete type without abstract super type. */ -class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements SimpleType { +public class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.hierarchy.data.SimpleType { private String _str = ""; @@ -12,9 +12,9 @@ class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implem /** * Creates a {@link SimpleType_Impl} instance. * - * @see SimpleType#create() + * @see test.hierarchy.data.SimpleType#create() */ - protected SimpleType_Impl() { + public SimpleType_Impl() { super(); } @@ -24,7 +24,7 @@ public final String getStr() { } @Override - public SimpleType setStr(String value) { + public test.hierarchy.data.SimpleType setStr(String value) { internalSetStr(value); return this; } @@ -41,7 +41,7 @@ public final int getX() { } @Override - public SimpleType setX(int value) { + public test.hierarchy.data.SimpleType setX(int value) { internalSetX(value); return this; } @@ -55,7 +55,7 @@ protected final void internalSetX(int value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.hierarchy.data.SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -65,7 +65,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.hierarchy.data.SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -94,7 +94,7 @@ public Object get(String field) { switch (field) { case STR__PROP: return getStr(); case X__PROP: return getX(); - default: return SimpleType.super.get(field); + default: return test.hierarchy.data.SimpleType.super.get(field); } } @@ -150,9 +150,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getX()); } - /** Helper for creating an object of type {@link SimpleType} from a polymorphic composition. */ - public static SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.notypekind.SimpleType_Impl result = new SimpleType_Impl(); + /** Helper for creating an object of type {@link test.hierarchy.data.SimpleType} from a polymorphic composition. */ + public static test.hierarchy.data.SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.hierarchy.data.impl.SimpleType_Impl result = new SimpleType_Impl(); result.readContent(in); return result; } @@ -174,7 +174,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link SimpleType} type. */ + /** XML element name representing a {@link test.hierarchy.data.SimpleType} type. */ public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; /** XML attribute or element name of a {@link #getStr} property. */ @@ -202,9 +202,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.hierarchy.data.SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SimpleType_Impl result = new SimpleType_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java index d545c99f..09e5424c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java @@ -4,32 +4,32 @@ public interface A extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msg public interface C extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link C} instance. + * Creates a {@link test.innertypeclash.A.C} instance. */ - static C create() { - return new test.innertypeclash.A_Impl.C_Impl(); + static test.innertypeclash.A.C create() { + return new test.innertypeclash.impl.A_Impl.C_Impl(); } - /** Identifier for the {@link C} type in JSON format. */ + /** Identifier for the {@link test.innertypeclash.A.C} type in JSON format. */ static final String C__TYPE = "C"; @Override - public C registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.innertypeclash.A.C registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public C unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.innertypeclash.A.C unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static C readC(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.innertypeclash.A_Impl.C_Impl result = new test.innertypeclash.A_Impl.C_Impl(); + static test.innertypeclash.A.C readC(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.innertypeclash.impl.A_Impl.C_Impl result = new test.innertypeclash.impl.A_Impl.C_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static C readC(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.innertypeclash.A.C readC(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - C result = test.innertypeclash.A_Impl.C_Impl.readC_Content(in); + test.innertypeclash.A.C result = test.innertypeclash.impl.A_Impl.C_Impl.readC_Content(in); in.endObject(); return result; } @@ -37,19 +37,19 @@ static C readC(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOExcept /** Creates a new {@link C} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static C readC(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.innertypeclash.A_Impl.C_Impl.readC_XmlContent(in); + return test.innertypeclash.impl.A_Impl.C_Impl.readC_XmlContent(in); } } /** - * Creates a {@link A} instance. + * Creates a {@link test.innertypeclash.A} instance. */ - static A create() { - return new test.innertypeclash.A_Impl(); + static test.innertypeclash.A create() { + return new test.innertypeclash.impl.A_Impl(); } - /** Identifier for the {@link A} type in JSON format. */ + /** Identifier for the {@link test.innertypeclash.A} type in JSON format. */ static final String A__TYPE = "A"; /** @see #getAc() */ @@ -70,36 +70,36 @@ static A create() { /** Identifier for the property {@link #getC()} in binary format. */ static final int C__ID = 3; - A.C getAc(); + test.innertypeclash.A.C getAc(); /** * @see #getAc() */ - A setAc(A.C value); + test.innertypeclash.A setAc(test.innertypeclash.A.C value); /** * Checks, whether {@link #getAc()} has a value. */ boolean hasAc(); - B.C getBc(); + test.innertypeclash.B.C getBc(); /** * @see #getBc() */ - A setBc(B.C value); + test.innertypeclash.A setBc(test.innertypeclash.B.C value); /** * Checks, whether {@link #getBc()} has a value. */ boolean hasBc(); - C getC(); + test.innertypeclash.A.C getC(); /** * @see #getC() */ - A setC(C value); + test.innertypeclash.A setC(test.innertypeclash.A.C value); /** * Checks, whether {@link #getC()} has a value. @@ -107,22 +107,22 @@ static A create() { boolean hasC(); @Override - public A registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.innertypeclash.A registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public A unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.innertypeclash.A unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static A readA(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.innertypeclash.A_Impl result = new test.innertypeclash.A_Impl(); + static test.innertypeclash.A readA(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.innertypeclash.impl.A_Impl result = new test.innertypeclash.impl.A_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static A readA(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.innertypeclash.A readA(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - A result = test.innertypeclash.A_Impl.readA_Content(in); + test.innertypeclash.A result = test.innertypeclash.impl.A_Impl.readA_Content(in); in.endObject(); return result; } @@ -130,7 +130,7 @@ static A readA(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOExcept /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static A readA(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.innertypeclash.A_Impl.readA_XmlContent(in); + return test.innertypeclash.impl.A_Impl.readA_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java index 4379b64f..619ec4a7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java @@ -4,32 +4,32 @@ public interface B extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msg public interface C extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link C} instance. + * Creates a {@link test.innertypeclash.B.C} instance. */ - static C create() { - return new test.innertypeclash.B_Impl.C_Impl(); + static test.innertypeclash.B.C create() { + return new test.innertypeclash.impl.B_Impl.C_Impl(); } - /** Identifier for the {@link C} type in JSON format. */ + /** Identifier for the {@link test.innertypeclash.B.C} type in JSON format. */ static final String C__TYPE = "C"; @Override - public C registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.innertypeclash.B.C registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public C unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.innertypeclash.B.C unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static C readC(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.innertypeclash.B_Impl.C_Impl result = new test.innertypeclash.B_Impl.C_Impl(); + static test.innertypeclash.B.C readC(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.innertypeclash.impl.B_Impl.C_Impl result = new test.innertypeclash.impl.B_Impl.C_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static C readC(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.innertypeclash.B.C readC(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - C result = test.innertypeclash.B_Impl.C_Impl.readC_Content(in); + test.innertypeclash.B.C result = test.innertypeclash.impl.B_Impl.C_Impl.readC_Content(in); in.endObject(); return result; } @@ -37,19 +37,19 @@ static C readC(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOExcept /** Creates a new {@link C} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static C readC(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.innertypeclash.B_Impl.C_Impl.readC_XmlContent(in); + return test.innertypeclash.impl.B_Impl.C_Impl.readC_XmlContent(in); } } /** - * Creates a {@link B} instance. + * Creates a {@link test.innertypeclash.B} instance. */ - static B create() { - return new test.innertypeclash.B_Impl(); + static test.innertypeclash.B create() { + return new test.innertypeclash.impl.B_Impl(); } - /** Identifier for the {@link B} type in JSON format. */ + /** Identifier for the {@link test.innertypeclash.B} type in JSON format. */ static final String B__TYPE = "B"; /** @see #getAc() */ @@ -70,36 +70,36 @@ static B create() { /** Identifier for the property {@link #getC()} in binary format. */ static final int C__ID = 3; - A.C getAc(); + test.innertypeclash.A.C getAc(); /** * @see #getAc() */ - B setAc(A.C value); + test.innertypeclash.B setAc(test.innertypeclash.A.C value); /** * Checks, whether {@link #getAc()} has a value. */ boolean hasAc(); - B.C getBc(); + test.innertypeclash.B.C getBc(); /** * @see #getBc() */ - B setBc(B.C value); + test.innertypeclash.B setBc(test.innertypeclash.B.C value); /** * Checks, whether {@link #getBc()} has a value. */ boolean hasBc(); - C getC(); + test.innertypeclash.B.C getC(); /** * @see #getC() */ - B setC(C value); + test.innertypeclash.B setC(test.innertypeclash.B.C value); /** * Checks, whether {@link #getC()} has a value. @@ -107,22 +107,22 @@ static B create() { boolean hasC(); @Override - public B registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.innertypeclash.B registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public B unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.innertypeclash.B unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static B readB(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.innertypeclash.B_Impl result = new test.innertypeclash.B_Impl(); + static test.innertypeclash.B readB(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.innertypeclash.impl.B_Impl result = new test.innertypeclash.impl.B_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static B readB(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.innertypeclash.B readB(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - B result = test.innertypeclash.B_Impl.readB_Content(in); + test.innertypeclash.B result = test.innertypeclash.impl.B_Impl.readB_Content(in); in.endObject(); return result; } @@ -130,7 +130,7 @@ static B readB(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOExcept /** Creates a new {@link B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static B readB(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.innertypeclash.B_Impl.readB_XmlContent(in); + return test.innertypeclash.impl.B_Impl.readB_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java similarity index 80% rename from de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java index d69c898f..667e995d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java @@ -1,21 +1,21 @@ -package test.innertypeclash; +package test.innertypeclash.impl; -class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements A { - static class C_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements C { +public class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.innertypeclash.A { + public static class C_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.innertypeclash.A.C { /** * Creates a {@link C_Impl} instance. * - * @see C#create() + * @see test.innertypeclash.A.C#create() */ - protected C_Impl() { + public C_Impl() { super(); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public C registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.innertypeclash.A.C registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -25,7 +25,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public C unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.innertypeclash.A.C unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -62,9 +62,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav // No fields to write, hook for subclasses. } - /** Helper for creating an object of type {@link C} from a polymorphic composition. */ - public static C readC_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.innertypeclash.A_Impl.C_Impl result = new C_Impl(); + /** Helper for creating an object of type {@link test.innertypeclash.A.C} from a polymorphic composition. */ + public static test.innertypeclash.A.C readC_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.innertypeclash.impl.A_Impl.C_Impl result = new C_Impl(); result.readContent(in); return result; } @@ -84,7 +84,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link C} type. */ + /** XML element name representing a {@link test.innertypeclash.A.C} type. */ public static final String C__XML_ELEMENT = "c"; @Override @@ -104,9 +104,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link C} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.innertypeclash.A.C} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static C_Impl readC_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { C_Impl result = new C_Impl(); result.readContentXml(in); @@ -163,34 +164,34 @@ protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream } - private A.C _ac = null; + private test.innertypeclash.A.C _ac = null; - private B.C _bc = null; + private test.innertypeclash.B.C _bc = null; - private C _c = null; + private test.innertypeclash.A.C _c = null; /** * Creates a {@link A_Impl} instance. * - * @see A#create() + * @see test.innertypeclash.A#create() */ - protected A_Impl() { + public A_Impl() { super(); } @Override - public final A.C getAc() { + public final test.innertypeclash.A.C getAc() { return _ac; } @Override - public A setAc(A.C value) { + public test.innertypeclash.A setAc(test.innertypeclash.A.C value) { internalSetAc(value); return this; } /** Internal setter for {@link #getAc()} without chain call utility. */ - protected final void internalSetAc(A.C value) { + protected final void internalSetAc(test.innertypeclash.A.C value) { _listener.beforeSet(this, AC__PROP, value); _ac = value; } @@ -201,18 +202,18 @@ public final boolean hasAc() { } @Override - public final B.C getBc() { + public final test.innertypeclash.B.C getBc() { return _bc; } @Override - public A setBc(B.C value) { + public test.innertypeclash.A setBc(test.innertypeclash.B.C value) { internalSetBc(value); return this; } /** Internal setter for {@link #getBc()} without chain call utility. */ - protected final void internalSetBc(B.C value) { + protected final void internalSetBc(test.innertypeclash.B.C value) { _listener.beforeSet(this, BC__PROP, value); _bc = value; } @@ -223,18 +224,18 @@ public final boolean hasBc() { } @Override - public final C getC() { + public final test.innertypeclash.A.C getC() { return _c; } @Override - public A setC(C value) { + public test.innertypeclash.A setC(test.innertypeclash.A.C value) { internalSetC(value); return this; } /** Internal setter for {@link #getC()} without chain call utility. */ - protected final void internalSetC(C value) { + protected final void internalSetC(test.innertypeclash.A.C value) { _listener.beforeSet(this, C__PROP, value); _c = value; } @@ -247,7 +248,7 @@ public final boolean hasC() { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public A registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.innertypeclash.A registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -257,7 +258,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public A unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.innertypeclash.A unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -288,16 +289,16 @@ public Object get(String field) { case AC__PROP: return getAc(); case BC__PROP: return getBc(); case C__PROP: return getC(); - default: return A.super.get(field); + default: return test.innertypeclash.A.super.get(field); } } @Override public void set(String field, Object value) { switch (field) { - case AC__PROP: internalSetAc((A.C) value); break; - case BC__PROP: internalSetBc((B.C) value); break; - case C__PROP: internalSetC((C) value); break; + case AC__PROP: internalSetAc((test.innertypeclash.A.C) value); break; + case BC__PROP: internalSetBc((test.innertypeclash.B.C) value); break; + case C__PROP: internalSetC((test.innertypeclash.A.C) value); break; } } @@ -362,9 +363,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } } - /** Helper for creating an object of type {@link A} from a polymorphic composition. */ - public static A readA_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.innertypeclash.A_Impl result = new A_Impl(); + /** Helper for creating an object of type {@link test.innertypeclash.A} from a polymorphic composition. */ + public static test.innertypeclash.A readA_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.innertypeclash.impl.A_Impl result = new A_Impl(); result.readContent(in); return result; } @@ -387,7 +388,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link A} type. */ + /** XML element name representing a {@link test.innertypeclash.A} type. */ public static final String A__XML_ELEMENT = "a"; /** XML attribute or element name of a {@link #getAc} property. */ @@ -433,7 +434,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. } } - /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.innertypeclash.A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static A_Impl readA_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { A_Impl result = new A_Impl(); result.readContentXml(in); @@ -473,15 +474,15 @@ protected void readFieldXmlAttribute(String name, String value) { protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { case AC__XML_ATTR: { - setAc(test.innertypeclash.A_Impl.C_Impl.readC_XmlContent(in)); + setAc(test.innertypeclash.impl.A_Impl.C_Impl.readC_XmlContent(in)); break; } case BC__XML_ATTR: { - setBc(test.innertypeclash.B_Impl.C_Impl.readC_XmlContent(in)); + setBc(test.innertypeclash.impl.B_Impl.C_Impl.readC_XmlContent(in)); break; } case C__XML_ATTR: { - setC(test.innertypeclash.A_Impl.C_Impl.readC_XmlContent(in)); + setC(test.innertypeclash.impl.A_Impl.C_Impl.readC_XmlContent(in)); break; } default: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java similarity index 80% rename from de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java index 271f4010..f41ffe1f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java @@ -1,21 +1,21 @@ -package test.innertypeclash; +package test.innertypeclash.impl; -class B_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements B { - static class C_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements C { +public class B_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.innertypeclash.B { + public static class C_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.innertypeclash.B.C { /** * Creates a {@link C_Impl} instance. * - * @see C#create() + * @see test.innertypeclash.B.C#create() */ - protected C_Impl() { + public C_Impl() { super(); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public C registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.innertypeclash.B.C registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -25,7 +25,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public C unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.innertypeclash.B.C unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -62,9 +62,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav // No fields to write, hook for subclasses. } - /** Helper for creating an object of type {@link C} from a polymorphic composition. */ - public static C readC_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.innertypeclash.B_Impl.C_Impl result = new C_Impl(); + /** Helper for creating an object of type {@link test.innertypeclash.B.C} from a polymorphic composition. */ + public static test.innertypeclash.B.C readC_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.innertypeclash.impl.B_Impl.C_Impl result = new C_Impl(); result.readContent(in); return result; } @@ -84,7 +84,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link C} type. */ + /** XML element name representing a {@link test.innertypeclash.B.C} type. */ public static final String C__XML_ELEMENT = "c"; @Override @@ -104,9 +104,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link C} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.innertypeclash.B.C} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static C_Impl readC_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { C_Impl result = new C_Impl(); result.readContentXml(in); @@ -163,34 +164,34 @@ protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream } - private A.C _ac = null; + private test.innertypeclash.A.C _ac = null; - private B.C _bc = null; + private test.innertypeclash.B.C _bc = null; - private C _c = null; + private test.innertypeclash.B.C _c = null; /** * Creates a {@link B_Impl} instance. * - * @see B#create() + * @see test.innertypeclash.B#create() */ - protected B_Impl() { + public B_Impl() { super(); } @Override - public final A.C getAc() { + public final test.innertypeclash.A.C getAc() { return _ac; } @Override - public B setAc(A.C value) { + public test.innertypeclash.B setAc(test.innertypeclash.A.C value) { internalSetAc(value); return this; } /** Internal setter for {@link #getAc()} without chain call utility. */ - protected final void internalSetAc(A.C value) { + protected final void internalSetAc(test.innertypeclash.A.C value) { _listener.beforeSet(this, AC__PROP, value); _ac = value; } @@ -201,18 +202,18 @@ public final boolean hasAc() { } @Override - public final B.C getBc() { + public final test.innertypeclash.B.C getBc() { return _bc; } @Override - public B setBc(B.C value) { + public test.innertypeclash.B setBc(test.innertypeclash.B.C value) { internalSetBc(value); return this; } /** Internal setter for {@link #getBc()} without chain call utility. */ - protected final void internalSetBc(B.C value) { + protected final void internalSetBc(test.innertypeclash.B.C value) { _listener.beforeSet(this, BC__PROP, value); _bc = value; } @@ -223,18 +224,18 @@ public final boolean hasBc() { } @Override - public final C getC() { + public final test.innertypeclash.B.C getC() { return _c; } @Override - public B setC(C value) { + public test.innertypeclash.B setC(test.innertypeclash.B.C value) { internalSetC(value); return this; } /** Internal setter for {@link #getC()} without chain call utility. */ - protected final void internalSetC(C value) { + protected final void internalSetC(test.innertypeclash.B.C value) { _listener.beforeSet(this, C__PROP, value); _c = value; } @@ -247,7 +248,7 @@ public final boolean hasC() { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public B registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.innertypeclash.B registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -257,7 +258,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public B unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.innertypeclash.B unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -288,16 +289,16 @@ public Object get(String field) { case AC__PROP: return getAc(); case BC__PROP: return getBc(); case C__PROP: return getC(); - default: return B.super.get(field); + default: return test.innertypeclash.B.super.get(field); } } @Override public void set(String field, Object value) { switch (field) { - case AC__PROP: internalSetAc((A.C) value); break; - case BC__PROP: internalSetBc((B.C) value); break; - case C__PROP: internalSetC((C) value); break; + case AC__PROP: internalSetAc((test.innertypeclash.A.C) value); break; + case BC__PROP: internalSetBc((test.innertypeclash.B.C) value); break; + case C__PROP: internalSetC((test.innertypeclash.B.C) value); break; } } @@ -362,9 +363,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } } - /** Helper for creating an object of type {@link B} from a polymorphic composition. */ - public static B readB_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.innertypeclash.B_Impl result = new B_Impl(); + /** Helper for creating an object of type {@link test.innertypeclash.B} from a polymorphic composition. */ + public static test.innertypeclash.B readB_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.innertypeclash.impl.B_Impl result = new B_Impl(); result.readContent(in); return result; } @@ -387,7 +388,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link B} type. */ + /** XML element name representing a {@link test.innertypeclash.B} type. */ public static final String B__XML_ELEMENT = "b"; /** XML attribute or element name of a {@link #getAc} property. */ @@ -433,7 +434,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. } } - /** Creates a new {@link B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.innertypeclash.B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static B_Impl readB_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { B_Impl result = new B_Impl(); result.readContentXml(in); @@ -473,15 +474,15 @@ protected void readFieldXmlAttribute(String name, String value) { protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { case AC__XML_ATTR: { - setAc(test.innertypeclash.A_Impl.C_Impl.readC_XmlContent(in)); + setAc(test.innertypeclash.impl.A_Impl.C_Impl.readC_XmlContent(in)); break; } case BC__XML_ATTR: { - setBc(test.innertypeclash.B_Impl.C_Impl.readC_XmlContent(in)); + setBc(test.innertypeclash.impl.B_Impl.C_Impl.readC_XmlContent(in)); break; } case C__XML_ATTR: { - setC(test.innertypeclash.B_Impl.C_Impl.readC_XmlContent(in)); + setC(test.innertypeclash.impl.B_Impl.C_Impl.readC_XmlContent(in)); break; } default: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java index c009e9cf..b1758a52 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java @@ -4,13 +4,13 @@ public interface A extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msg public interface B extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link B} instance. + * Creates a {@link test.lowercasemessage.A.B} instance. */ - static B create() { - return new test.lowercasemessage.A_Impl.B_Impl(); + static test.lowercasemessage.A.B create() { + return new test.lowercasemessage.impl.A_Impl.B_Impl(); } - /** Identifier for the {@link B} type in JSON format. */ + /** Identifier for the {@link test.lowercasemessage.A.B} type in JSON format. */ static final String B__TYPE = "b"; /** @see #getA1() */ @@ -25,24 +25,24 @@ static B create() { /** Identifier for the property {@link #getB1()} in binary format. */ static final int B_1__ID = 2; - A getA1(); + test.lowercasemessage.A getA1(); /** * @see #getA1() */ - B setA1(A value); + test.lowercasemessage.A.B setA1(test.lowercasemessage.A value); /** * Checks, whether {@link #getA1()} has a value. */ boolean hasA1(); - A.B getB1(); + test.lowercasemessage.A.B getB1(); /** * @see #getB1() */ - B setB1(A.B value); + test.lowercasemessage.A.B setB1(test.lowercasemessage.A.B value); /** * Checks, whether {@link #getB1()} has a value. @@ -50,22 +50,22 @@ static B create() { boolean hasB1(); @Override - public B registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.lowercasemessage.A.B registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public B unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.lowercasemessage.A.B unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static B readb(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.lowercasemessage.A_Impl.B_Impl result = new test.lowercasemessage.A_Impl.B_Impl(); + static test.lowercasemessage.A.B readb(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.lowercasemessage.impl.A_Impl.B_Impl result = new test.lowercasemessage.impl.A_Impl.B_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static B readb(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.lowercasemessage.A.B readb(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - B result = test.lowercasemessage.A_Impl.B_Impl.readb_Content(in); + test.lowercasemessage.A.B result = test.lowercasemessage.impl.A_Impl.B_Impl.readb_Content(in); in.endObject(); return result; } @@ -73,19 +73,19 @@ static B readb(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOExcept /** Creates a new {@link B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static B readB(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.lowercasemessage.A_Impl.B_Impl.readB_XmlContent(in); + return test.lowercasemessage.impl.A_Impl.B_Impl.readB_XmlContent(in); } } /** - * Creates a {@link A} instance. + * Creates a {@link test.lowercasemessage.A} instance. */ - static A create() { - return new test.lowercasemessage.A_Impl(); + static test.lowercasemessage.A create() { + return new test.lowercasemessage.impl.A_Impl(); } - /** Identifier for the {@link A} type in JSON format. */ + /** Identifier for the {@link test.lowercasemessage.A} type in JSON format. */ static final String A__TYPE = "a"; /** @see #getA1() */ @@ -100,24 +100,24 @@ static A create() { /** Identifier for the property {@link #getB1()} in binary format. */ static final int B_1__ID = 2; - A getA1(); + test.lowercasemessage.A getA1(); /** * @see #getA1() */ - A setA1(A value); + test.lowercasemessage.A setA1(test.lowercasemessage.A value); /** * Checks, whether {@link #getA1()} has a value. */ boolean hasA1(); - A.B getB1(); + test.lowercasemessage.A.B getB1(); /** * @see #getB1() */ - A setB1(A.B value); + test.lowercasemessage.A setB1(test.lowercasemessage.A.B value); /** * Checks, whether {@link #getB1()} has a value. @@ -125,22 +125,22 @@ static A create() { boolean hasB1(); @Override - public A registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.lowercasemessage.A registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public A unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.lowercasemessage.A unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static A reada(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.lowercasemessage.A_Impl result = new test.lowercasemessage.A_Impl(); + static test.lowercasemessage.A reada(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.lowercasemessage.impl.A_Impl result = new test.lowercasemessage.impl.A_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static A reada(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.lowercasemessage.A reada(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - A result = test.lowercasemessage.A_Impl.reada_Content(in); + test.lowercasemessage.A result = test.lowercasemessage.impl.A_Impl.reada_Content(in); in.endObject(); return result; } @@ -148,7 +148,7 @@ static A reada(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOExcept /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static A readA(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.lowercasemessage.A_Impl.readA_XmlContent(in); + return test.lowercasemessage.impl.A_Impl.readA_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java similarity index 79% rename from de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java index 63c86667..b8003d3e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java @@ -1,34 +1,34 @@ -package test.lowercasemessage; +package test.lowercasemessage.impl; -class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements A { - static class B_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements B { +public class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.lowercasemessage.A { + public static class B_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.lowercasemessage.A.B { - private A _a1 = null; + private test.lowercasemessage.A _a1 = null; - private A.B _b1 = null; + private test.lowercasemessage.A.B _b1 = null; /** * Creates a {@link B_Impl} instance. * - * @see B#create() + * @see test.lowercasemessage.A.B#create() */ - protected B_Impl() { + public B_Impl() { super(); } @Override - public final A getA1() { + public final test.lowercasemessage.A getA1() { return _a1; } @Override - public B setA1(A value) { + public test.lowercasemessage.A.B setA1(test.lowercasemessage.A value) { internalSetA1(value); return this; } /** Internal setter for {@link #getA1()} without chain call utility. */ - protected final void internalSetA1(A value) { + protected final void internalSetA1(test.lowercasemessage.A value) { _listener.beforeSet(this, A_1__PROP, value); _a1 = value; } @@ -39,18 +39,18 @@ public final boolean hasA1() { } @Override - public final A.B getB1() { + public final test.lowercasemessage.A.B getB1() { return _b1; } @Override - public B setB1(A.B value) { + public test.lowercasemessage.A.B setB1(test.lowercasemessage.A.B value) { internalSetB1(value); return this; } /** Internal setter for {@link #getB1()} without chain call utility. */ - protected final void internalSetB1(A.B value) { + protected final void internalSetB1(test.lowercasemessage.A.B value) { _listener.beforeSet(this, B_1__PROP, value); _b1 = value; } @@ -63,7 +63,7 @@ public final boolean hasB1() { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public B registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.lowercasemessage.A.B registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -73,7 +73,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public B unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.lowercasemessage.A.B unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -102,15 +102,15 @@ public Object get(String field) { switch (field) { case A_1__PROP: return getA1(); case B_1__PROP: return getB1(); - default: return B.super.get(field); + default: return test.lowercasemessage.A.B.super.get(field); } } @Override public void set(String field, Object value) { switch (field) { - case A_1__PROP: internalSetA1((A) value); break; - case B_1__PROP: internalSetB1((A.B) value); break; + case A_1__PROP: internalSetA1((test.lowercasemessage.A) value); break; + case B_1__PROP: internalSetB1((test.lowercasemessage.A.B) value); break; } } @@ -166,9 +166,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } } - /** Helper for creating an object of type {@link B} from a polymorphic composition. */ - public static B readb_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.lowercasemessage.A_Impl.B_Impl result = new B_Impl(); + /** Helper for creating an object of type {@link test.lowercasemessage.A.B} from a polymorphic composition. */ + public static test.lowercasemessage.A.B readb_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.lowercasemessage.impl.A_Impl.B_Impl result = new B_Impl(); result.readContent(in); return result; } @@ -190,7 +190,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link B} type. */ + /** XML element name representing a {@link test.lowercasemessage.A.B} type. */ public static final String B__XML_ELEMENT = "b"; /** XML attribute or element name of a {@link #getA1} property. */ @@ -228,7 +228,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. } } - /** Creates a new {@link B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.lowercasemessage.A.B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static B_Impl readB_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { B_Impl result = new B_Impl(); result.readContentXml(in); @@ -268,11 +268,11 @@ protected void readFieldXmlAttribute(String name, String value) { protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { case A_1__XML_ATTR: { - setA1(test.lowercasemessage.A_Impl.readA_XmlContent(in)); + setA1(test.lowercasemessage.impl.A_Impl.readA_XmlContent(in)); break; } case B_1__XML_ATTR: { - setB1(test.lowercasemessage.A_Impl.B_Impl.readB_XmlContent(in)); + setB1(test.lowercasemessage.impl.A_Impl.B_Impl.readB_XmlContent(in)); break; } default: { @@ -293,32 +293,32 @@ protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream } - private A _a1 = null; + private test.lowercasemessage.A _a1 = null; - private A.B _b1 = null; + private test.lowercasemessage.A.B _b1 = null; /** * Creates a {@link A_Impl} instance. * - * @see A#create() + * @see test.lowercasemessage.A#create() */ - protected A_Impl() { + public A_Impl() { super(); } @Override - public final A getA1() { + public final test.lowercasemessage.A getA1() { return _a1; } @Override - public A setA1(A value) { + public test.lowercasemessage.A setA1(test.lowercasemessage.A value) { internalSetA1(value); return this; } /** Internal setter for {@link #getA1()} without chain call utility. */ - protected final void internalSetA1(A value) { + protected final void internalSetA1(test.lowercasemessage.A value) { _listener.beforeSet(this, A_1__PROP, value); _a1 = value; } @@ -329,18 +329,18 @@ public final boolean hasA1() { } @Override - public final A.B getB1() { + public final test.lowercasemessage.A.B getB1() { return _b1; } @Override - public A setB1(A.B value) { + public test.lowercasemessage.A setB1(test.lowercasemessage.A.B value) { internalSetB1(value); return this; } /** Internal setter for {@link #getB1()} without chain call utility. */ - protected final void internalSetB1(A.B value) { + protected final void internalSetB1(test.lowercasemessage.A.B value) { _listener.beforeSet(this, B_1__PROP, value); _b1 = value; } @@ -353,7 +353,7 @@ public final boolean hasB1() { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public A registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.lowercasemessage.A registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -363,7 +363,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public A unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.lowercasemessage.A unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -392,15 +392,15 @@ public Object get(String field) { switch (field) { case A_1__PROP: return getA1(); case B_1__PROP: return getB1(); - default: return A.super.get(field); + default: return test.lowercasemessage.A.super.get(field); } } @Override public void set(String field, Object value) { switch (field) { - case A_1__PROP: internalSetA1((A) value); break; - case B_1__PROP: internalSetB1((A.B) value); break; + case A_1__PROP: internalSetA1((test.lowercasemessage.A) value); break; + case B_1__PROP: internalSetB1((test.lowercasemessage.A.B) value); break; } } @@ -456,9 +456,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } } - /** Helper for creating an object of type {@link A} from a polymorphic composition. */ - public static A reada_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.lowercasemessage.A_Impl result = new A_Impl(); + /** Helper for creating an object of type {@link test.lowercasemessage.A} from a polymorphic composition. */ + public static test.lowercasemessage.A reada_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.lowercasemessage.impl.A_Impl result = new A_Impl(); result.readContent(in); return result; } @@ -480,7 +480,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link A} type. */ + /** XML element name representing a {@link test.lowercasemessage.A} type. */ public static final String A__XML_ELEMENT = "a"; /** XML attribute or element name of a {@link #getA1} property. */ @@ -518,7 +518,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. } } - /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.lowercasemessage.A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static A_Impl readA_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { A_Impl result = new A_Impl(); result.readContentXml(in); @@ -558,11 +558,11 @@ protected void readFieldXmlAttribute(String name, String value) { protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { case A_1__XML_ATTR: { - setA1(test.lowercasemessage.A_Impl.readA_XmlContent(in)); + setA1(test.lowercasemessage.impl.A_Impl.readA_XmlContent(in)); break; } case B_1__XML_ATTR: { - setB1(test.lowercasemessage.A_Impl.B_Impl.readB_XmlContent(in)); + setB1(test.lowercasemessage.impl.A_Impl.B_Impl.readB_XmlContent(in)); break; } default: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java index c5b265ad..844ca565 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java @@ -3,13 +3,13 @@ public interface MyMessage extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link MyMessage} instance. + * Creates a {@link test.maptype.data.MyMessage} instance. */ - static MyMessage create() { - return new test.maptype.data.MyMessage_Impl(); + static test.maptype.data.MyMessage create() { + return new test.maptype.data.impl.MyMessage_Impl(); } - /** Identifier for the {@link MyMessage} type in JSON format. */ + /** Identifier for the {@link test.maptype.data.MyMessage} type in JSON format. */ static final String MY_MESSAGE__TYPE = "MyMessage"; /** @see #getProjects() */ @@ -24,17 +24,17 @@ static MyMessage create() { /** Identifier for the property {@link #getRating()} in binary format. */ static final int RATING__ID = 4; - java.util.Map getProjects(); + java.util.Map getProjects(); /** * @see #getProjects() */ - MyMessage setProjects(java.util.Map value); + test.maptype.data.MyMessage setProjects(java.util.Map value); /** * Adds a key value pair to the {@link #getProjects()} map. */ - MyMessage putProject(String key, Project value); + test.maptype.data.MyMessage putProject(String key, test.maptype.data.Project value); /** * Removes a key from the {@link #getProjects()} map. @@ -46,12 +46,12 @@ static MyMessage create() { /** * @see #getRating() */ - MyMessage setRating(java.util.Map value); + test.maptype.data.MyMessage setRating(java.util.Map value); /** * Adds a key value pair to the {@link #getRating()} map. */ - MyMessage putRating(int key, String value); + test.maptype.data.MyMessage putRating(int key, String value); /** * Removes a key from the {@link #getRating()} map. @@ -59,22 +59,22 @@ static MyMessage create() { void removeRating(int key); @Override - public MyMessage registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.maptype.data.MyMessage registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public MyMessage unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.maptype.data.MyMessage unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static MyMessage readMyMessage(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.maptype.data.MyMessage_Impl result = new test.maptype.data.MyMessage_Impl(); + static test.maptype.data.MyMessage readMyMessage(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.maptype.data.impl.MyMessage_Impl result = new test.maptype.data.impl.MyMessage_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static MyMessage readMyMessage(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.maptype.data.MyMessage readMyMessage(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - MyMessage result = test.maptype.data.MyMessage_Impl.readMyMessage_Content(in); + test.maptype.data.MyMessage result = test.maptype.data.impl.MyMessage_Impl.readMyMessage_Content(in); in.endObject(); return result; } @@ -82,7 +82,7 @@ static MyMessage readMyMessage(de.haumacher.msgbuf.binary.DataReader in) throws /** Creates a new {@link MyMessage} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static MyMessage readMyMessage(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.maptype.data.MyMessage_Impl.readMyMessage_XmlContent(in); + return test.maptype.data.impl.MyMessage_Impl.readMyMessage_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java index 63aca69f..c88112e7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java @@ -3,13 +3,13 @@ public interface Project extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link Project} instance. + * Creates a {@link test.maptype.data.Project} instance. */ - static Project create() { - return new test.maptype.data.Project_Impl(); + static test.maptype.data.Project create() { + return new test.maptype.data.impl.Project_Impl(); } - /** Identifier for the {@link Project} type in JSON format. */ + /** Identifier for the {@link test.maptype.data.Project} type in JSON format. */ static final String PROJECT__TYPE = "Project"; /** @see #getName() */ @@ -29,32 +29,32 @@ static Project create() { /** * @see #getName() */ - Project setName(String value); + test.maptype.data.Project setName(String value); double getCost(); /** * @see #getCost() */ - Project setCost(double value); + test.maptype.data.Project setCost(double value); @Override - public Project registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.maptype.data.Project registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public Project unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.maptype.data.Project unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static Project readProject(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.maptype.data.Project_Impl result = new test.maptype.data.Project_Impl(); + static test.maptype.data.Project readProject(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.maptype.data.impl.Project_Impl result = new test.maptype.data.impl.Project_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Project readProject(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.maptype.data.Project readProject(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Project result = test.maptype.data.Project_Impl.readProject_Content(in); + test.maptype.data.Project result = test.maptype.data.impl.Project_Impl.readProject_Content(in); in.endObject(); return result; } @@ -62,7 +62,7 @@ static Project readProject(de.haumacher.msgbuf.binary.DataReader in) throws java /** Creates a new {@link Project} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Project readProject(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.maptype.data.Project_Impl.readProject_XmlContent(in); + return test.maptype.data.impl.Project_Impl.readProject_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java similarity index 82% rename from de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java index afd2a9ea..d8c8e0c8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java @@ -1,46 +1,46 @@ -package test.maptype.data; +package test.maptype.data.impl; -class MyMessage_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements MyMessage { +public class MyMessage_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.maptype.data.MyMessage { - private final java.util.Map _projects = new java.util.HashMap<>(); + private final java.util.Map _projects = new java.util.HashMap<>(); private final java.util.Map _rating = new java.util.HashMap<>(); /** * Creates a {@link MyMessage_Impl} instance. * - * @see MyMessage#create() + * @see test.maptype.data.MyMessage#create() */ - protected MyMessage_Impl() { + public MyMessage_Impl() { super(); } @Override - public final java.util.Map getProjects() { + public final java.util.Map getProjects() { return _projects; } @Override - public MyMessage setProjects(java.util.Map value) { + public test.maptype.data.MyMessage setProjects(java.util.Map value) { internalSetProjects(value); return this; } /** Internal setter for {@link #getProjects()} without chain call utility. */ - protected final void internalSetProjects(java.util.Map value) { + protected final void internalSetProjects(java.util.Map value) { if (value == null) throw new IllegalArgumentException("Property 'projects' cannot be null."); _projects.clear(); _projects.putAll(value); } @Override - public MyMessage putProject(String key, Project value) { + public test.maptype.data.MyMessage putProject(String key, test.maptype.data.Project value) { internalPutProject(key, value); return this; } - /** Implementation of {@link #putProject(String, Project)} without chain call utility. */ - protected final void internalPutProject(String key, Project value) { + /** Implementation of {@link #putProject(String, test.maptype.data.Project)} without chain call utility. */ + protected final void internalPutProject(String key, test.maptype.data.Project value) { if (_projects.containsKey(key)) { throw new IllegalArgumentException("Property 'projects' already contains a value for key '" + key + "'."); } @@ -58,7 +58,7 @@ public final java.util.Map getRating() { } @Override - public MyMessage setRating(java.util.Map value) { + public test.maptype.data.MyMessage setRating(java.util.Map value) { internalSetRating(value); return this; } @@ -71,7 +71,7 @@ protected final void internalSetRating(java.util.Map value) { } @Override - public MyMessage putRating(int key, String value) { + public test.maptype.data.MyMessage putRating(int key, String value) { internalPutRating(key, value); return this; } @@ -92,7 +92,7 @@ public final void removeRating(int key) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public MyMessage registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.maptype.data.MyMessage registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -102,7 +102,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public MyMessage unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.maptype.data.MyMessage unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -131,14 +131,14 @@ public Object get(String field) { switch (field) { case PROJECTS__PROP: return getProjects(); case RATING__PROP: return getRating(); - default: return MyMessage.super.get(field); + default: return test.maptype.data.MyMessage.super.get(field); } } @Override public void set(String field, Object value) { switch (field) { - case PROJECTS__PROP: internalSetProjects((java.util.Map) value); break; + case PROJECTS__PROP: internalSetProjects((java.util.Map) value); break; case RATING__PROP: internalSetRating((java.util.Map) value); break; } } @@ -153,7 +153,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. super.writeFields(out); out.name(PROJECTS__PROP); out.beginObject(); - for (java.util.Map.Entry entry : getProjects().entrySet()) { + for (java.util.Map.Entry entry : getProjects().entrySet()) { out.name(entry.getKey()); entry.getValue().writeTo(out); } @@ -224,9 +224,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.name(RATING__ID); } - /** Helper for creating an object of type {@link MyMessage} from a polymorphic composition. */ - public static MyMessage readMyMessage_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.maptype.data.MyMessage_Impl result = new MyMessage_Impl(); + /** Helper for creating an object of type {@link test.maptype.data.MyMessage} from a polymorphic composition. */ + public static test.maptype.data.MyMessage readMyMessage_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.maptype.data.impl.MyMessage_Impl result = new MyMessage_Impl(); result.readContent(in); return result; } @@ -247,7 +247,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th while (in.hasNext()) { in.beginObject(); String key = ""; - Project value = null; + test.maptype.data.Project value = null; while (in.hasNext()) { switch (in.nextName()) { case 1: key = in.nextString(); break; @@ -284,7 +284,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link MyMessage} type. */ + /** XML element name representing a {@link test.maptype.data.MyMessage} type. */ public static final String MY_MESSAGE__XML_ELEMENT = "my-message"; /** XML attribute or element name of a {@link #getProjects} property. */ @@ -310,9 +310,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link MyMessage} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.maptype.data.MyMessage} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static MyMessage_Impl readMyMessage_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { MyMessage_Impl result = new MyMessage_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java similarity index 85% rename from de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java index 2b1e04f3..8c1b8af3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java @@ -1,6 +1,6 @@ -package test.maptype.data; +package test.maptype.data.impl; -class Project_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements Project { +public class Project_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.maptype.data.Project { private String _name = ""; @@ -9,9 +9,9 @@ class Project_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implement /** * Creates a {@link Project_Impl} instance. * - * @see Project#create() + * @see test.maptype.data.Project#create() */ - protected Project_Impl() { + public Project_Impl() { super(); } @@ -21,7 +21,7 @@ public final String getName() { } @Override - public Project setName(String value) { + public test.maptype.data.Project setName(String value) { internalSetName(value); return this; } @@ -38,7 +38,7 @@ public final double getCost() { } @Override - public Project setCost(double value) { + public test.maptype.data.Project setCost(double value) { internalSetCost(value); return this; } @@ -52,7 +52,7 @@ protected final void internalSetCost(double value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public Project registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.maptype.data.Project registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -62,7 +62,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public Project unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.maptype.data.Project unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -91,7 +91,7 @@ public Object get(String field) { switch (field) { case NAME__PROP: return getName(); case COST__PROP: return getCost(); - default: return Project.super.get(field); + default: return test.maptype.data.Project.super.get(field); } } @@ -147,9 +147,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getCost()); } - /** Helper for creating an object of type {@link Project} from a polymorphic composition. */ - public static Project readProject_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.maptype.data.Project_Impl result = new Project_Impl(); + /** Helper for creating an object of type {@link test.maptype.data.Project} from a polymorphic composition. */ + public static test.maptype.data.Project readProject_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.maptype.data.impl.Project_Impl result = new Project_Impl(); result.readContent(in); return result; } @@ -171,7 +171,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Project} type. */ + /** XML element name representing a {@link test.maptype.data.Project} type. */ public static final String PROJECT__XML_ELEMENT = "project"; /** XML attribute or element name of a {@link #getName} property. */ @@ -199,9 +199,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link Project} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.maptype.data.Project} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Project_Impl readProject_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Project_Impl result = new Project_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java index 9d48d138..97321fc3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java @@ -4,13 +4,13 @@ public interface SearchResponse extends de.haumacher.msgbuf.data.DataObject, de. public interface Result extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link Result} instance. + * Creates a {@link test.nested.data.SearchResponse.Result} instance. */ - static Result create() { - return new test.nested.data.SearchResponse_Impl.Result_Impl(); + static test.nested.data.SearchResponse.Result create() { + return new test.nested.data.impl.SearchResponse_Impl.Result_Impl(); } - /** Identifier for the {@link Result} type in JSON format. */ + /** Identifier for the {@link test.nested.data.SearchResponse.Result} type in JSON format. */ static final String RESULT__TYPE = "Result"; /** @see #getUrl() */ @@ -36,26 +36,26 @@ static Result create() { /** * @see #getUrl() */ - Result setUrl(String value); + test.nested.data.SearchResponse.Result setUrl(String value); String getTitle(); /** * @see #getTitle() */ - Result setTitle(String value); + test.nested.data.SearchResponse.Result setTitle(String value); java.util.List getSnippets(); /** * @see #getSnippets() */ - Result setSnippets(java.util.List value); + test.nested.data.SearchResponse.Result setSnippets(java.util.List value); /** * Adds a value to the {@link #getSnippets()} list. */ - Result addSnippet(String value); + test.nested.data.SearchResponse.Result addSnippet(String value); /** * Removes a value from the {@link #getSnippets()} list. @@ -63,22 +63,22 @@ static Result create() { void removeSnippet(String value); @Override - public Result registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.nested.data.SearchResponse.Result registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public Result unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.nested.data.SearchResponse.Result unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static Result readResult(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.nested.data.SearchResponse_Impl.Result_Impl result = new test.nested.data.SearchResponse_Impl.Result_Impl(); + static test.nested.data.SearchResponse.Result readResult(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.SearchResponse_Impl.Result_Impl result = new test.nested.data.impl.SearchResponse_Impl.Result_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Result readResult(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.nested.data.SearchResponse.Result readResult(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Result result = test.nested.data.SearchResponse_Impl.Result_Impl.readResult_Content(in); + test.nested.data.SearchResponse.Result result = test.nested.data.impl.SearchResponse_Impl.Result_Impl.readResult_Content(in); in.endObject(); return result; } @@ -86,19 +86,19 @@ static Result readResult(de.haumacher.msgbuf.binary.DataReader in) throws java.i /** Creates a new {@link Result} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Result readResult(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.nested.data.SearchResponse_Impl.Result_Impl.readResult_XmlContent(in); + return test.nested.data.impl.SearchResponse_Impl.Result_Impl.readResult_XmlContent(in); } } /** - * Creates a {@link SearchResponse} instance. + * Creates a {@link test.nested.data.SearchResponse} instance. */ - static SearchResponse create() { - return new test.nested.data.SearchResponse_Impl(); + static test.nested.data.SearchResponse create() { + return new test.nested.data.impl.SearchResponse_Impl(); } - /** Identifier for the {@link SearchResponse} type in JSON format. */ + /** Identifier for the {@link test.nested.data.SearchResponse} type in JSON format. */ static final String SEARCH_RESPONSE__TYPE = "SearchResponse"; /** @see #getResults() */ @@ -107,40 +107,40 @@ static SearchResponse create() { /** Identifier for the property {@link #getResults()} in binary format. */ static final int RESULTS__ID = 1; - java.util.List getResults(); + java.util.List getResults(); /** * @see #getResults() */ - SearchResponse setResults(java.util.List value); + test.nested.data.SearchResponse setResults(java.util.List value); /** * Adds a value to the {@link #getResults()} list. */ - SearchResponse addResult(Result value); + test.nested.data.SearchResponse addResult(test.nested.data.SearchResponse.Result value); /** * Removes a value from the {@link #getResults()} list. */ - void removeResult(Result value); + void removeResult(test.nested.data.SearchResponse.Result value); @Override - public SearchResponse registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.nested.data.SearchResponse registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public SearchResponse unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.nested.data.SearchResponse unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static SearchResponse readSearchResponse(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.nested.data.SearchResponse_Impl result = new test.nested.data.SearchResponse_Impl(); + static test.nested.data.SearchResponse readSearchResponse(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.SearchResponse_Impl result = new test.nested.data.impl.SearchResponse_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static SearchResponse readSearchResponse(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.nested.data.SearchResponse readSearchResponse(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - SearchResponse result = test.nested.data.SearchResponse_Impl.readSearchResponse_Content(in); + test.nested.data.SearchResponse result = test.nested.data.impl.SearchResponse_Impl.readSearchResponse_Content(in); in.endObject(); return result; } @@ -148,7 +148,7 @@ static SearchResponse readSearchResponse(de.haumacher.msgbuf.binary.DataReader i /** Creates a new {@link SearchResponse} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SearchResponse readSearchResponse(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.nested.data.SearchResponse_Impl.readSearchResponse_XmlContent(in); + return test.nested.data.impl.SearchResponse_Impl.readSearchResponse_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java similarity index 81% rename from de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java index 41f7ee23..faa24c26 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java @@ -1,7 +1,7 @@ -package test.nested.data; +package test.nested.data.impl; -class SearchResponse_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements SearchResponse { - static class Result_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements Result { +public class SearchResponse_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.data.SearchResponse { + public static class Result_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.data.SearchResponse.Result { private String _url = ""; @@ -22,9 +22,9 @@ protected void afterRemove(int index, String element) { /** * Creates a {@link Result_Impl} instance. * - * @see Result#create() + * @see test.nested.data.SearchResponse.Result#create() */ - protected Result_Impl() { + public Result_Impl() { super(); } @@ -34,7 +34,7 @@ public final String getUrl() { } @Override - public Result setUrl(String value) { + public test.nested.data.SearchResponse.Result setUrl(String value) { internalSetUrl(value); return this; } @@ -51,7 +51,7 @@ public final String getTitle() { } @Override - public Result setTitle(String value) { + public test.nested.data.SearchResponse.Result setTitle(String value) { internalSetTitle(value); return this; } @@ -68,7 +68,7 @@ public final java.util.List getSnippets() { } @Override - public Result setSnippets(java.util.List value) { + public test.nested.data.SearchResponse.Result setSnippets(java.util.List value) { internalSetSnippets(value); return this; } @@ -80,7 +80,7 @@ protected final void internalSetSnippets(java.util.List value) } @Override - public Result addSnippet(String value) { + public test.nested.data.SearchResponse.Result addSnippet(String value) { internalAddSnippet(value); return this; } @@ -98,7 +98,7 @@ public final void removeSnippet(String value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public Result registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.nested.data.SearchResponse.Result registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -108,7 +108,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public Result unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.nested.data.SearchResponse.Result unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -139,7 +139,7 @@ public Object get(String field) { case URL__PROP: return getUrl(); case TITLE__PROP: return getTitle(); case SNIPPETS__PROP: return getSnippets(); - default: return Result.super.get(field); + default: return test.nested.data.SearchResponse.Result.super.get(field); } } @@ -219,9 +219,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } } - /** Helper for creating an object of type {@link Result} from a polymorphic composition. */ - public static Result readResult_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.nested.data.SearchResponse_Impl.Result_Impl result = new Result_Impl(); + /** Helper for creating an object of type {@link test.nested.data.SearchResponse.Result} from a polymorphic composition. */ + public static test.nested.data.SearchResponse.Result readResult_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.SearchResponse_Impl.Result_Impl result = new Result_Impl(); result.readContent(in); return result; } @@ -251,7 +251,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Result} type. */ + /** XML element name representing a {@link test.nested.data.SearchResponse.Result} type. */ public static final String RESULT__XML_ELEMENT = "result"; /** XML attribute or element name of a {@link #getUrl} property. */ @@ -283,9 +283,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link Result} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nested.data.SearchResponse.Result} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Result_Impl readResult_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Result_Impl result = new Result_Impl(); result.readContentXml(in); @@ -366,14 +367,14 @@ protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream } - private final java.util.List _results = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _results = new de.haumacher.msgbuf.util.ReferenceList() { @Override - protected void beforeAdd(int index, Result element) { + protected void beforeAdd(int index, test.nested.data.SearchResponse.Result element) { _listener.beforeAdd(SearchResponse_Impl.this, RESULTS__PROP, index, element); } @Override - protected void afterRemove(int index, Result element) { + protected void afterRemove(int index, test.nested.data.SearchResponse.Result element) { _listener.afterRemove(SearchResponse_Impl.this, RESULTS__PROP, index, element); } }; @@ -381,50 +382,50 @@ protected void afterRemove(int index, Result element) { /** * Creates a {@link SearchResponse_Impl} instance. * - * @see SearchResponse#create() + * @see test.nested.data.SearchResponse#create() */ - protected SearchResponse_Impl() { + public SearchResponse_Impl() { super(); } @Override - public final java.util.List getResults() { + public final java.util.List getResults() { return _results; } @Override - public SearchResponse setResults(java.util.List value) { + public test.nested.data.SearchResponse setResults(java.util.List value) { internalSetResults(value); return this; } /** Internal setter for {@link #getResults()} without chain call utility. */ - protected final void internalSetResults(java.util.List value) { + protected final void internalSetResults(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'results' cannot be null."); _results.clear(); _results.addAll(value); } @Override - public SearchResponse addResult(Result value) { + public test.nested.data.SearchResponse addResult(test.nested.data.SearchResponse.Result value) { internalAddResult(value); return this; } - /** Implementation of {@link #addResult(Result)} without chain call utility. */ - protected final void internalAddResult(Result value) { + /** Implementation of {@link #addResult(test.nested.data.SearchResponse.Result)} without chain call utility. */ + protected final void internalAddResult(test.nested.data.SearchResponse.Result value) { _results.add(value); } @Override - public final void removeResult(Result value) { + public final void removeResult(test.nested.data.SearchResponse.Result value) { _results.remove(value); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public SearchResponse registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.nested.data.SearchResponse registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -434,7 +435,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public SearchResponse unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.nested.data.SearchResponse unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -461,14 +462,14 @@ public java.util.List properties() { public Object get(String field) { switch (field) { case RESULTS__PROP: return getResults(); - default: return SearchResponse.super.get(field); + default: return test.nested.data.SearchResponse.super.get(field); } } @Override public void set(String field, Object value) { switch (field) { - case RESULTS__PROP: internalSetResults(de.haumacher.msgbuf.util.Conversions.asList(Result.class, value)); break; + case RESULTS__PROP: internalSetResults(de.haumacher.msgbuf.util.Conversions.asList(test.nested.data.SearchResponse.Result.class, value)); break; } } @@ -482,7 +483,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. super.writeFields(out); out.name(RESULTS__PROP); out.beginArray(); - for (Result x : getResults()) { + for (test.nested.data.SearchResponse.Result x : getResults()) { x.writeTo(out); } out.endArray(); @@ -520,18 +521,18 @@ public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { out.name(RESULTS__ID); { - java.util.List values = getResults(); + java.util.List values = getResults(); out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); - for (Result x : values) { + for (test.nested.data.SearchResponse.Result x : values) { x.writeTo(out); } out.endArray(); } } - /** Helper for creating an object of type {@link SearchResponse} from a polymorphic composition. */ - public static SearchResponse readSearchResponse_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.nested.data.SearchResponse_Impl result = new SearchResponse_Impl(); + /** Helper for creating an object of type {@link test.nested.data.SearchResponse} from a polymorphic composition. */ + public static test.nested.data.SearchResponse readSearchResponse_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.SearchResponse_Impl result = new SearchResponse_Impl(); result.readContent(in); return result; } @@ -559,7 +560,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link SearchResponse} type. */ + /** XML element name representing a {@link test.nested.data.SearchResponse} type. */ public static final String SEARCH_RESPONSE__XML_ELEMENT = "search-response"; /** XML attribute or element name of a {@link #getResults} property. */ @@ -589,7 +590,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. out.writeEndElement(); } - /** Creates a new {@link SearchResponse} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nested.data.SearchResponse} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SearchResponse_Impl readSearchResponse_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SearchResponse_Impl result = new SearchResponse_Impl(); result.readContentXml(in); @@ -655,7 +656,7 @@ private void internalReadResultsListXml(javax.xml.stream.XMLStreamReader in) thr break; } - addResult(test.nested.data.SearchResponse_Impl.Result_Impl.readResult_XmlContent(in)); + addResult(test.nested.data.impl.SearchResponse_Impl.Result_Impl.readResult_XmlContent(in)); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/AtomicShape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/AtomicShape.java index 6510b528..295cd737 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/AtomicShape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/AtomicShape.java @@ -5,14 +5,14 @@ */ public abstract class AtomicShape extends Shape { - /** Visitor interface for the {@link AtomicShape} hierarchy.*/ + /** Visitor interface for the {@link test.nointerfaces.AtomicShape} hierarchy.*/ public interface Visitor { - /** Visit case for {@link Circle}.*/ - R visit(Circle self, A arg) throws E; + /** Visit case for {@link test.nointerfaces.Circle}.*/ + R visit(test.nointerfaces.Circle self, A arg) throws E; - /** Visit case for {@link Rectangle}.*/ - R visit(Rectangle self, A arg) throws E; + /** Visit case for {@link test.nointerfaces.Rectangle}.*/ + R visit(test.nointerfaces.Rectangle self, A arg) throws E; } @@ -24,20 +24,20 @@ protected AtomicShape() { } @Override - public AtomicShape setXCoordinate(int value) { + public test.nointerfaces.AtomicShape setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public AtomicShape setYCoordinate(int value) { + public test.nointerfaces.AtomicShape setYCoordinate(int value) { internalSetYCoordinate(value); return this; } /** Reads a new instance from the given reader. */ - public static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - AtomicShape result; + public static test.nointerfaces.AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nointerfaces.AtomicShape result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -50,22 +50,22 @@ public static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in } /** Reads a new instance from the given reader. */ - public static AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + public static test.nointerfaces.AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); int typeField = in.nextName(); assert typeField == 0; int type = in.nextInt(); - AtomicShape result; + test.nointerfaces.AtomicShape result; switch (type) { - case Circle.CIRCLE__TYPE_ID: result = test.nointerfaces.Circle.readCircle_Content(in); break; - case Rectangle.RECTANGLE__TYPE_ID: result = test.nointerfaces.Rectangle.readRectangle_Content(in); break; + case test.nointerfaces.Circle.CIRCLE__TYPE_ID: result = test.nointerfaces.Circle.readCircle_Content(in); break; + case test.nointerfaces.Rectangle.RECTANGLE__TYPE_ID: result = test.nointerfaces.Rectangle.readRectangle_Content(in); break; default: result = null; while (in.hasNext()) {in.skipValue(); } } in.endObject(); return result; } - /** XML element name representing a {@link AtomicShape} type. */ + /** XML element name representing a {@link test.nointerfaces.AtomicShape} type. */ public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; /** Serializes all fields that are written as XML attributes. */ @@ -78,9 +78,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nointerfaces.AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { case Circle.CIRCLE__XML_ELEMENT: { @@ -126,8 +127,8 @@ public static AtomicShape readAtomicShape(javax.xml.stream.XMLStreamReader in) t public abstract R visit(Visitor v, A arg) throws E; @Override - public final R visit(Shape.Visitor v, A arg) throws E { - return visit((AtomicShape.Visitor) v, arg); + public final R visit(test.nointerfaces.Shape.Visitor v, A arg) throws E { + return visit((test.nointerfaces.AtomicShape.Visitor) v, arg); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java index d981f3cd..dd7d592d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java @@ -6,13 +6,13 @@ public class Car extends Shape { /** - * Creates a {@link Car} instance. + * Creates a {@link test.nointerfaces.Car} instance. */ - public static Car create() { + public static test.nointerfaces.Car create() { return new test.nointerfaces.Car(); } - /** Identifier for the {@link Car} type in JSON format. */ + /** Identifier for the {@link test.nointerfaces.Car} type in JSON format. */ public static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ @@ -24,7 +24,7 @@ public static Car create() { /** @see #getBody() */ public static final String BODY__PROP = "body"; - /** Identifier for the {@link Car} type in binary format. */ + /** Identifier for the {@link test.nointerfaces.Car} type in binary format. */ static final int CAR__TYPE_ID = 4; /** Identifier for the property {@link #getWheel1()} in binary format. */ @@ -36,16 +36,16 @@ public static Car create() { /** Identifier for the property {@link #getBody()} in binary format. */ static final int BODY__ID = 5; - private Circle _wheel1 = null; + private test.nointerfaces.Circle _wheel1 = null; - private Circle _wheel2 = null; + private test.nointerfaces.Circle _wheel2 = null; - private Rectangle _body = null; + private test.nointerfaces.Rectangle _body = null; /** * Creates a {@link Car} instance. * - * @see Car#create() + * @see test.nointerfaces.Car#create() */ protected Car() { super(); @@ -59,20 +59,20 @@ public TypeKind kind() { /** * The front wheel. */ - public final Circle getWheel1() { + public final test.nointerfaces.Circle getWheel1() { return _wheel1; } /** * @see #getWheel1() */ - public Car setWheel1(Circle value) { + public test.nointerfaces.Car setWheel1(test.nointerfaces.Circle value) { internalSetWheel1(value); return this; } /** Internal setter for {@link #getWheel1()} without chain call utility. */ - protected final void internalSetWheel1(Circle value) { + protected final void internalSetWheel1(test.nointerfaces.Circle value) { _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; } @@ -87,20 +87,20 @@ public final boolean hasWheel1() { /** * The back wheel. */ - public final Circle getWheel2() { + public final test.nointerfaces.Circle getWheel2() { return _wheel2; } /** * @see #getWheel2() */ - public Car setWheel2(Circle value) { + public test.nointerfaces.Car setWheel2(test.nointerfaces.Circle value) { internalSetWheel2(value); return this; } /** Internal setter for {@link #getWheel2()} without chain call utility. */ - protected final void internalSetWheel2(Circle value) { + protected final void internalSetWheel2(test.nointerfaces.Circle value) { _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; } @@ -115,20 +115,20 @@ public final boolean hasWheel2() { /** * The car body. */ - public final Rectangle getBody() { + public final test.nointerfaces.Rectangle getBody() { return _body; } /** * @see #getBody() */ - public Car setBody(Rectangle value) { + public test.nointerfaces.Car setBody(test.nointerfaces.Rectangle value) { internalSetBody(value); return this; } /** Internal setter for {@link #getBody()} without chain call utility. */ - protected final void internalSetBody(Rectangle value) { + protected final void internalSetBody(test.nointerfaces.Rectangle value) { _listener.beforeSet(this, BODY__PROP, value); _body = value; } @@ -141,13 +141,13 @@ public final boolean hasBody() { } @Override - public Car setXCoordinate(int value) { + public test.nointerfaces.Car setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Car setYCoordinate(int value) { + public test.nointerfaces.Car setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -181,15 +181,15 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; - case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; - case BODY__PROP: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((test.nointerfaces.Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((test.nointerfaces.Circle) value); break; + case BODY__PROP: internalSetBody((test.nointerfaces.Rectangle) value); break; default: super.set(field, value); break; } } /** Reads a new instance from the given reader. */ - public static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static test.nointerfaces.Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.nointerfaces.Car result = new test.nointerfaces.Car(); result.readContent(in); return result; @@ -222,7 +222,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t } } - /** The binary identifier for this concrete type in the polymorphic {@link Car} hierarchy. */ + /** The binary identifier for this concrete type in the polymorphic {@link test.nointerfaces.Car} hierarchy. */ public int typeId() { return CAR__TYPE_ID; } @@ -245,15 +245,15 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } /** Reads a new instance from the given reader. */ - public static Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + public static test.nointerfaces.Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Car result = test.nointerfaces.Car.readCar_Content(in); + test.nointerfaces.Car result = test.nointerfaces.Car.readCar_Content(in); in.endObject(); return result; } - /** Helper for creating an object of type {@link Car} from a polymorphic composition. */ - public static Car readCar_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + /** Helper for creating an object of type {@link test.nointerfaces.Car} from a polymorphic composition. */ + public static test.nointerfaces.Car readCar_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { test.nointerfaces.Car result = new Car(); result.readContent(in); return result; @@ -269,7 +269,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Car} type. */ + /** XML element name representing a {@link test.nointerfaces.Car} type. */ public static final String CAR__XML_ELEMENT = "car"; /** XML attribute or element name of a {@link #getWheel1} property. */ @@ -313,7 +313,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. } } - /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nointerfaces.Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car result = new Car(); result.readContentXml(in); @@ -357,7 +357,7 @@ public static Car readCar(javax.xml.stream.XMLStreamReader in) throws javax.xml. } @Override - public R visit(Shape.Visitor v, A arg) throws E { + public R visit(test.nointerfaces.Shape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java index 1e838bff..bbe02d5d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java @@ -6,19 +6,19 @@ public class Circle extends AtomicShape { /** - * Creates a {@link Circle} instance. + * Creates a {@link test.nointerfaces.Circle} instance. */ - public static Circle create() { + public static test.nointerfaces.Circle create() { return new test.nointerfaces.Circle(); } - /** Identifier for the {@link Circle} type in JSON format. */ + /** Identifier for the {@link test.nointerfaces.Circle} type in JSON format. */ public static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ public static final String RADIUS__PROP = "r"; - /** Identifier for the {@link Circle} type in binary format. */ + /** Identifier for the {@link test.nointerfaces.Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; /** Identifier for the property {@link #getRadius()} in binary format. */ @@ -29,7 +29,7 @@ public static Circle create() { /** * Creates a {@link Circle} instance. * - * @see Circle#create() + * @see test.nointerfaces.Circle#create() */ protected Circle() { super(); @@ -50,7 +50,7 @@ public final int getRadius() { /** * @see #getRadius() */ - public Circle setRadius(int value) { + public test.nointerfaces.Circle setRadius(int value) { internalSetRadius(value); return this; } @@ -62,13 +62,13 @@ protected final void internalSetRadius(int value) { } @Override - public Circle setXCoordinate(int value) { + public test.nointerfaces.Circle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Circle setYCoordinate(int value) { + public test.nointerfaces.Circle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -104,7 +104,7 @@ public void set(String field, Object value) { } /** Reads a new instance from the given reader. */ - public static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static test.nointerfaces.Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.nointerfaces.Circle result = new test.nointerfaces.Circle(); result.readContent(in); return result; @@ -125,7 +125,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t } } - /** The binary identifier for this concrete type in the polymorphic {@link Circle} hierarchy. */ + /** The binary identifier for this concrete type in the polymorphic {@link test.nointerfaces.Circle} hierarchy. */ public int typeId() { return CIRCLE__TYPE_ID; } @@ -138,15 +138,15 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } /** Reads a new instance from the given reader. */ - public static Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + public static test.nointerfaces.Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Circle result = test.nointerfaces.Circle.readCircle_Content(in); + test.nointerfaces.Circle result = test.nointerfaces.Circle.readCircle_Content(in); in.endObject(); return result; } - /** Helper for creating an object of type {@link Circle} from a polymorphic composition. */ - public static Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + /** Helper for creating an object of type {@link test.nointerfaces.Circle} from a polymorphic composition. */ + public static test.nointerfaces.Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { test.nointerfaces.Circle result = new Circle(); result.readContent(in); return result; @@ -160,7 +160,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Circle} type. */ + /** XML element name representing a {@link test.nointerfaces.Circle} type. */ public static final String CIRCLE__XML_ELEMENT = "circle"; /** XML attribute or element name of a {@link #getRadius} property. */ @@ -182,9 +182,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nointerfaces.Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle result = new Circle(); result.readContentXml(in); @@ -224,7 +225,7 @@ public static Circle readCircle(javax.xml.stream.XMLStreamReader in) throws java } @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { + public R visit(test.nointerfaces.AtomicShape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java index 23e9c85d..84c22f3c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java @@ -6,32 +6,32 @@ public class Group extends Shape { /** - * Creates a {@link Group} instance. + * Creates a {@link test.nointerfaces.Group} instance. */ - public static Group create() { + public static test.nointerfaces.Group create() { return new test.nointerfaces.Group(); } - /** Identifier for the {@link Group} type in JSON format. */ + /** Identifier for the {@link test.nointerfaces.Group} type in JSON format. */ public static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ public static final String SHAPES__PROP = "shapes"; - /** Identifier for the {@link Group} type in binary format. */ + /** Identifier for the {@link test.nointerfaces.Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; /** Identifier for the property {@link #getShapes()} in binary format. */ static final int SHAPES__ID = 3; - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override - protected void beforeAdd(int index, Shape element) { + protected void beforeAdd(int index, test.nointerfaces.Shape element) { _listener.beforeAdd(Group.this, SHAPES__PROP, index, element); } @Override - protected void afterRemove(int index, Shape element) { + protected void afterRemove(int index, test.nointerfaces.Shape element) { _listener.afterRemove(Group.this, SHAPES__PROP, index, element); } }; @@ -39,7 +39,7 @@ protected void afterRemove(int index, Shape element) { /** * Creates a {@link Group} instance. * - * @see Group#create() + * @see test.nointerfaces.Group#create() */ protected Group() { super(); @@ -57,20 +57,20 @@ public TypeKind kind() { * The origins of these {@link Shape}s get a coordinate offset of ({@link #getXCoordinate()}, {@link #getYCoordinate()}). *

*/ - public final java.util.List getShapes() { + public final java.util.List getShapes() { return _shapes; } /** * @see #getShapes() */ - public Group setShapes(java.util.List value) { + public test.nointerfaces.Group setShapes(java.util.List value) { internalSetShapes(value); return this; } /** Internal setter for {@link #getShapes()} without chain call utility. */ - protected final void internalSetShapes(java.util.List value) { + protected final void internalSetShapes(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); _shapes.clear(); _shapes.addAll(value); @@ -79,31 +79,31 @@ protected final void internalSetShapes(java.util.List value) { /** * Adds a value to the {@link #getShapes()} list. */ - public Group addShape(Shape value) { + public test.nointerfaces.Group addShape(test.nointerfaces.Shape value) { internalAddShape(value); return this; } - /** Implementation of {@link #addShape(Shape)} without chain call utility. */ - protected final void internalAddShape(Shape value) { + /** Implementation of {@link #addShape(test.nointerfaces.Shape)} without chain call utility. */ + protected final void internalAddShape(test.nointerfaces.Shape value) { _shapes.add(value); } /** * Removes a value from the {@link #getShapes()} list. */ - public final void removeShape(Shape value) { + public final void removeShape(test.nointerfaces.Shape value) { _shapes.remove(value); } @Override - public Group setXCoordinate(int value) { + public test.nointerfaces.Group setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Group setYCoordinate(int value) { + public test.nointerfaces.Group setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -133,13 +133,13 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(test.nointerfaces.Shape.class, value)); break; default: super.set(field, value); break; } } /** Reads a new instance from the given reader. */ - public static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static test.nointerfaces.Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.nointerfaces.Group result = new test.nointerfaces.Group(); result.readContent(in); return result; @@ -150,7 +150,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. super.writeFields(out); out.name(SHAPES__PROP); out.beginArray(); - for (Shape x : getShapes()) { + for (test.nointerfaces.Shape x : getShapes()) { x.writeTo(out); } out.endArray(); @@ -171,7 +171,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t } } - /** The binary identifier for this concrete type in the polymorphic {@link Group} hierarchy. */ + /** The binary identifier for this concrete type in the polymorphic {@link test.nointerfaces.Group} hierarchy. */ public int typeId() { return GROUP__TYPE_ID; } @@ -181,9 +181,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav super.writeFields(out); out.name(SHAPES__ID); { - java.util.List values = getShapes(); + java.util.List values = getShapes(); out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); - for (Shape x : values) { + for (test.nointerfaces.Shape x : values) { x.writeTo(out); } out.endArray(); @@ -191,15 +191,15 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } /** Reads a new instance from the given reader. */ - public static Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + public static test.nointerfaces.Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Group result = test.nointerfaces.Group.readGroup_Content(in); + test.nointerfaces.Group result = test.nointerfaces.Group.readGroup_Content(in); in.endObject(); return result; } - /** Helper for creating an object of type {@link Group} from a polymorphic composition. */ - public static Group readGroup_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + /** Helper for creating an object of type {@link test.nointerfaces.Group} from a polymorphic composition. */ + public static test.nointerfaces.Group readGroup_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { test.nointerfaces.Group result = new Group(); result.readContent(in); return result; @@ -220,7 +220,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Group} type. */ + /** XML element name representing a {@link test.nointerfaces.Group} type. */ public static final String GROUP__XML_ELEMENT = "group"; /** XML attribute or element name of a {@link #getShapes} property. */ @@ -248,7 +248,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. out.writeEndElement(); } - /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nointerfaces.Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group result = new Group(); result.readContentXml(in); @@ -295,7 +295,7 @@ public static Group readGroup(javax.xml.stream.XMLStreamReader in) throws javax. } @Override - public R visit(Shape.Visitor v, A arg) throws E { + public R visit(test.nointerfaces.Shape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java index 5a2c8358..39586643 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java @@ -6,13 +6,13 @@ public class Rectangle extends AtomicShape { /** - * Creates a {@link Rectangle} instance. + * Creates a {@link test.nointerfaces.Rectangle} instance. */ - public static Rectangle create() { + public static test.nointerfaces.Rectangle create() { return new test.nointerfaces.Rectangle(); } - /** Identifier for the {@link Rectangle} type in JSON format. */ + /** Identifier for the {@link test.nointerfaces.Rectangle} type in JSON format. */ public static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ @@ -21,7 +21,7 @@ public static Rectangle create() { /** @see #getHeight() */ public static final String HEIGHT__PROP = "h"; - /** Identifier for the {@link Rectangle} type in binary format. */ + /** Identifier for the {@link test.nointerfaces.Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; /** Identifier for the property {@link #getWidth()} in binary format. */ @@ -37,7 +37,7 @@ public static Rectangle create() { /** * Creates a {@link Rectangle} instance. * - * @see Rectangle#create() + * @see test.nointerfaces.Rectangle#create() */ protected Rectangle() { super(); @@ -64,7 +64,7 @@ public final int getWidth() { /** * @see #getWidth() */ - public Rectangle setWidth(int value) { + public test.nointerfaces.Rectangle setWidth(int value) { internalSetWidth(value); return this; } @@ -87,7 +87,7 @@ public final int getHeight() { /** * @see #getHeight() */ - public Rectangle setHeight(int value) { + public test.nointerfaces.Rectangle setHeight(int value) { internalSetHeight(value); return this; } @@ -99,13 +99,13 @@ protected final void internalSetHeight(int value) { } @Override - public Rectangle setXCoordinate(int value) { + public test.nointerfaces.Rectangle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Rectangle setYCoordinate(int value) { + public test.nointerfaces.Rectangle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -144,7 +144,7 @@ public void set(String field, Object value) { } /** Reads a new instance from the given reader. */ - public static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static test.nointerfaces.Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.nointerfaces.Rectangle result = new test.nointerfaces.Rectangle(); result.readContent(in); return result; @@ -168,7 +168,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t } } - /** The binary identifier for this concrete type in the polymorphic {@link Rectangle} hierarchy. */ + /** The binary identifier for this concrete type in the polymorphic {@link test.nointerfaces.Rectangle} hierarchy. */ public int typeId() { return RECTANGLE__TYPE_ID; } @@ -183,15 +183,15 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } /** Reads a new instance from the given reader. */ - public static Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + public static test.nointerfaces.Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Rectangle result = test.nointerfaces.Rectangle.readRectangle_Content(in); + test.nointerfaces.Rectangle result = test.nointerfaces.Rectangle.readRectangle_Content(in); in.endObject(); return result; } - /** Helper for creating an object of type {@link Rectangle} from a polymorphic composition. */ - public static Rectangle readRectangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + /** Helper for creating an object of type {@link test.nointerfaces.Rectangle} from a polymorphic composition. */ + public static test.nointerfaces.Rectangle readRectangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { test.nointerfaces.Rectangle result = new Rectangle(); result.readContent(in); return result; @@ -206,7 +206,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Rectangle} type. */ + /** XML element name representing a {@link test.nointerfaces.Rectangle} type. */ public static final String RECTANGLE__XML_ELEMENT = "rectangle"; /** XML attribute or element name of a {@link #getWidth} property. */ @@ -232,9 +232,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nointerfaces.Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle result = new Rectangle(); result.readContentXml(in); @@ -282,7 +283,7 @@ public static Rectangle readRectangle(javax.xml.stream.XMLStreamReader in) throw } @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { + public R visit(test.nointerfaces.AtomicShape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java index c638051b..512a6abc 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java @@ -5,32 +5,32 @@ */ public abstract class Shape extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { - /** Type codes for the {@link Shape} hierarchy. */ + /** Type codes for the {@link test.nointerfaces.Shape} hierarchy. */ public enum TypeKind { - /** Type literal for {@link Circle}. */ + /** Type literal for {@link test.nointerfaces.Circle}. */ CIRCLE, - /** Type literal for {@link Rectangle}. */ + /** Type literal for {@link test.nointerfaces.Rectangle}. */ RECTANGLE, - /** Type literal for {@link Group}. */ + /** Type literal for {@link test.nointerfaces.Group}. */ GROUP, - /** Type literal for {@link Car}. */ + /** Type literal for {@link test.nointerfaces.Car}. */ CAR, ; } - /** Visitor interface for the {@link Shape} hierarchy.*/ - public interface Visitor extends AtomicShape.Visitor { + /** Visitor interface for the {@link test.nointerfaces.Shape} hierarchy.*/ + public interface Visitor extends test.nointerfaces.AtomicShape.Visitor { - /** Visit case for {@link Group}.*/ - R visit(Group self, A arg) throws E; + /** Visit case for {@link test.nointerfaces.Group}.*/ + R visit(test.nointerfaces.Group self, A arg) throws E; - /** Visit case for {@link Car}.*/ - R visit(Car self, A arg) throws E; + /** Visit case for {@link test.nointerfaces.Car}.*/ + R visit(test.nointerfaces.Car self, A arg) throws E; } @@ -70,7 +70,7 @@ public final int getXCoordinate() { /** * @see #getXCoordinate() */ - public Shape setXCoordinate(int value) { + public test.nointerfaces.Shape setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @@ -91,7 +91,7 @@ public final int getYCoordinate() { /** * @see #getYCoordinate() */ - public Shape setYCoordinate(int value) { + public test.nointerfaces.Shape setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -105,7 +105,7 @@ protected final void internalSetYCoordinate(int value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public Shape registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.nointerfaces.Shape registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -115,7 +115,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.nointerfaces.Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -152,8 +152,8 @@ public void set(String field, Object value) { } /** Reads a new instance from the given reader. */ - public static Shape readShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - Shape result; + public static test.nointerfaces.Shape readShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nointerfaces.Shape result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -193,7 +193,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t } } - /** The binary identifier for this concrete type in the polymorphic {@link Shape} hierarchy. */ + /** The binary identifier for this concrete type in the polymorphic {@link test.nointerfaces.Shape} hierarchy. */ abstract int typeId(); @Override @@ -220,17 +220,17 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } /** Reads a new instance from the given reader. */ - public static Shape readShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + public static test.nointerfaces.Shape readShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); int typeField = in.nextName(); assert typeField == 0; int type = in.nextInt(); - Shape result; + test.nointerfaces.Shape result; switch (type) { - case Group.GROUP__TYPE_ID: result = test.nointerfaces.Group.readGroup_Content(in); break; - case Car.CAR__TYPE_ID: result = test.nointerfaces.Car.readCar_Content(in); break; - case Circle.CIRCLE__TYPE_ID: result = test.nointerfaces.Circle.readCircle_Content(in); break; - case Rectangle.RECTANGLE__TYPE_ID: result = test.nointerfaces.Rectangle.readRectangle_Content(in); break; + case test.nointerfaces.Group.GROUP__TYPE_ID: result = test.nointerfaces.Group.readGroup_Content(in); break; + case test.nointerfaces.Car.CAR__TYPE_ID: result = test.nointerfaces.Car.readCar_Content(in); break; + case test.nointerfaces.Circle.CIRCLE__TYPE_ID: result = test.nointerfaces.Circle.readCircle_Content(in); break; + case test.nointerfaces.Rectangle.RECTANGLE__TYPE_ID: result = test.nointerfaces.Rectangle.readRectangle_Content(in); break; default: result = null; while (in.hasNext()) {in.skipValue(); } } in.endObject(); @@ -254,7 +254,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Shape} type. */ + /** XML element name representing a {@link test.nointerfaces.Shape} type. */ public static final String SHAPE__XML_ELEMENT = "shape"; /** XML attribute or element name of a {@link #getXCoordinate} property. */ @@ -277,9 +277,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nointerfaces.Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { case Circle.CIRCLE__XML_ELEMENT: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java index 74c52a91..00014c9e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java @@ -6,13 +6,13 @@ public class SimpleType extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link SimpleType} instance. + * Creates a {@link test.nointerfaces.SimpleType} instance. */ - public static SimpleType create() { + public static test.nointerfaces.SimpleType create() { return new test.nointerfaces.SimpleType(); } - /** Identifier for the {@link SimpleType} type in JSON format. */ + /** Identifier for the {@link test.nointerfaces.SimpleType} type in JSON format. */ public static final String SIMPLE_TYPE__TYPE = "SimpleType"; /** @see #getStr() */ @@ -34,7 +34,7 @@ public static SimpleType create() { /** * Creates a {@link SimpleType} instance. * - * @see SimpleType#create() + * @see test.nointerfaces.SimpleType#create() */ protected SimpleType() { super(); @@ -50,7 +50,7 @@ public final String getStr() { /** * @see #getStr() */ - public SimpleType setStr(String value) { + public test.nointerfaces.SimpleType setStr(String value) { internalSetStr(value); return this; } @@ -71,7 +71,7 @@ public final int getX() { /** * @see #getX() */ - public SimpleType setX(int value) { + public test.nointerfaces.SimpleType setX(int value) { internalSetX(value); return this; } @@ -85,7 +85,7 @@ protected final void internalSetX(int value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.nointerfaces.SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -95,7 +95,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.nointerfaces.SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -137,7 +137,7 @@ public void set(String field, Object value) { } /** Reads a new instance from the given reader. */ - public static SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static test.nointerfaces.SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.nointerfaces.SimpleType result = new test.nointerfaces.SimpleType(); result.readContent(in); return result; @@ -188,15 +188,15 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } /** Reads a new instance from the given reader. */ - public static SimpleType readSimpleType(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + public static test.nointerfaces.SimpleType readSimpleType(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - SimpleType result = test.nointerfaces.SimpleType.readSimpleType_Content(in); + test.nointerfaces.SimpleType result = test.nointerfaces.SimpleType.readSimpleType_Content(in); in.endObject(); return result; } - /** Helper for creating an object of type {@link SimpleType} from a polymorphic composition. */ - public static SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + /** Helper for creating an object of type {@link test.nointerfaces.SimpleType} from a polymorphic composition. */ + public static test.nointerfaces.SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { test.nointerfaces.SimpleType result = new SimpleType(); result.readContent(in); return result; @@ -219,7 +219,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link SimpleType} type. */ + /** XML element name representing a {@link test.nointerfaces.SimpleType} type. */ public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; /** XML attribute or element name of a {@link #getStr} property. */ @@ -247,9 +247,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nointerfaces.SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SimpleType readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SimpleType result = new SimpleType(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/AtomicShape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/AtomicShape.java index e3c424a8..2afa82d3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/AtomicShape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/AtomicShape.java @@ -5,33 +5,33 @@ */ public interface AtomicShape extends Shape { - /** Visitor interface for the {@link AtomicShape} hierarchy.*/ + /** Visitor interface for the {@link test.nojson.AtomicShape} hierarchy.*/ public interface Visitor { - /** Visit case for {@link Circle}.*/ - R visit(Circle self, A arg) throws E; + /** Visit case for {@link test.nojson.Circle}.*/ + R visit(test.nojson.Circle self, A arg) throws E; - /** Visit case for {@link Rectangle}.*/ - R visit(Rectangle self, A arg) throws E; + /** Visit case for {@link test.nojson.Rectangle}.*/ + R visit(test.nojson.Rectangle self, A arg) throws E; } @Override - AtomicShape setXCoordinate(int value); + test.nojson.AtomicShape setXCoordinate(int value); @Override - AtomicShape setYCoordinate(int value); + test.nojson.AtomicShape setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.nojson.AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); int typeField = in.nextName(); assert typeField == 0; int type = in.nextInt(); - AtomicShape result; + test.nojson.AtomicShape result; switch (type) { - case Circle.CIRCLE__TYPE_ID: result = test.nojson.Circle_Impl.readCircle_Content(in); break; - case Rectangle.RECTANGLE__TYPE_ID: result = test.nojson.Rectangle_Impl.readRectangle_Content(in); break; + case test.nojson.Circle.CIRCLE__TYPE_ID: result = test.nojson.impl.Circle_Impl.readCircle_Content(in); break; + case test.nojson.Rectangle.RECTANGLE__TYPE_ID: result = test.nojson.impl.Rectangle_Impl.readRectangle_Content(in); break; default: result = null; while (in.hasNext()) {in.skipValue(); } } in.endObject(); @@ -41,7 +41,7 @@ static AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) thr /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape readAtomicShape(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.nojson.AtomicShape_Impl.readAtomicShape_XmlContent(in); + return test.nojson.impl.AtomicShape_Impl.readAtomicShape_XmlContent(in); } /** Accepts the given visitor. */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java index 2b8dc8f2..e9aaf29f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java @@ -6,13 +6,13 @@ public interface Car extends Shape { /** - * Creates a {@link Car} instance. + * Creates a {@link test.nojson.Car} instance. */ - static Car create() { - return new test.nojson.Car_Impl(); + static test.nojson.Car create() { + return new test.nojson.impl.Car_Impl(); } - /** Identifier for the {@link Car} type in JSON format. */ + /** Identifier for the {@link test.nojson.Car} type in JSON format. */ static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ @@ -24,7 +24,7 @@ static Car create() { /** @see #getBody() */ static final String BODY__PROP = "body"; - /** Identifier for the {@link Car} type in binary format. */ + /** Identifier for the {@link test.nojson.Car} type in binary format. */ static final int CAR__TYPE_ID = 4; /** Identifier for the property {@link #getWheel1()} in binary format. */ @@ -39,12 +39,12 @@ static Car create() { /** * The front wheel. */ - Circle getWheel1(); + test.nojson.Circle getWheel1(); /** * @see #getWheel1() */ - Car setWheel1(Circle value); + test.nojson.Car setWheel1(test.nojson.Circle value); /** * Checks, whether {@link #getWheel1()} has a value. @@ -54,12 +54,12 @@ static Car create() { /** * The back wheel. */ - Circle getWheel2(); + test.nojson.Circle getWheel2(); /** * @see #getWheel2() */ - Car setWheel2(Circle value); + test.nojson.Car setWheel2(test.nojson.Circle value); /** * Checks, whether {@link #getWheel2()} has a value. @@ -69,12 +69,12 @@ static Car create() { /** * The car body. */ - Rectangle getBody(); + test.nojson.Rectangle getBody(); /** * @see #getBody() */ - Car setBody(Rectangle value); + test.nojson.Car setBody(test.nojson.Rectangle value); /** * Checks, whether {@link #getBody()} has a value. @@ -82,15 +82,15 @@ static Car create() { boolean hasBody(); @Override - Car setXCoordinate(int value); + test.nojson.Car setXCoordinate(int value); @Override - Car setYCoordinate(int value); + test.nojson.Car setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.nojson.Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Car result = test.nojson.Car_Impl.readCar_Content(in); + test.nojson.Car result = test.nojson.impl.Car_Impl.readCar_Content(in); in.endObject(); return result; } @@ -98,7 +98,7 @@ static Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOEx /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car readCar(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.nojson.Car_Impl.readCar_XmlContent(in); + return test.nojson.impl.Car_Impl.readCar_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java index e3f47d1c..6004b96d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java @@ -6,19 +6,19 @@ public interface Circle extends AtomicShape { /** - * Creates a {@link Circle} instance. + * Creates a {@link test.nojson.Circle} instance. */ - static Circle create() { - return new test.nojson.Circle_Impl(); + static test.nojson.Circle create() { + return new test.nojson.impl.Circle_Impl(); } - /** Identifier for the {@link Circle} type in JSON format. */ + /** Identifier for the {@link test.nojson.Circle} type in JSON format. */ static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ static final String RADIUS__PROP = "r"; - /** Identifier for the {@link Circle} type in binary format. */ + /** Identifier for the {@link test.nojson.Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; /** Identifier for the property {@link #getRadius()} in binary format. */ @@ -32,18 +32,18 @@ static Circle create() { /** * @see #getRadius() */ - Circle setRadius(int value); + test.nojson.Circle setRadius(int value); @Override - Circle setXCoordinate(int value); + test.nojson.Circle setXCoordinate(int value); @Override - Circle setYCoordinate(int value); + test.nojson.Circle setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.nojson.Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Circle result = test.nojson.Circle_Impl.readCircle_Content(in); + test.nojson.Circle result = test.nojson.impl.Circle_Impl.readCircle_Content(in); in.endObject(); return result; } @@ -51,7 +51,7 @@ static Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.i /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle readCircle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.nojson.Circle_Impl.readCircle_XmlContent(in); + return test.nojson.impl.Circle_Impl.readCircle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java index 93ff9f52..6c64a1f3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java @@ -6,19 +6,19 @@ public interface Group extends Shape { /** - * Creates a {@link Group} instance. + * Creates a {@link test.nojson.Group} instance. */ - static Group create() { - return new test.nojson.Group_Impl(); + static test.nojson.Group create() { + return new test.nojson.impl.Group_Impl(); } - /** Identifier for the {@link Group} type in JSON format. */ + /** Identifier for the {@link test.nojson.Group} type in JSON format. */ static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ static final String SHAPES__PROP = "shapes"; - /** Identifier for the {@link Group} type in binary format. */ + /** Identifier for the {@link test.nojson.Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; /** Identifier for the property {@link #getShapes()} in binary format. */ @@ -31,33 +31,33 @@ static Group create() { * The origins of these {@link Shape}s get a coordinate offset of ({@link #getXCoordinate()}, {@link #getYCoordinate()}). *

*/ - java.util.List getShapes(); + java.util.List getShapes(); /** * @see #getShapes() */ - Group setShapes(java.util.List value); + test.nojson.Group setShapes(java.util.List value); /** * Adds a value to the {@link #getShapes()} list. */ - Group addShape(Shape value); + test.nojson.Group addShape(test.nojson.Shape value); /** * Removes a value from the {@link #getShapes()} list. */ - void removeShape(Shape value); + void removeShape(test.nojson.Shape value); @Override - Group setXCoordinate(int value); + test.nojson.Group setXCoordinate(int value); @Override - Group setYCoordinate(int value); + test.nojson.Group setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.nojson.Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Group result = test.nojson.Group_Impl.readGroup_Content(in); + test.nojson.Group result = test.nojson.impl.Group_Impl.readGroup_Content(in); in.endObject(); return result; } @@ -65,7 +65,7 @@ static Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io. /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group readGroup(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.nojson.Group_Impl.readGroup_XmlContent(in); + return test.nojson.impl.Group_Impl.readGroup_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java index 6aa30c12..8e4c6cc5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java @@ -6,13 +6,13 @@ public interface Rectangle extends AtomicShape { /** - * Creates a {@link Rectangle} instance. + * Creates a {@link test.nojson.Rectangle} instance. */ - static Rectangle create() { - return new test.nojson.Rectangle_Impl(); + static test.nojson.Rectangle create() { + return new test.nojson.impl.Rectangle_Impl(); } - /** Identifier for the {@link Rectangle} type in JSON format. */ + /** Identifier for the {@link test.nojson.Rectangle} type in JSON format. */ static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ @@ -21,7 +21,7 @@ static Rectangle create() { /** @see #getHeight() */ static final String HEIGHT__PROP = "h"; - /** Identifier for the {@link Rectangle} type in binary format. */ + /** Identifier for the {@link test.nojson.Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; /** Identifier for the property {@link #getWidth()} in binary format. */ @@ -44,7 +44,7 @@ static Rectangle create() { /** * @see #getWidth() */ - Rectangle setWidth(int value); + test.nojson.Rectangle setWidth(int value); /** * The width of this {@link Rectangle}. @@ -56,18 +56,18 @@ static Rectangle create() { /** * @see #getHeight() */ - Rectangle setHeight(int value); + test.nojson.Rectangle setHeight(int value); @Override - Rectangle setXCoordinate(int value); + test.nojson.Rectangle setXCoordinate(int value); @Override - Rectangle setYCoordinate(int value); + test.nojson.Rectangle setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.nojson.Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Rectangle result = test.nojson.Rectangle_Impl.readRectangle_Content(in); + test.nojson.Rectangle result = test.nojson.impl.Rectangle_Impl.readRectangle_Content(in); in.endObject(); return result; } @@ -75,7 +75,7 @@ static Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle readRectangle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.nojson.Rectangle_Impl.readRectangle_XmlContent(in); + return test.nojson.impl.Rectangle_Impl.readRectangle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java index 27b9064b..5902cfee 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java @@ -5,32 +5,32 @@ */ public interface Shape extends de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { - /** Type codes for the {@link Shape} hierarchy. */ + /** Type codes for the {@link test.nojson.Shape} hierarchy. */ public enum TypeKind { - /** Type literal for {@link Circle}. */ + /** Type literal for {@link test.nojson.Circle}. */ CIRCLE, - /** Type literal for {@link Rectangle}. */ + /** Type literal for {@link test.nojson.Rectangle}. */ RECTANGLE, - /** Type literal for {@link Group}. */ + /** Type literal for {@link test.nojson.Group}. */ GROUP, - /** Type literal for {@link Car}. */ + /** Type literal for {@link test.nojson.Car}. */ CAR, ; } - /** Visitor interface for the {@link Shape} hierarchy.*/ - public interface Visitor extends AtomicShape.Visitor { + /** Visitor interface for the {@link test.nojson.Shape} hierarchy.*/ + public interface Visitor extends test.nojson.AtomicShape.Visitor { - /** Visit case for {@link Group}.*/ - R visit(Group self, A arg) throws E; + /** Visit case for {@link test.nojson.Group}.*/ + R visit(test.nojson.Group self, A arg) throws E; - /** Visit case for {@link Car}.*/ - R visit(Car self, A arg) throws E; + /** Visit case for {@link test.nojson.Car}.*/ + R visit(test.nojson.Car self, A arg) throws E; } @@ -57,7 +57,7 @@ public interface Visitor extends AtomicShape.Visitor extends AtomicShape.Visitor R visit(Shape.Visitor v, A arg) throws E { - return visit((AtomicShape.Visitor) v, arg); + public final R visit(test.nojson.Shape.Visitor v, A arg) throws E { + return visit((test.nojson.AtomicShape.Visitor) v, arg); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java similarity index 71% rename from de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java index 1730d500..de6950a1 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java @@ -1,22 +1,22 @@ -package test.nojson; +package test.nojson.impl; /** * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. */ -class Car_Impl extends Shape_Impl implements Car { +public class Car_Impl extends test.nojson.impl.Shape_Impl implements test.nojson.Car { - private Circle _wheel1 = null; + private test.nojson.Circle _wheel1 = null; - private Circle _wheel2 = null; + private test.nojson.Circle _wheel2 = null; - private Rectangle _body = null; + private test.nojson.Rectangle _body = null; /** * Creates a {@link Car_Impl} instance. * - * @see Car#create() + * @see test.nojson.Car#create() */ - protected Car_Impl() { + public Car_Impl() { super(); } @@ -26,18 +26,18 @@ public TypeKind kind() { } @Override - public final Circle getWheel1() { + public final test.nojson.Circle getWheel1() { return _wheel1; } @Override - public Car setWheel1(Circle value) { + public test.nojson.Car setWheel1(test.nojson.Circle value) { internalSetWheel1(value); return this; } /** Internal setter for {@link #getWheel1()} without chain call utility. */ - protected final void internalSetWheel1(Circle value) { + protected final void internalSetWheel1(test.nojson.Circle value) { _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; } @@ -48,18 +48,18 @@ public final boolean hasWheel1() { } @Override - public final Circle getWheel2() { + public final test.nojson.Circle getWheel2() { return _wheel2; } @Override - public Car setWheel2(Circle value) { + public test.nojson.Car setWheel2(test.nojson.Circle value) { internalSetWheel2(value); return this; } /** Internal setter for {@link #getWheel2()} without chain call utility. */ - protected final void internalSetWheel2(Circle value) { + protected final void internalSetWheel2(test.nojson.Circle value) { _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; } @@ -70,18 +70,18 @@ public final boolean hasWheel2() { } @Override - public final Rectangle getBody() { + public final test.nojson.Rectangle getBody() { return _body; } @Override - public Car setBody(Rectangle value) { + public test.nojson.Car setBody(test.nojson.Rectangle value) { internalSetBody(value); return this; } /** Internal setter for {@link #getBody()} without chain call utility. */ - protected final void internalSetBody(Rectangle value) { + protected final void internalSetBody(test.nojson.Rectangle value) { _listener.beforeSet(this, BODY__PROP, value); _body = value; } @@ -92,13 +92,13 @@ public final boolean hasBody() { } @Override - public Car setXCoordinate(int value) { + public test.nojson.Car setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Car setYCoordinate(int value) { + public test.nojson.Car setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -132,9 +132,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; - case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; - case BODY__PROP: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((test.nojson.Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((test.nojson.Circle) value); break; + case BODY__PROP: internalSetBody((test.nojson.Rectangle) value); break; default: super.set(field, value); break; } } @@ -161,9 +161,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } } - /** Helper for creating an object of type {@link Car} from a polymorphic composition. */ - public static Car readCar_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.nojson.Car_Impl result = new Car_Impl(); + /** Helper for creating an object of type {@link test.nojson.Car} from a polymorphic composition. */ + public static test.nojson.Car readCar_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nojson.impl.Car_Impl result = new Car_Impl(); result.readContent(in); return result; } @@ -178,7 +178,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Car} type. */ + /** XML element name representing a {@link test.nojson.Car} type. */ public static final String CAR__XML_ELEMENT = "car"; /** XML attribute or element name of a {@link #getWheel1} property. */ @@ -222,7 +222,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. } } - /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nojson.Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); result.readContentXml(in); @@ -242,15 +242,15 @@ protected void readFieldXmlAttribute(String name, String value) { protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { case WHEEL_1__XML_ATTR: { - setWheel1(test.nojson.Circle_Impl.readCircle_XmlContent(in)); + setWheel1(test.nojson.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case WHEEL_2__XML_ATTR: { - setWheel2(test.nojson.Circle_Impl.readCircle_XmlContent(in)); + setWheel2(test.nojson.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case BODY__XML_ATTR: { - setBody(test.nojson.Rectangle_Impl.readRectangle_XmlContent(in)); + setBody(test.nojson.impl.Rectangle_Impl.readRectangle_XmlContent(in)); break; } default: { @@ -260,7 +260,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(Shape.Visitor v, A arg) throws E { + public R visit(test.nojson.Shape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java similarity index 77% rename from de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java index da4607ed..aaf5bd73 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java @@ -1,18 +1,18 @@ -package test.nojson; +package test.nojson.impl; /** * A circle {@link Shape}. */ -class Circle_Impl extends AtomicShape_Impl implements Circle { +public class Circle_Impl extends test.nojson.impl.AtomicShape_Impl implements test.nojson.Circle { private int _radius = 0; /** * Creates a {@link Circle_Impl} instance. * - * @see Circle#create() + * @see test.nojson.Circle#create() */ - protected Circle_Impl() { + public Circle_Impl() { super(); } @@ -27,7 +27,7 @@ public final int getRadius() { } @Override - public Circle setRadius(int value) { + public test.nojson.Circle setRadius(int value) { internalSetRadius(value); return this; } @@ -39,13 +39,13 @@ protected final void internalSetRadius(int value) { } @Override - public Circle setXCoordinate(int value) { + public test.nojson.Circle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Circle setYCoordinate(int value) { + public test.nojson.Circle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -92,9 +92,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getRadius()); } - /** Helper for creating an object of type {@link Circle} from a polymorphic composition. */ - public static Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.nojson.Circle_Impl result = new Circle_Impl(); + /** Helper for creating an object of type {@link test.nojson.Circle} from a polymorphic composition. */ + public static test.nojson.Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nojson.impl.Circle_Impl result = new Circle_Impl(); result.readContent(in); return result; } @@ -107,7 +107,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Circle} type. */ + /** XML element name representing a {@link test.nojson.Circle} type. */ public static final String CIRCLE__XML_ELEMENT = "circle"; /** XML attribute or element name of a {@link #getRadius} property. */ @@ -129,9 +129,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nojson.Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); result.readContentXml(in); @@ -165,7 +166,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { + public R visit(test.nojson.AtomicShape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java similarity index 69% rename from de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java index 308aaa6c..af30cfea 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java @@ -1,18 +1,18 @@ -package test.nojson; +package test.nojson.impl; /** * A group of shapes. */ -class Group_Impl extends Shape_Impl implements Group { +public class Group_Impl extends test.nojson.impl.Shape_Impl implements test.nojson.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override - protected void beforeAdd(int index, Shape element) { + protected void beforeAdd(int index, test.nojson.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); } @Override - protected void afterRemove(int index, Shape element) { + protected void afterRemove(int index, test.nojson.Shape element) { _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } }; @@ -20,9 +20,9 @@ protected void afterRemove(int index, Shape element) { /** * Creates a {@link Group_Impl} instance. * - * @see Group#create() + * @see test.nojson.Group#create() */ - protected Group_Impl() { + public Group_Impl() { super(); } @@ -32,47 +32,47 @@ public TypeKind kind() { } @Override - public final java.util.List getShapes() { + public final java.util.List getShapes() { return _shapes; } @Override - public Group setShapes(java.util.List value) { + public test.nojson.Group setShapes(java.util.List value) { internalSetShapes(value); return this; } /** Internal setter for {@link #getShapes()} without chain call utility. */ - protected final void internalSetShapes(java.util.List value) { + protected final void internalSetShapes(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); _shapes.clear(); _shapes.addAll(value); } @Override - public Group addShape(Shape value) { + public test.nojson.Group addShape(test.nojson.Shape value) { internalAddShape(value); return this; } - /** Implementation of {@link #addShape(Shape)} without chain call utility. */ - protected final void internalAddShape(Shape value) { + /** Implementation of {@link #addShape(test.nojson.Shape)} without chain call utility. */ + protected final void internalAddShape(test.nojson.Shape value) { _shapes.add(value); } @Override - public final void removeShape(Shape value) { + public final void removeShape(test.nojson.Shape value) { _shapes.remove(value); } @Override - public Group setXCoordinate(int value) { + public test.nojson.Group setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Group setYCoordinate(int value) { + public test.nojson.Group setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -102,7 +102,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(test.nojson.Shape.class, value)); break; default: super.set(field, value); break; } } @@ -117,18 +117,18 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav super.writeFields(out); out.name(SHAPES__ID); { - java.util.List values = getShapes(); + java.util.List values = getShapes(); out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); - for (Shape x : values) { + for (test.nojson.Shape x : values) { x.writeTo(out); } out.endArray(); } } - /** Helper for creating an object of type {@link Group} from a polymorphic composition. */ - public static Group readGroup_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.nojson.Group_Impl result = new Group_Impl(); + /** Helper for creating an object of type {@link test.nojson.Group} from a polymorphic composition. */ + public static test.nojson.Group readGroup_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nojson.impl.Group_Impl result = new Group_Impl(); result.readContent(in); return result; } @@ -148,7 +148,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Group} type. */ + /** XML element name representing a {@link test.nojson.Group} type. */ public static final String GROUP__XML_ELEMENT = "group"; /** XML attribute or element name of a {@link #getShapes} property. */ @@ -176,7 +176,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. out.writeEndElement(); } - /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nojson.Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); result.readContentXml(in); @@ -212,12 +212,12 @@ private void internalReadShapesListXml(javax.xml.stream.XMLStreamReader in) thro break; } - addShape(test.nojson.Shape_Impl.readShape_XmlContent(in)); + addShape(test.nojson.impl.Shape_Impl.readShape_XmlContent(in)); } } @Override - public R visit(Shape.Visitor v, A arg) throws E { + public R visit(test.nojson.Shape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java similarity index 79% rename from de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java index c98a2458..4f605b43 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java @@ -1,9 +1,9 @@ -package test.nojson; +package test.nojson.impl; /** * A rectangle. */ -class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { +public class Rectangle_Impl extends test.nojson.impl.AtomicShape_Impl implements test.nojson.Rectangle { private int _width = 0; @@ -12,9 +12,9 @@ class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { /** * Creates a {@link Rectangle_Impl} instance. * - * @see Rectangle#create() + * @see test.nojson.Rectangle#create() */ - protected Rectangle_Impl() { + public Rectangle_Impl() { super(); } @@ -29,7 +29,7 @@ public final int getWidth() { } @Override - public Rectangle setWidth(int value) { + public test.nojson.Rectangle setWidth(int value) { internalSetWidth(value); return this; } @@ -46,7 +46,7 @@ public final int getHeight() { } @Override - public Rectangle setHeight(int value) { + public test.nojson.Rectangle setHeight(int value) { internalSetHeight(value); return this; } @@ -58,13 +58,13 @@ protected final void internalSetHeight(int value) { } @Override - public Rectangle setXCoordinate(int value) { + public test.nojson.Rectangle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Rectangle setYCoordinate(int value) { + public test.nojson.Rectangle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -116,9 +116,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getHeight()); } - /** Helper for creating an object of type {@link Rectangle} from a polymorphic composition. */ - public static Rectangle readRectangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.nojson.Rectangle_Impl result = new Rectangle_Impl(); + /** Helper for creating an object of type {@link test.nojson.Rectangle} from a polymorphic composition. */ + public static test.nojson.Rectangle readRectangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nojson.impl.Rectangle_Impl result = new Rectangle_Impl(); result.readContent(in); return result; } @@ -132,7 +132,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Rectangle} type. */ + /** XML element name representing a {@link test.nojson.Rectangle} type. */ public static final String RECTANGLE__XML_ELEMENT = "rectangle"; /** XML attribute or element name of a {@link #getWidth} property. */ @@ -158,9 +158,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nojson.Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); result.readContentXml(in); @@ -202,7 +203,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { + public R visit(test.nojson.AtomicShape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java similarity index 87% rename from de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java index e39fa7d6..4eaf380b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java @@ -1,9 +1,9 @@ -package test.nojson; +package test.nojson.impl; /** * An abstract base class for all shapes */ -abstract class Shape_Impl implements Shape { +public abstract class Shape_Impl implements test.nojson.Shape { private int _xCoordinate = 0; @@ -12,7 +12,7 @@ abstract class Shape_Impl implements Shape { /** * Creates a {@link Shape_Impl} instance. */ - protected Shape_Impl() { + public Shape_Impl() { super(); } @@ -25,7 +25,7 @@ public final int getXCoordinate() { } @Override - public Shape setXCoordinate(int value) { + public test.nojson.Shape setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @@ -42,7 +42,7 @@ public final int getYCoordinate() { } @Override - public Shape setYCoordinate(int value) { + public test.nojson.Shape setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -56,7 +56,7 @@ protected final void internalSetYCoordinate(int value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public Shape registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.nojson.Shape registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -66,7 +66,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.nojson.Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -90,7 +90,7 @@ public Object get(String field) { switch (field) { case X_COORDINATE__PROP: return getXCoordinate(); case Y_COORDINATE__PROP: return getYCoordinate(); - default: return Shape.super.get(field); + default: return test.nojson.Shape.super.get(field); } } @@ -142,7 +142,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Shape} type. */ + /** XML element name representing a {@link test.nojson.Shape} type. */ public static final String SHAPE__XML_ELEMENT = "shape"; /** XML attribute or element name of a {@link #getXCoordinate} property. */ @@ -165,25 +165,26 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nojson.Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { case Circle_Impl.CIRCLE__XML_ELEMENT: { - return test.nojson.Circle_Impl.readCircle_XmlContent(in); + return test.nojson.impl.Circle_Impl.readCircle_XmlContent(in); } case Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - return test.nojson.Rectangle_Impl.readRectangle_XmlContent(in); + return test.nojson.impl.Rectangle_Impl.readRectangle_XmlContent(in); } case Group_Impl.GROUP__XML_ELEMENT: { - return test.nojson.Group_Impl.readGroup_XmlContent(in); + return test.nojson.impl.Group_Impl.readGroup_XmlContent(in); } case Car_Impl.CAR__XML_ELEMENT: { - return test.nojson.Car_Impl.readCar_XmlContent(in); + return test.nojson.impl.Car_Impl.readCar_XmlContent(in); } default: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java similarity index 85% rename from de.haumacher.msgbuf.generator/src/test/java/test/nojson/SimpleType_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java index 3671c926..e8b41b7b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java @@ -1,9 +1,9 @@ -package test.nojson; +package test.nojson.impl; /** * A concrete type without abstract super type. */ -class SimpleType_Impl implements SimpleType { +public class SimpleType_Impl implements test.nojson.SimpleType { private String _str = ""; @@ -12,9 +12,9 @@ class SimpleType_Impl implements SimpleType { /** * Creates a {@link SimpleType_Impl} instance. * - * @see SimpleType#create() + * @see test.nojson.SimpleType#create() */ - protected SimpleType_Impl() { + public SimpleType_Impl() { super(); } @@ -24,7 +24,7 @@ public final String getStr() { } @Override - public SimpleType setStr(String value) { + public test.nojson.SimpleType setStr(String value) { internalSetStr(value); return this; } @@ -41,7 +41,7 @@ public final int getX() { } @Override - public SimpleType setX(int value) { + public test.nojson.SimpleType setX(int value) { internalSetX(value); return this; } @@ -55,7 +55,7 @@ protected final void internalSetX(int value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.nojson.SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -65,7 +65,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.nojson.SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -94,7 +94,7 @@ public Object get(String field) { switch (field) { case STR__PROP: return getStr(); case X__PROP: return getX(); - default: return SimpleType.super.get(field); + default: return test.nojson.SimpleType.super.get(field); } } @@ -127,9 +127,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getX()); } - /** Helper for creating an object of type {@link SimpleType} from a polymorphic composition. */ - public static SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.nojson.SimpleType_Impl result = new SimpleType_Impl(); + /** Helper for creating an object of type {@link test.nojson.SimpleType} from a polymorphic composition. */ + public static test.nojson.SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nojson.impl.SimpleType_Impl result = new SimpleType_Impl(); result.readContent(in); return result; } @@ -151,7 +151,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link SimpleType} type. */ + /** XML element name representing a {@link test.nojson.SimpleType} type. */ public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; /** XML attribute or element name of a {@link #getStr} property. */ @@ -179,9 +179,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nojson.SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SimpleType_Impl result = new SimpleType_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/AtomicShape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/AtomicShape.java index 3f2717d1..3fc07971 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/AtomicShape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/AtomicShape.java @@ -5,26 +5,26 @@ */ public interface AtomicShape extends Shape { - /** Visitor interface for the {@link AtomicShape} hierarchy.*/ + /** Visitor interface for the {@link test.nolistener.AtomicShape} hierarchy.*/ public interface Visitor { - /** Visit case for {@link Circle}.*/ - R visit(Circle self, A arg) throws E; + /** Visit case for {@link test.nolistener.Circle}.*/ + R visit(test.nolistener.Circle self, A arg) throws E; - /** Visit case for {@link Rectangle}.*/ - R visit(Rectangle self, A arg) throws E; + /** Visit case for {@link test.nolistener.Rectangle}.*/ + R visit(test.nolistener.Rectangle self, A arg) throws E; } @Override - AtomicShape setXCoordinate(int value); + test.nolistener.AtomicShape setXCoordinate(int value); @Override - AtomicShape setYCoordinate(int value); + test.nolistener.AtomicShape setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - AtomicShape result; + static test.nolistener.AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nolistener.AtomicShape result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -37,15 +37,15 @@ static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throw } /** Reads a new instance from the given reader. */ - static AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.nolistener.AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); int typeField = in.nextName(); assert typeField == 0; int type = in.nextInt(); - AtomicShape result; + test.nolistener.AtomicShape result; switch (type) { - case Circle.CIRCLE__TYPE_ID: result = test.nolistener.Circle_Impl.readCircle_Content(in); break; - case Rectangle.RECTANGLE__TYPE_ID: result = test.nolistener.Rectangle_Impl.readRectangle_Content(in); break; + case test.nolistener.Circle.CIRCLE__TYPE_ID: result = test.nolistener.impl.Circle_Impl.readCircle_Content(in); break; + case test.nolistener.Rectangle.RECTANGLE__TYPE_ID: result = test.nolistener.impl.Rectangle_Impl.readRectangle_Content(in); break; default: result = null; while (in.hasNext()) {in.skipValue(); } } in.endObject(); @@ -55,7 +55,7 @@ static AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) thr /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape readAtomicShape(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.nolistener.AtomicShape_Impl.readAtomicShape_XmlContent(in); + return test.nolistener.impl.AtomicShape_Impl.readAtomicShape_XmlContent(in); } /** Accepts the given visitor. */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java index 204195b2..08e6d751 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java @@ -6,13 +6,13 @@ public interface Car extends Shape { /** - * Creates a {@link Car} instance. + * Creates a {@link test.nolistener.Car} instance. */ - static Car create() { - return new test.nolistener.Car_Impl(); + static test.nolistener.Car create() { + return new test.nolistener.impl.Car_Impl(); } - /** Identifier for the {@link Car} type in JSON format. */ + /** Identifier for the {@link test.nolistener.Car} type in JSON format. */ static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ @@ -24,7 +24,7 @@ static Car create() { /** @see #getBody() */ static final String BODY__PROP = "body"; - /** Identifier for the {@link Car} type in binary format. */ + /** Identifier for the {@link test.nolistener.Car} type in binary format. */ static final int CAR__TYPE_ID = 4; /** Identifier for the property {@link #getWheel1()} in binary format. */ @@ -39,12 +39,12 @@ static Car create() { /** * The front wheel. */ - Circle getWheel1(); + test.nolistener.Circle getWheel1(); /** * @see #getWheel1() */ - Car setWheel1(Circle value); + test.nolistener.Car setWheel1(test.nolistener.Circle value); /** * Checks, whether {@link #getWheel1()} has a value. @@ -54,12 +54,12 @@ static Car create() { /** * The back wheel. */ - Circle getWheel2(); + test.nolistener.Circle getWheel2(); /** * @see #getWheel2() */ - Car setWheel2(Circle value); + test.nolistener.Car setWheel2(test.nolistener.Circle value); /** * Checks, whether {@link #getWheel2()} has a value. @@ -69,12 +69,12 @@ static Car create() { /** * The car body. */ - Rectangle getBody(); + test.nolistener.Rectangle getBody(); /** * @see #getBody() */ - Car setBody(Rectangle value); + test.nolistener.Car setBody(test.nolistener.Rectangle value); /** * Checks, whether {@link #getBody()} has a value. @@ -82,22 +82,22 @@ static Car create() { boolean hasBody(); @Override - Car setXCoordinate(int value); + test.nolistener.Car setXCoordinate(int value); @Override - Car setYCoordinate(int value); + test.nolistener.Car setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.nolistener.Car_Impl result = new test.nolistener.Car_Impl(); + static test.nolistener.Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nolistener.impl.Car_Impl result = new test.nolistener.impl.Car_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.nolistener.Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Car result = test.nolistener.Car_Impl.readCar_Content(in); + test.nolistener.Car result = test.nolistener.impl.Car_Impl.readCar_Content(in); in.endObject(); return result; } @@ -105,7 +105,7 @@ static Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOEx /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car readCar(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.nolistener.Car_Impl.readCar_XmlContent(in); + return test.nolistener.impl.Car_Impl.readCar_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java index 457f3585..4a5b04ba 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java @@ -6,19 +6,19 @@ public interface Circle extends AtomicShape { /** - * Creates a {@link Circle} instance. + * Creates a {@link test.nolistener.Circle} instance. */ - static Circle create() { - return new test.nolistener.Circle_Impl(); + static test.nolistener.Circle create() { + return new test.nolistener.impl.Circle_Impl(); } - /** Identifier for the {@link Circle} type in JSON format. */ + /** Identifier for the {@link test.nolistener.Circle} type in JSON format. */ static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ static final String RADIUS__PROP = "r"; - /** Identifier for the {@link Circle} type in binary format. */ + /** Identifier for the {@link test.nolistener.Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; /** Identifier for the property {@link #getRadius()} in binary format. */ @@ -32,25 +32,25 @@ static Circle create() { /** * @see #getRadius() */ - Circle setRadius(int value); + test.nolistener.Circle setRadius(int value); @Override - Circle setXCoordinate(int value); + test.nolistener.Circle setXCoordinate(int value); @Override - Circle setYCoordinate(int value); + test.nolistener.Circle setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.nolistener.Circle_Impl result = new test.nolistener.Circle_Impl(); + static test.nolistener.Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nolistener.impl.Circle_Impl result = new test.nolistener.impl.Circle_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.nolistener.Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Circle result = test.nolistener.Circle_Impl.readCircle_Content(in); + test.nolistener.Circle result = test.nolistener.impl.Circle_Impl.readCircle_Content(in); in.endObject(); return result; } @@ -58,7 +58,7 @@ static Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.i /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle readCircle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.nolistener.Circle_Impl.readCircle_XmlContent(in); + return test.nolistener.impl.Circle_Impl.readCircle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java index 4cd0b74e..b4b5b1e0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java @@ -6,19 +6,19 @@ public interface Group extends Shape { /** - * Creates a {@link Group} instance. + * Creates a {@link test.nolistener.Group} instance. */ - static Group create() { - return new test.nolistener.Group_Impl(); + static test.nolistener.Group create() { + return new test.nolistener.impl.Group_Impl(); } - /** Identifier for the {@link Group} type in JSON format. */ + /** Identifier for the {@link test.nolistener.Group} type in JSON format. */ static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ static final String SHAPES__PROP = "shapes"; - /** Identifier for the {@link Group} type in binary format. */ + /** Identifier for the {@link test.nolistener.Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; /** Identifier for the property {@link #getShapes()} in binary format. */ @@ -31,40 +31,40 @@ static Group create() { * The origins of these {@link Shape}s get a coordinate offset of ({@link #getXCoordinate()}, {@link #getYCoordinate()}). *

*/ - java.util.List getShapes(); + java.util.List getShapes(); /** * @see #getShapes() */ - Group setShapes(java.util.List value); + test.nolistener.Group setShapes(java.util.List value); /** * Adds a value to the {@link #getShapes()} list. */ - Group addShape(Shape value); + test.nolistener.Group addShape(test.nolistener.Shape value); /** * Removes a value from the {@link #getShapes()} list. */ - void removeShape(Shape value); + void removeShape(test.nolistener.Shape value); @Override - Group setXCoordinate(int value); + test.nolistener.Group setXCoordinate(int value); @Override - Group setYCoordinate(int value); + test.nolistener.Group setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.nolistener.Group_Impl result = new test.nolistener.Group_Impl(); + static test.nolistener.Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nolistener.impl.Group_Impl result = new test.nolistener.impl.Group_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.nolistener.Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Group result = test.nolistener.Group_Impl.readGroup_Content(in); + test.nolistener.Group result = test.nolistener.impl.Group_Impl.readGroup_Content(in); in.endObject(); return result; } @@ -72,7 +72,7 @@ static Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io. /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group readGroup(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.nolistener.Group_Impl.readGroup_XmlContent(in); + return test.nolistener.impl.Group_Impl.readGroup_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java index aff71d41..baaa7a30 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java @@ -6,13 +6,13 @@ public interface Rectangle extends AtomicShape { /** - * Creates a {@link Rectangle} instance. + * Creates a {@link test.nolistener.Rectangle} instance. */ - static Rectangle create() { - return new test.nolistener.Rectangle_Impl(); + static test.nolistener.Rectangle create() { + return new test.nolistener.impl.Rectangle_Impl(); } - /** Identifier for the {@link Rectangle} type in JSON format. */ + /** Identifier for the {@link test.nolistener.Rectangle} type in JSON format. */ static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ @@ -21,7 +21,7 @@ static Rectangle create() { /** @see #getHeight() */ static final String HEIGHT__PROP = "h"; - /** Identifier for the {@link Rectangle} type in binary format. */ + /** Identifier for the {@link test.nolistener.Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; /** Identifier for the property {@link #getWidth()} in binary format. */ @@ -44,7 +44,7 @@ static Rectangle create() { /** * @see #getWidth() */ - Rectangle setWidth(int value); + test.nolistener.Rectangle setWidth(int value); /** * The width of this {@link Rectangle}. @@ -56,25 +56,25 @@ static Rectangle create() { /** * @see #getHeight() */ - Rectangle setHeight(int value); + test.nolistener.Rectangle setHeight(int value); @Override - Rectangle setXCoordinate(int value); + test.nolistener.Rectangle setXCoordinate(int value); @Override - Rectangle setYCoordinate(int value); + test.nolistener.Rectangle setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.nolistener.Rectangle_Impl result = new test.nolistener.Rectangle_Impl(); + static test.nolistener.Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nolistener.impl.Rectangle_Impl result = new test.nolistener.impl.Rectangle_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.nolistener.Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Rectangle result = test.nolistener.Rectangle_Impl.readRectangle_Content(in); + test.nolistener.Rectangle result = test.nolistener.impl.Rectangle_Impl.readRectangle_Content(in); in.endObject(); return result; } @@ -82,7 +82,7 @@ static Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle readRectangle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.nolistener.Rectangle_Impl.readRectangle_XmlContent(in); + return test.nolistener.impl.Rectangle_Impl.readRectangle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java index e9809ba4..1d5ed00a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java @@ -5,32 +5,32 @@ */ public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.data.ReflectiveDataObject, de.haumacher.msgbuf.xml.XmlSerializable { - /** Type codes for the {@link Shape} hierarchy. */ + /** Type codes for the {@link test.nolistener.Shape} hierarchy. */ public enum TypeKind { - /** Type literal for {@link Circle}. */ + /** Type literal for {@link test.nolistener.Circle}. */ CIRCLE, - /** Type literal for {@link Rectangle}. */ + /** Type literal for {@link test.nolistener.Rectangle}. */ RECTANGLE, - /** Type literal for {@link Group}. */ + /** Type literal for {@link test.nolistener.Group}. */ GROUP, - /** Type literal for {@link Car}. */ + /** Type literal for {@link test.nolistener.Car}. */ CAR, ; } - /** Visitor interface for the {@link Shape} hierarchy.*/ - public interface Visitor extends AtomicShape.Visitor { + /** Visitor interface for the {@link test.nolistener.Shape} hierarchy.*/ + public interface Visitor extends test.nolistener.AtomicShape.Visitor { - /** Visit case for {@link Group}.*/ - R visit(Group self, A arg) throws E; + /** Visit case for {@link test.nolistener.Group}.*/ + R visit(test.nolistener.Group self, A arg) throws E; - /** Visit case for {@link Car}.*/ - R visit(Car self, A arg) throws E; + /** Visit case for {@link test.nolistener.Car}.*/ + R visit(test.nolistener.Car self, A arg) throws E; } @@ -57,7 +57,7 @@ public interface Visitor extends AtomicShape.Visitor extends AtomicShape.Visitor R visit(Shape.Visitor v, A arg) throws E { - return visit((AtomicShape.Visitor) v, arg); + public final R visit(test.nolistener.Shape.Visitor v, A arg) throws E { + return visit((test.nolistener.AtomicShape.Visitor) v, arg); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Car_Impl.java similarity index 72% rename from de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Car_Impl.java index f4a92549..56761d79 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Car_Impl.java @@ -1,22 +1,22 @@ -package test.nolistener; +package test.nolistener.impl; /** * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. */ -class Car_Impl extends Shape_Impl implements Car { +public class Car_Impl extends test.nolistener.impl.Shape_Impl implements test.nolistener.Car { - private Circle _wheel1 = null; + private test.nolistener.Circle _wheel1 = null; - private Circle _wheel2 = null; + private test.nolistener.Circle _wheel2 = null; - private Rectangle _body = null; + private test.nolistener.Rectangle _body = null; /** * Creates a {@link Car_Impl} instance. * - * @see Car#create() + * @see test.nolistener.Car#create() */ - protected Car_Impl() { + public Car_Impl() { super(); } @@ -26,18 +26,18 @@ public TypeKind kind() { } @Override - public final Circle getWheel1() { + public final test.nolistener.Circle getWheel1() { return _wheel1; } @Override - public Car setWheel1(Circle value) { + public test.nolistener.Car setWheel1(test.nolistener.Circle value) { internalSetWheel1(value); return this; } /** Internal setter for {@link #getWheel1()} without chain call utility. */ - protected final void internalSetWheel1(Circle value) { + protected final void internalSetWheel1(test.nolistener.Circle value) { _wheel1 = value; } @@ -47,18 +47,18 @@ public final boolean hasWheel1() { } @Override - public final Circle getWheel2() { + public final test.nolistener.Circle getWheel2() { return _wheel2; } @Override - public Car setWheel2(Circle value) { + public test.nolistener.Car setWheel2(test.nolistener.Circle value) { internalSetWheel2(value); return this; } /** Internal setter for {@link #getWheel2()} without chain call utility. */ - protected final void internalSetWheel2(Circle value) { + protected final void internalSetWheel2(test.nolistener.Circle value) { _wheel2 = value; } @@ -68,18 +68,18 @@ public final boolean hasWheel2() { } @Override - public final Rectangle getBody() { + public final test.nolistener.Rectangle getBody() { return _body; } @Override - public Car setBody(Rectangle value) { + public test.nolistener.Car setBody(test.nolistener.Rectangle value) { internalSetBody(value); return this; } /** Internal setter for {@link #getBody()} without chain call utility. */ - protected final void internalSetBody(Rectangle value) { + protected final void internalSetBody(test.nolistener.Rectangle value) { _body = value; } @@ -89,13 +89,13 @@ public final boolean hasBody() { } @Override - public Car setXCoordinate(int value) { + public test.nolistener.Car setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Car setYCoordinate(int value) { + public test.nolistener.Car setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -129,9 +129,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; - case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; - case BODY__PROP: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((test.nolistener.Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((test.nolistener.Circle) value); break; + case BODY__PROP: internalSetBody((test.nolistener.Rectangle) value); break; default: super.set(field, value); break; } } @@ -185,9 +185,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } } - /** Helper for creating an object of type {@link Car} from a polymorphic composition. */ - public static Car readCar_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.nolistener.Car_Impl result = new Car_Impl(); + /** Helper for creating an object of type {@link test.nolistener.Car} from a polymorphic composition. */ + public static test.nolistener.Car readCar_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nolistener.impl.Car_Impl result = new Car_Impl(); result.readContent(in); return result; } @@ -202,7 +202,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Car} type. */ + /** XML element name representing a {@link test.nolistener.Car} type. */ public static final String CAR__XML_ELEMENT = "car"; /** XML attribute or element name of a {@link #getWheel1} property. */ @@ -246,7 +246,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. } } - /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nolistener.Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); result.readContentXml(in); @@ -266,15 +266,15 @@ protected void readFieldXmlAttribute(String name, String value) { protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { case WHEEL_1__XML_ATTR: { - setWheel1(test.nolistener.Circle_Impl.readCircle_XmlContent(in)); + setWheel1(test.nolistener.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case WHEEL_2__XML_ATTR: { - setWheel2(test.nolistener.Circle_Impl.readCircle_XmlContent(in)); + setWheel2(test.nolistener.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case BODY__XML_ATTR: { - setBody(test.nolistener.Rectangle_Impl.readRectangle_XmlContent(in)); + setBody(test.nolistener.impl.Rectangle_Impl.readRectangle_XmlContent(in)); break; } default: { @@ -284,7 +284,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(Shape.Visitor v, A arg) throws E { + public R visit(test.nolistener.Shape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Circle_Impl.java similarity index 78% rename from de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Circle_Impl.java index 65b87311..95c4b4a7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Circle_Impl.java @@ -1,18 +1,18 @@ -package test.nolistener; +package test.nolistener.impl; /** * A circle {@link Shape}. */ -class Circle_Impl extends AtomicShape_Impl implements Circle { +public class Circle_Impl extends test.nolistener.impl.AtomicShape_Impl implements test.nolistener.Circle { private int _radius = 0; /** * Creates a {@link Circle_Impl} instance. * - * @see Circle#create() + * @see test.nolistener.Circle#create() */ - protected Circle_Impl() { + public Circle_Impl() { super(); } @@ -27,7 +27,7 @@ public final int getRadius() { } @Override - public Circle setRadius(int value) { + public test.nolistener.Circle setRadius(int value) { internalSetRadius(value); return this; } @@ -38,13 +38,13 @@ protected final void internalSetRadius(int value) { } @Override - public Circle setXCoordinate(int value) { + public test.nolistener.Circle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Circle setYCoordinate(int value) { + public test.nolistener.Circle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -106,9 +106,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getRadius()); } - /** Helper for creating an object of type {@link Circle} from a polymorphic composition. */ - public static Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.nolistener.Circle_Impl result = new Circle_Impl(); + /** Helper for creating an object of type {@link test.nolistener.Circle} from a polymorphic composition. */ + public static test.nolistener.Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nolistener.impl.Circle_Impl result = new Circle_Impl(); result.readContent(in); return result; } @@ -121,7 +121,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Circle} type. */ + /** XML element name representing a {@link test.nolistener.Circle} type. */ public static final String CIRCLE__XML_ELEMENT = "circle"; /** XML attribute or element name of a {@link #getRadius} property. */ @@ -143,9 +143,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nolistener.Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); result.readContentXml(in); @@ -179,7 +180,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { + public R visit(test.nolistener.AtomicShape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java similarity index 71% rename from de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java index 3fbad377..43e9866c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java @@ -1,18 +1,18 @@ -package test.nolistener; +package test.nolistener.impl; /** * A group of shapes. */ -class Group_Impl extends Shape_Impl implements Group { +public class Group_Impl extends test.nolistener.impl.Shape_Impl implements test.nolistener.Group { - private final java.util.List _shapes = new java.util.ArrayList<>(); + private final java.util.List _shapes = new java.util.ArrayList<>(); /** * Creates a {@link Group_Impl} instance. * - * @see Group#create() + * @see test.nolistener.Group#create() */ - protected Group_Impl() { + public Group_Impl() { super(); } @@ -22,47 +22,47 @@ public TypeKind kind() { } @Override - public final java.util.List getShapes() { + public final java.util.List getShapes() { return _shapes; } @Override - public Group setShapes(java.util.List value) { + public test.nolistener.Group setShapes(java.util.List value) { internalSetShapes(value); return this; } /** Internal setter for {@link #getShapes()} without chain call utility. */ - protected final void internalSetShapes(java.util.List value) { + protected final void internalSetShapes(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); _shapes.clear(); _shapes.addAll(value); } @Override - public Group addShape(Shape value) { + public test.nolistener.Group addShape(test.nolistener.Shape value) { internalAddShape(value); return this; } - /** Implementation of {@link #addShape(Shape)} without chain call utility. */ - protected final void internalAddShape(Shape value) { + /** Implementation of {@link #addShape(test.nolistener.Shape)} without chain call utility. */ + protected final void internalAddShape(test.nolistener.Shape value) { _shapes.add(value); } @Override - public final void removeShape(Shape value) { + public final void removeShape(test.nolistener.Shape value) { _shapes.remove(value); } @Override - public Group setXCoordinate(int value) { + public test.nolistener.Group setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Group setYCoordinate(int value) { + public test.nolistener.Group setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -92,7 +92,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(test.nolistener.Shape.class, value)); break; default: super.set(field, value); break; } } @@ -102,7 +102,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. super.writeFields(out); out.name(SHAPES__PROP); out.beginArray(); - for (Shape x : getShapes()) { + for (test.nolistener.Shape x : getShapes()) { x.writeTo(out); } out.endArray(); @@ -133,18 +133,18 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav super.writeFields(out); out.name(SHAPES__ID); { - java.util.List values = getShapes(); + java.util.List values = getShapes(); out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); - for (Shape x : values) { + for (test.nolistener.Shape x : values) { x.writeTo(out); } out.endArray(); } } - /** Helper for creating an object of type {@link Group} from a polymorphic composition. */ - public static Group readGroup_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.nolistener.Group_Impl result = new Group_Impl(); + /** Helper for creating an object of type {@link test.nolistener.Group} from a polymorphic composition. */ + public static test.nolistener.Group readGroup_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nolistener.impl.Group_Impl result = new Group_Impl(); result.readContent(in); return result; } @@ -164,7 +164,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Group} type. */ + /** XML element name representing a {@link test.nolistener.Group} type. */ public static final String GROUP__XML_ELEMENT = "group"; /** XML attribute or element name of a {@link #getShapes} property. */ @@ -192,7 +192,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. out.writeEndElement(); } - /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nolistener.Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); result.readContentXml(in); @@ -228,12 +228,12 @@ private void internalReadShapesListXml(javax.xml.stream.XMLStreamReader in) thro break; } - addShape(test.nolistener.Shape_Impl.readShape_XmlContent(in)); + addShape(test.nolistener.impl.Shape_Impl.readShape_XmlContent(in)); } } @Override - public R visit(Shape.Visitor v, A arg) throws E { + public R visit(test.nolistener.Shape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Rectangle_Impl.java similarity index 80% rename from de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Rectangle_Impl.java index 979caa95..d5279800 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Rectangle_Impl.java @@ -1,9 +1,9 @@ -package test.nolistener; +package test.nolistener.impl; /** * A rectangle. */ -class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { +public class Rectangle_Impl extends test.nolistener.impl.AtomicShape_Impl implements test.nolistener.Rectangle { private int _width = 0; @@ -12,9 +12,9 @@ class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { /** * Creates a {@link Rectangle_Impl} instance. * - * @see Rectangle#create() + * @see test.nolistener.Rectangle#create() */ - protected Rectangle_Impl() { + public Rectangle_Impl() { super(); } @@ -29,7 +29,7 @@ public final int getWidth() { } @Override - public Rectangle setWidth(int value) { + public test.nolistener.Rectangle setWidth(int value) { internalSetWidth(value); return this; } @@ -45,7 +45,7 @@ public final int getHeight() { } @Override - public Rectangle setHeight(int value) { + public test.nolistener.Rectangle setHeight(int value) { internalSetHeight(value); return this; } @@ -56,13 +56,13 @@ protected final void internalSetHeight(int value) { } @Override - public Rectangle setXCoordinate(int value) { + public test.nolistener.Rectangle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Rectangle setYCoordinate(int value) { + public test.nolistener.Rectangle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -132,9 +132,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getHeight()); } - /** Helper for creating an object of type {@link Rectangle} from a polymorphic composition. */ - public static Rectangle readRectangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.nolistener.Rectangle_Impl result = new Rectangle_Impl(); + /** Helper for creating an object of type {@link test.nolistener.Rectangle} from a polymorphic composition. */ + public static test.nolistener.Rectangle readRectangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nolistener.impl.Rectangle_Impl result = new Rectangle_Impl(); result.readContent(in); return result; } @@ -148,7 +148,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Rectangle} type. */ + /** XML element name representing a {@link test.nolistener.Rectangle} type. */ public static final String RECTANGLE__XML_ELEMENT = "rectangle"; /** XML attribute or element name of a {@link #getWidth} property. */ @@ -174,9 +174,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nolistener.Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); result.readContentXml(in); @@ -218,7 +219,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { + public R visit(test.nolistener.AtomicShape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java similarity index 88% rename from de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java index 17054c5f..4a7039fd 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java @@ -1,9 +1,9 @@ -package test.nolistener; +package test.nolistener.impl; /** * An abstract base class for all shapes */ -abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements Shape { +public abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nolistener.Shape { private int _xCoordinate = 0; @@ -12,7 +12,7 @@ abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject im /** * Creates a {@link Shape_Impl} instance. */ - protected Shape_Impl() { + public Shape_Impl() { super(); } @@ -25,7 +25,7 @@ public final int getXCoordinate() { } @Override - public Shape setXCoordinate(int value) { + public test.nolistener.Shape setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @@ -41,7 +41,7 @@ public final int getYCoordinate() { } @Override - public Shape setYCoordinate(int value) { + public test.nolistener.Shape setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -66,7 +66,7 @@ public Object get(String field) { switch (field) { case X_COORDINATE__PROP: return getXCoordinate(); case Y_COORDINATE__PROP: return getYCoordinate(); - default: return Shape.super.get(field); + default: return test.nolistener.Shape.super.get(field); } } @@ -144,7 +144,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Shape} type. */ + /** XML element name representing a {@link test.nolistener.Shape} type. */ public static final String SHAPE__XML_ELEMENT = "shape"; /** XML attribute or element name of a {@link #getXCoordinate} property. */ @@ -167,25 +167,26 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nolistener.Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { case Circle_Impl.CIRCLE__XML_ELEMENT: { - return test.nolistener.Circle_Impl.readCircle_XmlContent(in); + return test.nolistener.impl.Circle_Impl.readCircle_XmlContent(in); } case Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - return test.nolistener.Rectangle_Impl.readRectangle_XmlContent(in); + return test.nolistener.impl.Rectangle_Impl.readRectangle_XmlContent(in); } case Group_Impl.GROUP__XML_ELEMENT: { - return test.nolistener.Group_Impl.readGroup_XmlContent(in); + return test.nolistener.impl.Group_Impl.readGroup_XmlContent(in); } case Car_Impl.CAR__XML_ELEMENT: { - return test.nolistener.Car_Impl.readCar_XmlContent(in); + return test.nolistener.impl.Car_Impl.readCar_XmlContent(in); } default: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/SimpleType_Impl.java similarity index 86% rename from de.haumacher.msgbuf.generator/src/test/java/test/nolistener/SimpleType_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/SimpleType_Impl.java index 8fe0ca26..68ad9798 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/SimpleType_Impl.java @@ -1,9 +1,9 @@ -package test.nolistener; +package test.nolistener.impl; /** * A concrete type without abstract super type. */ -class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements SimpleType { +public class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nolistener.SimpleType { private String _str = ""; @@ -12,9 +12,9 @@ class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implem /** * Creates a {@link SimpleType_Impl} instance. * - * @see SimpleType#create() + * @see test.nolistener.SimpleType#create() */ - protected SimpleType_Impl() { + public SimpleType_Impl() { super(); } @@ -24,7 +24,7 @@ public final String getStr() { } @Override - public SimpleType setStr(String value) { + public test.nolistener.SimpleType setStr(String value) { internalSetStr(value); return this; } @@ -40,7 +40,7 @@ public final int getX() { } @Override - public SimpleType setX(int value) { + public test.nolistener.SimpleType setX(int value) { internalSetX(value); return this; } @@ -70,7 +70,7 @@ public Object get(String field) { switch (field) { case STR__PROP: return getStr(); case X__PROP: return getX(); - default: return SimpleType.super.get(field); + default: return test.nolistener.SimpleType.super.get(field); } } @@ -126,9 +126,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getX()); } - /** Helper for creating an object of type {@link SimpleType} from a polymorphic composition. */ - public static SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.nolistener.SimpleType_Impl result = new SimpleType_Impl(); + /** Helper for creating an object of type {@link test.nolistener.SimpleType} from a polymorphic composition. */ + public static test.nolistener.SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nolistener.impl.SimpleType_Impl result = new SimpleType_Impl(); result.readContent(in); return result; } @@ -150,7 +150,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link SimpleType} type. */ + /** XML element name representing a {@link test.nolistener.SimpleType} type. */ public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; /** XML attribute or element name of a {@link #getStr} property. */ @@ -178,9 +178,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nolistener.SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SimpleType_Impl result = new SimpleType_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape.java index a1bff701..53bcbe1c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/AtomicShape.java @@ -5,14 +5,14 @@ */ public abstract class AtomicShape extends Shape { - /** Visitor interface for the {@link AtomicShape} hierarchy.*/ + /** Visitor interface for the {@link test.noreflection.AtomicShape} hierarchy.*/ public interface Visitor { - /** Visit case for {@link Circle}.*/ - R visit(Circle self, A arg) throws E; + /** Visit case for {@link test.noreflection.Circle}.*/ + R visit(test.noreflection.Circle self, A arg) throws E; - /** Visit case for {@link Rectangle}.*/ - R visit(Rectangle self, A arg) throws E; + /** Visit case for {@link test.noreflection.Rectangle}.*/ + R visit(test.noreflection.Rectangle self, A arg) throws E; } @@ -24,20 +24,20 @@ protected AtomicShape() { } @Override - public AtomicShape setXCoordinate(int value) { + public test.noreflection.AtomicShape setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public AtomicShape setYCoordinate(int value) { + public test.noreflection.AtomicShape setYCoordinate(int value) { internalSetYCoordinate(value); return this; } /** Reads a new instance from the given reader. */ - public static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - AtomicShape result; + public static test.noreflection.AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.noreflection.AtomicShape result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -53,8 +53,8 @@ public static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in public abstract R visit(Visitor v, A arg) throws E; @Override - public final R visit(Shape.Visitor v, A arg) throws E { - return visit((AtomicShape.Visitor) v, arg); + public final R visit(test.noreflection.Shape.Visitor v, A arg) throws E { + return visit((test.noreflection.AtomicShape.Visitor) v, arg); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car.java index 1e3e2560..6253ab2f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Car.java @@ -6,13 +6,13 @@ public class Car extends Shape { /** - * Creates a {@link Car} instance. + * Creates a {@link test.noreflection.Car} instance. */ - public static Car create() { + public static test.noreflection.Car create() { return new test.noreflection.Car(); } - /** Identifier for the {@link Car} type in JSON format. */ + /** Identifier for the {@link test.noreflection.Car} type in JSON format. */ public static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ @@ -24,16 +24,16 @@ public static Car create() { /** @see #getBody() */ private static final String BODY__PROP = "body"; - private Circle _wheel1 = null; + private test.noreflection.Circle _wheel1 = null; - private Circle _wheel2 = null; + private test.noreflection.Circle _wheel2 = null; - private Rectangle _body = null; + private test.noreflection.Rectangle _body = null; /** * Creates a {@link Car} instance. * - * @see Car#create() + * @see test.noreflection.Car#create() */ protected Car() { super(); @@ -42,20 +42,20 @@ protected Car() { /** * The front wheel. */ - public final Circle getWheel1() { + public final test.noreflection.Circle getWheel1() { return _wheel1; } /** * @see #getWheel1() */ - public Car setWheel1(Circle value) { + public test.noreflection.Car setWheel1(test.noreflection.Circle value) { internalSetWheel1(value); return this; } /** Internal setter for {@link #getWheel1()} without chain call utility. */ - protected final void internalSetWheel1(Circle value) { + protected final void internalSetWheel1(test.noreflection.Circle value) { _wheel1 = value; } @@ -69,20 +69,20 @@ public final boolean hasWheel1() { /** * The back wheel. */ - public final Circle getWheel2() { + public final test.noreflection.Circle getWheel2() { return _wheel2; } /** * @see #getWheel2() */ - public Car setWheel2(Circle value) { + public test.noreflection.Car setWheel2(test.noreflection.Circle value) { internalSetWheel2(value); return this; } /** Internal setter for {@link #getWheel2()} without chain call utility. */ - protected final void internalSetWheel2(Circle value) { + protected final void internalSetWheel2(test.noreflection.Circle value) { _wheel2 = value; } @@ -96,20 +96,20 @@ public final boolean hasWheel2() { /** * The car body. */ - public final Rectangle getBody() { + public final test.noreflection.Rectangle getBody() { return _body; } /** * @see #getBody() */ - public Car setBody(Rectangle value) { + public test.noreflection.Car setBody(test.noreflection.Rectangle value) { internalSetBody(value); return this; } /** Internal setter for {@link #getBody()} without chain call utility. */ - protected final void internalSetBody(Rectangle value) { + protected final void internalSetBody(test.noreflection.Rectangle value) { _body = value; } @@ -121,13 +121,13 @@ public final boolean hasBody() { } @Override - public Car setXCoordinate(int value) { + public test.noreflection.Car setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Car setYCoordinate(int value) { + public test.noreflection.Car setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -138,7 +138,7 @@ public String jsonType() { } /** Reads a new instance from the given reader. */ - public static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static test.noreflection.Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.noreflection.Car result = new test.noreflection.Car(); result.readContent(in); return result; @@ -172,7 +172,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t } @Override - public R visit(Shape.Visitor v, A arg) throws E { + public R visit(test.noreflection.Shape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle.java index 328b3f9f..ae8eb36a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Circle.java @@ -6,13 +6,13 @@ public class Circle extends AtomicShape { /** - * Creates a {@link Circle} instance. + * Creates a {@link test.noreflection.Circle} instance. */ - public static Circle create() { + public static test.noreflection.Circle create() { return new test.noreflection.Circle(); } - /** Identifier for the {@link Circle} type in JSON format. */ + /** Identifier for the {@link test.noreflection.Circle} type in JSON format. */ public static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ @@ -23,7 +23,7 @@ public static Circle create() { /** * Creates a {@link Circle} instance. * - * @see Circle#create() + * @see test.noreflection.Circle#create() */ protected Circle() { super(); @@ -39,7 +39,7 @@ public final int getRadius() { /** * @see #getRadius() */ - public Circle setRadius(int value) { + public test.noreflection.Circle setRadius(int value) { internalSetRadius(value); return this; } @@ -50,13 +50,13 @@ protected final void internalSetRadius(int value) { } @Override - public Circle setXCoordinate(int value) { + public test.noreflection.Circle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Circle setYCoordinate(int value) { + public test.noreflection.Circle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -67,7 +67,7 @@ public String jsonType() { } /** Reads a new instance from the given reader. */ - public static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static test.noreflection.Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.noreflection.Circle result = new test.noreflection.Circle(); result.readContent(in); return result; @@ -89,7 +89,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t } @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { + public R visit(test.noreflection.AtomicShape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group.java index f53a3ce8..e4639ee3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group.java @@ -6,24 +6,24 @@ public class Group extends Shape { /** - * Creates a {@link Group} instance. + * Creates a {@link test.noreflection.Group} instance. */ - public static Group create() { + public static test.noreflection.Group create() { return new test.noreflection.Group(); } - /** Identifier for the {@link Group} type in JSON format. */ + /** Identifier for the {@link test.noreflection.Group} type in JSON format. */ public static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ private static final String SHAPES__PROP = "shapes"; - private final java.util.List _shapes = new java.util.ArrayList<>(); + private final java.util.List _shapes = new java.util.ArrayList<>(); /** * Creates a {@link Group} instance. * - * @see Group#create() + * @see test.noreflection.Group#create() */ protected Group() { super(); @@ -36,20 +36,20 @@ protected Group() { * The origins of these {@link Shape}s get a coordinate offset of ({@link #getXCoordinate()}, {@link #getYCoordinate()}). *

*/ - public final java.util.List getShapes() { + public final java.util.List getShapes() { return _shapes; } /** * @see #getShapes() */ - public Group setShapes(java.util.List value) { + public test.noreflection.Group setShapes(java.util.List value) { internalSetShapes(value); return this; } /** Internal setter for {@link #getShapes()} without chain call utility. */ - protected final void internalSetShapes(java.util.List value) { + protected final void internalSetShapes(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); _shapes.clear(); _shapes.addAll(value); @@ -58,31 +58,31 @@ protected final void internalSetShapes(java.util.List value) { /** * Adds a value to the {@link #getShapes()} list. */ - public Group addShape(Shape value) { + public test.noreflection.Group addShape(test.noreflection.Shape value) { internalAddShape(value); return this; } - /** Implementation of {@link #addShape(Shape)} without chain call utility. */ - protected final void internalAddShape(Shape value) { + /** Implementation of {@link #addShape(test.noreflection.Shape)} without chain call utility. */ + protected final void internalAddShape(test.noreflection.Shape value) { _shapes.add(value); } /** * Removes a value from the {@link #getShapes()} list. */ - public final void removeShape(Shape value) { + public final void removeShape(test.noreflection.Shape value) { _shapes.remove(value); } @Override - public Group setXCoordinate(int value) { + public test.noreflection.Group setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Group setYCoordinate(int value) { + public test.noreflection.Group setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -93,7 +93,7 @@ public String jsonType() { } /** Reads a new instance from the given reader. */ - public static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static test.noreflection.Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.noreflection.Group result = new test.noreflection.Group(); result.readContent(in); return result; @@ -104,7 +104,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. super.writeFields(out); out.name(SHAPES__PROP); out.beginArray(); - for (Shape x : getShapes()) { + for (test.noreflection.Shape x : getShapes()) { x.writeTo(out); } out.endArray(); @@ -126,7 +126,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t } @Override - public R visit(Shape.Visitor v, A arg) throws E { + public R visit(test.noreflection.Shape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle.java index cfe4e7ac..e395116a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Rectangle.java @@ -6,13 +6,13 @@ public class Rectangle extends AtomicShape { /** - * Creates a {@link Rectangle} instance. + * Creates a {@link test.noreflection.Rectangle} instance. */ - public static Rectangle create() { + public static test.noreflection.Rectangle create() { return new test.noreflection.Rectangle(); } - /** Identifier for the {@link Rectangle} type in JSON format. */ + /** Identifier for the {@link test.noreflection.Rectangle} type in JSON format. */ public static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ @@ -28,7 +28,7 @@ public static Rectangle create() { /** * Creates a {@link Rectangle} instance. * - * @see Rectangle#create() + * @see test.noreflection.Rectangle#create() */ protected Rectangle() { super(); @@ -50,7 +50,7 @@ public final int getWidth() { /** * @see #getWidth() */ - public Rectangle setWidth(int value) { + public test.noreflection.Rectangle setWidth(int value) { internalSetWidth(value); return this; } @@ -72,7 +72,7 @@ public final int getHeight() { /** * @see #getHeight() */ - public Rectangle setHeight(int value) { + public test.noreflection.Rectangle setHeight(int value) { internalSetHeight(value); return this; } @@ -83,13 +83,13 @@ protected final void internalSetHeight(int value) { } @Override - public Rectangle setXCoordinate(int value) { + public test.noreflection.Rectangle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Rectangle setYCoordinate(int value) { + public test.noreflection.Rectangle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -100,7 +100,7 @@ public String jsonType() { } /** Reads a new instance from the given reader. */ - public static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static test.noreflection.Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.noreflection.Rectangle result = new test.noreflection.Rectangle(); result.readContent(in); return result; @@ -125,7 +125,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t } @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { + public R visit(test.noreflection.AtomicShape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape.java index fcc18198..b9b5cb52 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Shape.java @@ -5,14 +5,14 @@ */ public abstract class Shape extends de.haumacher.msgbuf.data.AbstractDataObject { - /** Visitor interface for the {@link Shape} hierarchy.*/ - public interface Visitor extends AtomicShape.Visitor { + /** Visitor interface for the {@link test.noreflection.Shape} hierarchy.*/ + public interface Visitor extends test.noreflection.AtomicShape.Visitor { - /** Visit case for {@link Group}.*/ - R visit(Group self, A arg) throws E; + /** Visit case for {@link test.noreflection.Group}.*/ + R visit(test.noreflection.Group self, A arg) throws E; - /** Visit case for {@link Car}.*/ - R visit(Car self, A arg) throws E; + /** Visit case for {@link test.noreflection.Car}.*/ + R visit(test.noreflection.Car self, A arg) throws E; } @@ -43,7 +43,7 @@ public final int getXCoordinate() { /** * @see #getXCoordinate() */ - public Shape setXCoordinate(int value) { + public test.noreflection.Shape setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @@ -63,7 +63,7 @@ public final int getYCoordinate() { /** * @see #getYCoordinate() */ - public Shape setYCoordinate(int value) { + public test.noreflection.Shape setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -77,8 +77,8 @@ protected final void internalSetYCoordinate(int value) { public abstract String jsonType(); /** Reads a new instance from the given reader. */ - public static Shape readShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - Shape result; + public static test.noreflection.Shape readShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.noreflection.Shape result; in.beginArray(); String type = in.nextString(); switch (type) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/SimpleType.java index 76d8b95a..f16a54cc 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/SimpleType.java @@ -6,13 +6,13 @@ public class SimpleType extends de.haumacher.msgbuf.data.AbstractDataObject { /** - * Creates a {@link SimpleType} instance. + * Creates a {@link test.noreflection.SimpleType} instance. */ - public static SimpleType create() { + public static test.noreflection.SimpleType create() { return new test.noreflection.SimpleType(); } - /** Identifier for the {@link SimpleType} type in JSON format. */ + /** Identifier for the {@link test.noreflection.SimpleType} type in JSON format. */ public static final String SIMPLE_TYPE__TYPE = "SimpleType"; /** @see #getStr() */ @@ -28,7 +28,7 @@ public static SimpleType create() { /** * Creates a {@link SimpleType} instance. * - * @see SimpleType#create() + * @see test.noreflection.SimpleType#create() */ protected SimpleType() { super(); @@ -44,7 +44,7 @@ public final String getStr() { /** * @see #getStr() */ - public SimpleType setStr(String value) { + public test.noreflection.SimpleType setStr(String value) { internalSetStr(value); return this; } @@ -64,7 +64,7 @@ public final int getX() { /** * @see #getX() */ - public SimpleType setX(int value) { + public test.noreflection.SimpleType setX(int value) { internalSetX(value); return this; } @@ -75,7 +75,7 @@ protected final void internalSetX(int value) { } /** Reads a new instance from the given reader. */ - public static SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static test.noreflection.SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { test.noreflection.SimpleType result = new test.noreflection.SimpleType(); result.readContent(in); return result; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/AtomicShape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/AtomicShape.java index e8e284be..41c855be 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/AtomicShape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/AtomicShape.java @@ -6,9 +6,9 @@ public interface AtomicShape extends Shape { @Override - AtomicShape setXCoordinate(int value); + test.nothing.AtomicShape setXCoordinate(int value); @Override - AtomicShape setYCoordinate(int value); + test.nothing.AtomicShape setYCoordinate(int value); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/AtomicShape_Impl.java deleted file mode 100644 index 3ee7c427..00000000 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/AtomicShape_Impl.java +++ /dev/null @@ -1,27 +0,0 @@ -package test.nothing; - -/** - * A {@link Shape} that has no sub-shapes. - */ -abstract class AtomicShape_Impl extends Shape_Impl implements AtomicShape { - - /** - * Creates a {@link AtomicShape_Impl} instance. - */ - protected AtomicShape_Impl() { - super(); - } - - @Override - public AtomicShape setXCoordinate(int value) { - internalSetXCoordinate(value); - return this; - } - - @Override - public AtomicShape setYCoordinate(int value) { - internalSetYCoordinate(value); - return this; - } - -} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Car.java index ebc57258..59a7f224 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Car.java @@ -6,21 +6,21 @@ public interface Car extends Shape { /** - * Creates a {@link Car} instance. + * Creates a {@link test.nothing.Car} instance. */ - static Car create() { - return new test.nothing.Car_Impl(); + static test.nothing.Car create() { + return new test.nothing.impl.Car_Impl(); } /** * The front wheel. */ - Circle getWheel1(); + test.nothing.Circle getWheel1(); /** * @see #getWheel1() */ - Car setWheel1(Circle value); + test.nothing.Car setWheel1(test.nothing.Circle value); /** * Checks, whether {@link #getWheel1()} has a value. @@ -30,12 +30,12 @@ static Car create() { /** * The back wheel. */ - Circle getWheel2(); + test.nothing.Circle getWheel2(); /** * @see #getWheel2() */ - Car setWheel2(Circle value); + test.nothing.Car setWheel2(test.nothing.Circle value); /** * Checks, whether {@link #getWheel2()} has a value. @@ -45,12 +45,12 @@ static Car create() { /** * The car body. */ - Rectangle getBody(); + test.nothing.Rectangle getBody(); /** * @see #getBody() */ - Car setBody(Rectangle value); + test.nothing.Car setBody(test.nothing.Rectangle value); /** * Checks, whether {@link #getBody()} has a value. @@ -58,9 +58,9 @@ static Car create() { boolean hasBody(); @Override - Car setXCoordinate(int value); + test.nothing.Car setXCoordinate(int value); @Override - Car setYCoordinate(int value); + test.nothing.Car setYCoordinate(int value); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Circle.java index d1addc2f..29839292 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Circle.java @@ -6,10 +6,10 @@ public interface Circle extends AtomicShape { /** - * Creates a {@link Circle} instance. + * Creates a {@link test.nothing.Circle} instance. */ - static Circle create() { - return new test.nothing.Circle_Impl(); + static test.nothing.Circle create() { + return new test.nothing.impl.Circle_Impl(); } /** @@ -20,12 +20,12 @@ static Circle create() { /** * @see #getRadius() */ - Circle setRadius(int value); + test.nothing.Circle setRadius(int value); @Override - Circle setXCoordinate(int value); + test.nothing.Circle setXCoordinate(int value); @Override - Circle setYCoordinate(int value); + test.nothing.Circle setYCoordinate(int value); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Group.java index 85025800..5c2159a7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Group.java @@ -6,10 +6,10 @@ public interface Group extends Shape { /** - * Creates a {@link Group} instance. + * Creates a {@link test.nothing.Group} instance. */ - static Group create() { - return new test.nothing.Group_Impl(); + static test.nothing.Group create() { + return new test.nothing.impl.Group_Impl(); } /** @@ -19,27 +19,27 @@ static Group create() { * The origins of these {@link Shape}s get a coordinate offset of ({@link #getXCoordinate()}, {@link #getYCoordinate()}). *

*/ - java.util.List getShapes(); + java.util.List getShapes(); /** * @see #getShapes() */ - Group setShapes(java.util.List value); + test.nothing.Group setShapes(java.util.List value); /** * Adds a value to the {@link #getShapes()} list. */ - Group addShape(Shape value); + test.nothing.Group addShape(test.nothing.Shape value); /** * Removes a value from the {@link #getShapes()} list. */ - void removeShape(Shape value); + void removeShape(test.nothing.Shape value); @Override - Group setXCoordinate(int value); + test.nothing.Group setXCoordinate(int value); @Override - Group setYCoordinate(int value); + test.nothing.Group setYCoordinate(int value); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Group_Impl.java deleted file mode 100644 index 0a764363..00000000 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Group_Impl.java +++ /dev/null @@ -1,65 +0,0 @@ -package test.nothing; - -/** - * A group of shapes. - */ -class Group_Impl extends Shape_Impl implements Group { - - private final java.util.List _shapes = new java.util.ArrayList<>(); - - /** - * Creates a {@link Group_Impl} instance. - * - * @see Group#create() - */ - protected Group_Impl() { - super(); - } - - @Override - public final java.util.List getShapes() { - return _shapes; - } - - @Override - public Group setShapes(java.util.List value) { - internalSetShapes(value); - return this; - } - - /** Internal setter for {@link #getShapes()} without chain call utility. */ - protected final void internalSetShapes(java.util.List value) { - if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); - _shapes.clear(); - _shapes.addAll(value); - } - - @Override - public Group addShape(Shape value) { - internalAddShape(value); - return this; - } - - /** Implementation of {@link #addShape(Shape)} without chain call utility. */ - protected final void internalAddShape(Shape value) { - _shapes.add(value); - } - - @Override - public final void removeShape(Shape value) { - _shapes.remove(value); - } - - @Override - public Group setXCoordinate(int value) { - internalSetXCoordinate(value); - return this; - } - - @Override - public Group setYCoordinate(int value) { - internalSetYCoordinate(value); - return this; - } - -} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Rectangle.java index 79ef011e..4d285c66 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Rectangle.java @@ -6,10 +6,10 @@ public interface Rectangle extends AtomicShape { /** - * Creates a {@link Rectangle} instance. + * Creates a {@link test.nothing.Rectangle} instance. */ - static Rectangle create() { - return new test.nothing.Rectangle_Impl(); + static test.nothing.Rectangle create() { + return new test.nothing.impl.Rectangle_Impl(); } /** @@ -26,7 +26,7 @@ static Rectangle create() { /** * @see #getWidth() */ - Rectangle setWidth(int value); + test.nothing.Rectangle setWidth(int value); /** * The width of this {@link Rectangle}. @@ -38,12 +38,12 @@ static Rectangle create() { /** * @see #getHeight() */ - Rectangle setHeight(int value); + test.nothing.Rectangle setHeight(int value); @Override - Rectangle setXCoordinate(int value); + test.nothing.Rectangle setXCoordinate(int value); @Override - Rectangle setYCoordinate(int value); + test.nothing.Rectangle setYCoordinate(int value); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Shape.java index 94d216ae..a8ad0657 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Shape.java @@ -13,7 +13,7 @@ public interface Shape { /** * @see #getXCoordinate() */ - Shape setXCoordinate(int value); + test.nothing.Shape setXCoordinate(int value); /** * Y coordinate of the origin of the coordinate system of this {@link Shape}. @@ -23,6 +23,6 @@ public interface Shape { /** * @see #getYCoordinate() */ - Shape setYCoordinate(int value); + test.nothing.Shape setYCoordinate(int value); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/SimpleType.java index ccea0d09..04710dc7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/SimpleType.java @@ -6,10 +6,10 @@ public interface SimpleType { /** - * Creates a {@link SimpleType} instance. + * Creates a {@link test.nothing.SimpleType} instance. */ - static SimpleType create() { - return new test.nothing.SimpleType_Impl(); + static test.nothing.SimpleType create() { + return new test.nothing.impl.SimpleType_Impl(); } /** @@ -20,7 +20,7 @@ static SimpleType create() { /** * @see #getStr() */ - SimpleType setStr(String value); + test.nothing.SimpleType setStr(String value); /** * An int property @@ -30,6 +30,6 @@ static SimpleType create() { /** * @see #getX() */ - SimpleType setX(int value); + test.nothing.SimpleType setX(int value); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/AtomicShape_Impl.java new file mode 100644 index 00000000..2dd06774 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/AtomicShape_Impl.java @@ -0,0 +1,27 @@ +package test.nothing.impl; + +/** + * A {@link Shape} that has no sub-shapes. + */ +public abstract class AtomicShape_Impl extends test.nothing.impl.Shape_Impl implements test.nothing.AtomicShape { + + /** + * Creates a {@link AtomicShape_Impl} instance. + */ + public AtomicShape_Impl() { + super(); + } + + @Override + public test.nothing.AtomicShape setXCoordinate(int value) { + internalSetXCoordinate(value); + return this; + } + + @Override + public test.nothing.AtomicShape setYCoordinate(int value) { + internalSetYCoordinate(value); + return this; + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Car_Impl.java similarity index 53% rename from de.haumacher.msgbuf.generator/src/test/java/test/nothing/Car_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Car_Impl.java index 7245ec0b..162971c8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Car_Impl.java @@ -1,38 +1,38 @@ -package test.nothing; +package test.nothing.impl; /** * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. */ -class Car_Impl extends Shape_Impl implements Car { +public class Car_Impl extends test.nothing.impl.Shape_Impl implements test.nothing.Car { - private Circle _wheel1 = null; + private test.nothing.Circle _wheel1 = null; - private Circle _wheel2 = null; + private test.nothing.Circle _wheel2 = null; - private Rectangle _body = null; + private test.nothing.Rectangle _body = null; /** * Creates a {@link Car_Impl} instance. * - * @see Car#create() + * @see test.nothing.Car#create() */ - protected Car_Impl() { + public Car_Impl() { super(); } @Override - public final Circle getWheel1() { + public final test.nothing.Circle getWheel1() { return _wheel1; } @Override - public Car setWheel1(Circle value) { + public test.nothing.Car setWheel1(test.nothing.Circle value) { internalSetWheel1(value); return this; } /** Internal setter for {@link #getWheel1()} without chain call utility. */ - protected final void internalSetWheel1(Circle value) { + protected final void internalSetWheel1(test.nothing.Circle value) { _wheel1 = value; } @@ -42,18 +42,18 @@ public final boolean hasWheel1() { } @Override - public final Circle getWheel2() { + public final test.nothing.Circle getWheel2() { return _wheel2; } @Override - public Car setWheel2(Circle value) { + public test.nothing.Car setWheel2(test.nothing.Circle value) { internalSetWheel2(value); return this; } /** Internal setter for {@link #getWheel2()} without chain call utility. */ - protected final void internalSetWheel2(Circle value) { + protected final void internalSetWheel2(test.nothing.Circle value) { _wheel2 = value; } @@ -63,18 +63,18 @@ public final boolean hasWheel2() { } @Override - public final Rectangle getBody() { + public final test.nothing.Rectangle getBody() { return _body; } @Override - public Car setBody(Rectangle value) { + public test.nothing.Car setBody(test.nothing.Rectangle value) { internalSetBody(value); return this; } /** Internal setter for {@link #getBody()} without chain call utility. */ - protected final void internalSetBody(Rectangle value) { + protected final void internalSetBody(test.nothing.Rectangle value) { _body = value; } @@ -84,13 +84,13 @@ public final boolean hasBody() { } @Override - public Car setXCoordinate(int value) { + public test.nothing.Car setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Car setYCoordinate(int value) { + public test.nothing.Car setYCoordinate(int value) { internalSetYCoordinate(value); return this; } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Circle_Impl.java similarity index 60% rename from de.haumacher.msgbuf.generator/src/test/java/test/nothing/Circle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Circle_Impl.java index 2a703375..845ef525 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Circle_Impl.java @@ -1,18 +1,18 @@ -package test.nothing; +package test.nothing.impl; /** * A circle {@link Shape}. */ -class Circle_Impl extends AtomicShape_Impl implements Circle { +public class Circle_Impl extends test.nothing.impl.AtomicShape_Impl implements test.nothing.Circle { private int _radius = 0; /** * Creates a {@link Circle_Impl} instance. * - * @see Circle#create() + * @see test.nothing.Circle#create() */ - protected Circle_Impl() { + public Circle_Impl() { super(); } @@ -22,7 +22,7 @@ public final int getRadius() { } @Override - public Circle setRadius(int value) { + public test.nothing.Circle setRadius(int value) { internalSetRadius(value); return this; } @@ -33,13 +33,13 @@ protected final void internalSetRadius(int value) { } @Override - public Circle setXCoordinate(int value) { + public test.nothing.Circle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Circle setYCoordinate(int value) { + public test.nothing.Circle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Group_Impl.java new file mode 100644 index 00000000..eda6e999 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Group_Impl.java @@ -0,0 +1,65 @@ +package test.nothing.impl; + +/** + * A group of shapes. + */ +public class Group_Impl extends test.nothing.impl.Shape_Impl implements test.nothing.Group { + + private final java.util.List _shapes = new java.util.ArrayList<>(); + + /** + * Creates a {@link Group_Impl} instance. + * + * @see test.nothing.Group#create() + */ + public Group_Impl() { + super(); + } + + @Override + public final java.util.List getShapes() { + return _shapes; + } + + @Override + public test.nothing.Group setShapes(java.util.List value) { + internalSetShapes(value); + return this; + } + + /** Internal setter for {@link #getShapes()} without chain call utility. */ + protected final void internalSetShapes(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); + _shapes.clear(); + _shapes.addAll(value); + } + + @Override + public test.nothing.Group addShape(test.nothing.Shape value) { + internalAddShape(value); + return this; + } + + /** Implementation of {@link #addShape(test.nothing.Shape)} without chain call utility. */ + protected final void internalAddShape(test.nothing.Shape value) { + _shapes.add(value); + } + + @Override + public final void removeShape(test.nothing.Shape value) { + _shapes.remove(value); + } + + @Override + public test.nothing.Group setXCoordinate(int value) { + internalSetXCoordinate(value); + return this; + } + + @Override + public test.nothing.Group setYCoordinate(int value) { + internalSetYCoordinate(value); + return this; + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Rectangle_Impl.java similarity index 66% rename from de.haumacher.msgbuf.generator/src/test/java/test/nothing/Rectangle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Rectangle_Impl.java index bffac7e4..8f28fe09 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Rectangle_Impl.java @@ -1,9 +1,9 @@ -package test.nothing; +package test.nothing.impl; /** * A rectangle. */ -class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { +public class Rectangle_Impl extends test.nothing.impl.AtomicShape_Impl implements test.nothing.Rectangle { private int _width = 0; @@ -12,9 +12,9 @@ class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { /** * Creates a {@link Rectangle_Impl} instance. * - * @see Rectangle#create() + * @see test.nothing.Rectangle#create() */ - protected Rectangle_Impl() { + public Rectangle_Impl() { super(); } @@ -24,7 +24,7 @@ public final int getWidth() { } @Override - public Rectangle setWidth(int value) { + public test.nothing.Rectangle setWidth(int value) { internalSetWidth(value); return this; } @@ -40,7 +40,7 @@ public final int getHeight() { } @Override - public Rectangle setHeight(int value) { + public test.nothing.Rectangle setHeight(int value) { internalSetHeight(value); return this; } @@ -51,13 +51,13 @@ protected final void internalSetHeight(int value) { } @Override - public Rectangle setXCoordinate(int value) { + public test.nothing.Rectangle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Rectangle setYCoordinate(int value) { + public test.nothing.Rectangle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Shape_Impl.java similarity index 77% rename from de.haumacher.msgbuf.generator/src/test/java/test/nothing/Shape_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Shape_Impl.java index 1cb36d47..310114ad 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Shape_Impl.java @@ -1,9 +1,9 @@ -package test.nothing; +package test.nothing.impl; /** * An abstract base class for all shapes */ -abstract class Shape_Impl implements Shape { +public abstract class Shape_Impl implements test.nothing.Shape { private int _xCoordinate = 0; @@ -12,7 +12,7 @@ abstract class Shape_Impl implements Shape { /** * Creates a {@link Shape_Impl} instance. */ - protected Shape_Impl() { + public Shape_Impl() { super(); } @@ -22,7 +22,7 @@ public final int getXCoordinate() { } @Override - public Shape setXCoordinate(int value) { + public test.nothing.Shape setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @@ -38,7 +38,7 @@ public final int getYCoordinate() { } @Override - public Shape setYCoordinate(int value) { + public test.nothing.Shape setYCoordinate(int value) { internalSetYCoordinate(value); return this; } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/SimpleType_Impl.java similarity index 72% rename from de.haumacher.msgbuf.generator/src/test/java/test/nothing/SimpleType_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/SimpleType_Impl.java index c12888b4..78d52e30 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/SimpleType_Impl.java @@ -1,9 +1,9 @@ -package test.nothing; +package test.nothing.impl; /** * A concrete type without abstract super type. */ -class SimpleType_Impl implements SimpleType { +public class SimpleType_Impl implements test.nothing.SimpleType { private String _str = ""; @@ -12,9 +12,9 @@ class SimpleType_Impl implements SimpleType { /** * Creates a {@link SimpleType_Impl} instance. * - * @see SimpleType#create() + * @see test.nothing.SimpleType#create() */ - protected SimpleType_Impl() { + public SimpleType_Impl() { super(); } @@ -24,7 +24,7 @@ public final String getStr() { } @Override - public SimpleType setStr(String value) { + public test.nothing.SimpleType setStr(String value) { internalSetStr(value); return this; } @@ -40,7 +40,7 @@ public final int getX() { } @Override - public SimpleType setX(int value) { + public test.nothing.SimpleType setX(int value) { internalSetX(value); return this; } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/AtomicShape.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/AtomicShape.java index b756c972..643be553 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/AtomicShape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/AtomicShape.java @@ -5,26 +5,26 @@ */ public interface AtomicShape extends Shape { - /** Visitor interface for the {@link AtomicShape} hierarchy.*/ + /** Visitor interface for the {@link test.notypekind.AtomicShape} hierarchy.*/ public interface Visitor { - /** Visit case for {@link Circle}.*/ - R visit(Circle self, A arg) throws E; + /** Visit case for {@link test.notypekind.Circle}.*/ + R visit(test.notypekind.Circle self, A arg) throws E; - /** Visit case for {@link Rectangle}.*/ - R visit(Rectangle self, A arg) throws E; + /** Visit case for {@link test.notypekind.Rectangle}.*/ + R visit(test.notypekind.Rectangle self, A arg) throws E; } @Override - AtomicShape setXCoordinate(int value); + test.notypekind.AtomicShape setXCoordinate(int value); @Override - AtomicShape setYCoordinate(int value); + test.notypekind.AtomicShape setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - AtomicShape result; + static test.notypekind.AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.notypekind.AtomicShape result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -37,15 +37,15 @@ static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throw } /** Reads a new instance from the given reader. */ - static AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.notypekind.AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); int typeField = in.nextName(); assert typeField == 0; int type = in.nextInt(); - AtomicShape result; + test.notypekind.AtomicShape result; switch (type) { - case Circle.CIRCLE__TYPE_ID: result = test.notypekind.Circle_Impl.readCircle_Content(in); break; - case Rectangle.RECTANGLE__TYPE_ID: result = test.notypekind.Rectangle_Impl.readRectangle_Content(in); break; + case test.notypekind.Circle.CIRCLE__TYPE_ID: result = test.notypekind.impl.Circle_Impl.readCircle_Content(in); break; + case test.notypekind.Rectangle.RECTANGLE__TYPE_ID: result = test.notypekind.impl.Rectangle_Impl.readRectangle_Content(in); break; default: result = null; while (in.hasNext()) {in.skipValue(); } } in.endObject(); @@ -55,7 +55,7 @@ static AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) thr /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape readAtomicShape(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.notypekind.AtomicShape_Impl.readAtomicShape_XmlContent(in); + return test.notypekind.impl.AtomicShape_Impl.readAtomicShape_XmlContent(in); } /** Accepts the given visitor. */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/AtomicShape_Impl.java deleted file mode 100644 index 102c2900..00000000 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/AtomicShape_Impl.java +++ /dev/null @@ -1,83 +0,0 @@ -package test.notypekind; - -/** - * A {@link Shape} that has no sub-shapes. - */ -abstract class AtomicShape_Impl extends Shape_Impl implements AtomicShape { - - /** - * Creates a {@link AtomicShape_Impl} instance. - */ - protected AtomicShape_Impl() { - super(); - } - - @Override - public AtomicShape setXCoordinate(int value) { - internalSetXCoordinate(value); - return this; - } - - @Override - public AtomicShape setYCoordinate(int value) { - internalSetYCoordinate(value); - return this; - } - - /** XML element name representing a {@link AtomicShape} type. */ - public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; - - /** Serializes all fields that are written as XML attributes. */ - @Override - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeAttributes(out); - } - - /** Serializes all fields that are written as XML elements. */ - @Override - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeElements(out); - } - - /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static AtomicShape_Impl readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - switch (in.getLocalName()) { - case Circle_Impl.CIRCLE__XML_ELEMENT: { - return test.notypekind.Circle_Impl.readCircle_XmlContent(in); - } - - case Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - return test.notypekind.Rectangle_Impl.readRectangle_XmlContent(in); - } - - default: { - internalSkipUntilMatchingEndElement(in); - return null; - } - } - } - - @Override - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - default: { - super.readFieldXmlAttribute(name, value); - } - } - } - - @Override - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - default: { - super.readFieldXmlElement(in, localName); - } - } - } - - @Override - public final R visit(Shape.Visitor v, A arg) throws E { - return visit((AtomicShape.Visitor) v, arg); - } - -} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java index 2294c7e7..f0c54d1d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java @@ -6,13 +6,13 @@ public interface Car extends Shape { /** - * Creates a {@link Car} instance. + * Creates a {@link test.notypekind.Car} instance. */ - static Car create() { - return new test.notypekind.Car_Impl(); + static test.notypekind.Car create() { + return new test.notypekind.impl.Car_Impl(); } - /** Identifier for the {@link Car} type in JSON format. */ + /** Identifier for the {@link test.notypekind.Car} type in JSON format. */ static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ @@ -24,7 +24,7 @@ static Car create() { /** @see #getBody() */ static final String BODY__PROP = "body"; - /** Identifier for the {@link Car} type in binary format. */ + /** Identifier for the {@link test.notypekind.Car} type in binary format. */ static final int CAR__TYPE_ID = 4; /** Identifier for the property {@link #getWheel1()} in binary format. */ @@ -39,12 +39,12 @@ static Car create() { /** * The front wheel. */ - Circle getWheel1(); + test.notypekind.Circle getWheel1(); /** * @see #getWheel1() */ - Car setWheel1(Circle value); + test.notypekind.Car setWheel1(test.notypekind.Circle value); /** * Checks, whether {@link #getWheel1()} has a value. @@ -54,12 +54,12 @@ static Car create() { /** * The back wheel. */ - Circle getWheel2(); + test.notypekind.Circle getWheel2(); /** * @see #getWheel2() */ - Car setWheel2(Circle value); + test.notypekind.Car setWheel2(test.notypekind.Circle value); /** * Checks, whether {@link #getWheel2()} has a value. @@ -69,12 +69,12 @@ static Car create() { /** * The car body. */ - Rectangle getBody(); + test.notypekind.Rectangle getBody(); /** * @see #getBody() */ - Car setBody(Rectangle value); + test.notypekind.Car setBody(test.notypekind.Rectangle value); /** * Checks, whether {@link #getBody()} has a value. @@ -82,22 +82,22 @@ static Car create() { boolean hasBody(); @Override - Car setXCoordinate(int value); + test.notypekind.Car setXCoordinate(int value); @Override - Car setYCoordinate(int value); + test.notypekind.Car setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.notypekind.Car_Impl result = new test.notypekind.Car_Impl(); + static test.notypekind.Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.notypekind.impl.Car_Impl result = new test.notypekind.impl.Car_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.notypekind.Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Car result = test.notypekind.Car_Impl.readCar_Content(in); + test.notypekind.Car result = test.notypekind.impl.Car_Impl.readCar_Content(in); in.endObject(); return result; } @@ -105,7 +105,7 @@ static Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOEx /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car readCar(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.notypekind.Car_Impl.readCar_XmlContent(in); + return test.notypekind.impl.Car_Impl.readCar_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java index 9532b9ec..c0c8ac27 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java @@ -6,19 +6,19 @@ public interface Circle extends AtomicShape { /** - * Creates a {@link Circle} instance. + * Creates a {@link test.notypekind.Circle} instance. */ - static Circle create() { - return new test.notypekind.Circle_Impl(); + static test.notypekind.Circle create() { + return new test.notypekind.impl.Circle_Impl(); } - /** Identifier for the {@link Circle} type in JSON format. */ + /** Identifier for the {@link test.notypekind.Circle} type in JSON format. */ static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ static final String RADIUS__PROP = "r"; - /** Identifier for the {@link Circle} type in binary format. */ + /** Identifier for the {@link test.notypekind.Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; /** Identifier for the property {@link #getRadius()} in binary format. */ @@ -32,25 +32,25 @@ static Circle create() { /** * @see #getRadius() */ - Circle setRadius(int value); + test.notypekind.Circle setRadius(int value); @Override - Circle setXCoordinate(int value); + test.notypekind.Circle setXCoordinate(int value); @Override - Circle setYCoordinate(int value); + test.notypekind.Circle setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.notypekind.Circle_Impl result = new test.notypekind.Circle_Impl(); + static test.notypekind.Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.notypekind.impl.Circle_Impl result = new test.notypekind.impl.Circle_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.notypekind.Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Circle result = test.notypekind.Circle_Impl.readCircle_Content(in); + test.notypekind.Circle result = test.notypekind.impl.Circle_Impl.readCircle_Content(in); in.endObject(); return result; } @@ -58,7 +58,7 @@ static Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.i /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle readCircle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.notypekind.Circle_Impl.readCircle_XmlContent(in); + return test.notypekind.impl.Circle_Impl.readCircle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java index ee3e11da..b0353afc 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java @@ -6,19 +6,19 @@ public interface Group extends Shape { /** - * Creates a {@link Group} instance. + * Creates a {@link test.notypekind.Group} instance. */ - static Group create() { - return new test.notypekind.Group_Impl(); + static test.notypekind.Group create() { + return new test.notypekind.impl.Group_Impl(); } - /** Identifier for the {@link Group} type in JSON format. */ + /** Identifier for the {@link test.notypekind.Group} type in JSON format. */ static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ static final String SHAPES__PROP = "shapes"; - /** Identifier for the {@link Group} type in binary format. */ + /** Identifier for the {@link test.notypekind.Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; /** Identifier for the property {@link #getShapes()} in binary format. */ @@ -31,40 +31,40 @@ static Group create() { * The origins of these {@link Shape}s get a coordinate offset of ({@link #getXCoordinate()}, {@link #getYCoordinate()}). *

*/ - java.util.List getShapes(); + java.util.List getShapes(); /** * @see #getShapes() */ - Group setShapes(java.util.List value); + test.notypekind.Group setShapes(java.util.List value); /** * Adds a value to the {@link #getShapes()} list. */ - Group addShape(Shape value); + test.notypekind.Group addShape(test.notypekind.Shape value); /** * Removes a value from the {@link #getShapes()} list. */ - void removeShape(Shape value); + void removeShape(test.notypekind.Shape value); @Override - Group setXCoordinate(int value); + test.notypekind.Group setXCoordinate(int value); @Override - Group setYCoordinate(int value); + test.notypekind.Group setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.notypekind.Group_Impl result = new test.notypekind.Group_Impl(); + static test.notypekind.Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.notypekind.impl.Group_Impl result = new test.notypekind.impl.Group_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.notypekind.Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Group result = test.notypekind.Group_Impl.readGroup_Content(in); + test.notypekind.Group result = test.notypekind.impl.Group_Impl.readGroup_Content(in); in.endObject(); return result; } @@ -72,7 +72,7 @@ static Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io. /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group readGroup(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.notypekind.Group_Impl.readGroup_XmlContent(in); + return test.notypekind.impl.Group_Impl.readGroup_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java index b6700f2d..dc1970b2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java @@ -6,13 +6,13 @@ public interface Rectangle extends AtomicShape { /** - * Creates a {@link Rectangle} instance. + * Creates a {@link test.notypekind.Rectangle} instance. */ - static Rectangle create() { - return new test.notypekind.Rectangle_Impl(); + static test.notypekind.Rectangle create() { + return new test.notypekind.impl.Rectangle_Impl(); } - /** Identifier for the {@link Rectangle} type in JSON format. */ + /** Identifier for the {@link test.notypekind.Rectangle} type in JSON format. */ static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ @@ -21,7 +21,7 @@ static Rectangle create() { /** @see #getHeight() */ static final String HEIGHT__PROP = "h"; - /** Identifier for the {@link Rectangle} type in binary format. */ + /** Identifier for the {@link test.notypekind.Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; /** Identifier for the property {@link #getWidth()} in binary format. */ @@ -44,7 +44,7 @@ static Rectangle create() { /** * @see #getWidth() */ - Rectangle setWidth(int value); + test.notypekind.Rectangle setWidth(int value); /** * The width of this {@link Rectangle}. @@ -56,25 +56,25 @@ static Rectangle create() { /** * @see #getHeight() */ - Rectangle setHeight(int value); + test.notypekind.Rectangle setHeight(int value); @Override - Rectangle setXCoordinate(int value); + test.notypekind.Rectangle setXCoordinate(int value); @Override - Rectangle setYCoordinate(int value); + test.notypekind.Rectangle setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.notypekind.Rectangle_Impl result = new test.notypekind.Rectangle_Impl(); + static test.notypekind.Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.notypekind.impl.Rectangle_Impl result = new test.notypekind.impl.Rectangle_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.notypekind.Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Rectangle result = test.notypekind.Rectangle_Impl.readRectangle_Content(in); + test.notypekind.Rectangle result = test.notypekind.impl.Rectangle_Impl.readRectangle_Content(in); in.endObject(); return result; } @@ -82,7 +82,7 @@ static Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle readRectangle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.notypekind.Rectangle_Impl.readRectangle_XmlContent(in); + return test.notypekind.impl.Rectangle_Impl.readRectangle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java index ec19fd7c..98cff04b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java @@ -5,14 +5,14 @@ */ public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { - /** Visitor interface for the {@link Shape} hierarchy.*/ - public interface Visitor extends AtomicShape.Visitor { + /** Visitor interface for the {@link test.notypekind.Shape} hierarchy.*/ + public interface Visitor extends test.notypekind.AtomicShape.Visitor { - /** Visit case for {@link Group}.*/ - R visit(Group self, A arg) throws E; + /** Visit case for {@link test.notypekind.Group}.*/ + R visit(test.notypekind.Group self, A arg) throws E; - /** Visit case for {@link Car}.*/ - R visit(Car self, A arg) throws E; + /** Visit case for {@link test.notypekind.Car}.*/ + R visit(test.notypekind.Car self, A arg) throws E; } @@ -36,7 +36,7 @@ public interface Visitor extends AtomicShape.Visitor extends AtomicShape.Visitor R visit(Shape.Visitor v, A arg) throws E { - return visit((AtomicShape.Visitor) v, arg); + public final R visit(test.notypekind.Shape.Visitor v, A arg) throws E { + return visit((test.notypekind.AtomicShape.Visitor) v, arg); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java similarity index 72% rename from de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java index beb71128..fc864274 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java @@ -1,38 +1,38 @@ -package test.notypekind; +package test.notypekind.impl; /** * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. */ -class Car_Impl extends Shape_Impl implements Car { +public class Car_Impl extends test.notypekind.impl.Shape_Impl implements test.notypekind.Car { - private Circle _wheel1 = null; + private test.notypekind.Circle _wheel1 = null; - private Circle _wheel2 = null; + private test.notypekind.Circle _wheel2 = null; - private Rectangle _body = null; + private test.notypekind.Rectangle _body = null; /** * Creates a {@link Car_Impl} instance. * - * @see Car#create() + * @see test.notypekind.Car#create() */ - protected Car_Impl() { + public Car_Impl() { super(); } @Override - public final Circle getWheel1() { + public final test.notypekind.Circle getWheel1() { return _wheel1; } @Override - public Car setWheel1(Circle value) { + public test.notypekind.Car setWheel1(test.notypekind.Circle value) { internalSetWheel1(value); return this; } /** Internal setter for {@link #getWheel1()} without chain call utility. */ - protected final void internalSetWheel1(Circle value) { + protected final void internalSetWheel1(test.notypekind.Circle value) { _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; } @@ -43,18 +43,18 @@ public final boolean hasWheel1() { } @Override - public final Circle getWheel2() { + public final test.notypekind.Circle getWheel2() { return _wheel2; } @Override - public Car setWheel2(Circle value) { + public test.notypekind.Car setWheel2(test.notypekind.Circle value) { internalSetWheel2(value); return this; } /** Internal setter for {@link #getWheel2()} without chain call utility. */ - protected final void internalSetWheel2(Circle value) { + protected final void internalSetWheel2(test.notypekind.Circle value) { _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; } @@ -65,18 +65,18 @@ public final boolean hasWheel2() { } @Override - public final Rectangle getBody() { + public final test.notypekind.Rectangle getBody() { return _body; } @Override - public Car setBody(Rectangle value) { + public test.notypekind.Car setBody(test.notypekind.Rectangle value) { internalSetBody(value); return this; } /** Internal setter for {@link #getBody()} without chain call utility. */ - protected final void internalSetBody(Rectangle value) { + protected final void internalSetBody(test.notypekind.Rectangle value) { _listener.beforeSet(this, BODY__PROP, value); _body = value; } @@ -87,13 +87,13 @@ public final boolean hasBody() { } @Override - public Car setXCoordinate(int value) { + public test.notypekind.Car setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Car setYCoordinate(int value) { + public test.notypekind.Car setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -127,9 +127,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; - case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; - case BODY__PROP: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((test.notypekind.Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((test.notypekind.Circle) value); break; + case BODY__PROP: internalSetBody((test.notypekind.Rectangle) value); break; default: super.set(field, value); break; } } @@ -183,9 +183,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } } - /** Helper for creating an object of type {@link Car} from a polymorphic composition. */ - public static Car readCar_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.notypekind.Car_Impl result = new Car_Impl(); + /** Helper for creating an object of type {@link test.notypekind.Car} from a polymorphic composition. */ + public static test.notypekind.Car readCar_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.notypekind.impl.Car_Impl result = new Car_Impl(); result.readContent(in); return result; } @@ -200,7 +200,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Car} type. */ + /** XML element name representing a {@link test.notypekind.Car} type. */ public static final String CAR__XML_ELEMENT = "car"; /** XML attribute or element name of a {@link #getWheel1} property. */ @@ -244,7 +244,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. } } - /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.notypekind.Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); result.readContentXml(in); @@ -264,15 +264,15 @@ protected void readFieldXmlAttribute(String name, String value) { protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { case WHEEL_1__XML_ATTR: { - setWheel1(test.notypekind.Circle_Impl.readCircle_XmlContent(in)); + setWheel1(test.notypekind.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case WHEEL_2__XML_ATTR: { - setWheel2(test.notypekind.Circle_Impl.readCircle_XmlContent(in)); + setWheel2(test.notypekind.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case BODY__XML_ATTR: { - setBody(test.notypekind.Rectangle_Impl.readRectangle_XmlContent(in)); + setBody(test.notypekind.impl.Rectangle_Impl.readRectangle_XmlContent(in)); break; } default: { @@ -282,7 +282,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(Shape.Visitor v, A arg) throws E { + public R visit(test.notypekind.Shape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java similarity index 77% rename from de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java index 251656ea..7d8d9910 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java @@ -1,18 +1,18 @@ -package test.notypekind; +package test.notypekind.impl; /** * A circle {@link Shape}. */ -class Circle_Impl extends AtomicShape_Impl implements Circle { +public class Circle_Impl extends test.notypekind.impl.AtomicShape_Impl implements test.notypekind.Circle { private int _radius = 0; /** * Creates a {@link Circle_Impl} instance. * - * @see Circle#create() + * @see test.notypekind.Circle#create() */ - protected Circle_Impl() { + public Circle_Impl() { super(); } @@ -22,7 +22,7 @@ public final int getRadius() { } @Override - public Circle setRadius(int value) { + public test.notypekind.Circle setRadius(int value) { internalSetRadius(value); return this; } @@ -34,13 +34,13 @@ protected final void internalSetRadius(int value) { } @Override - public Circle setXCoordinate(int value) { + public test.notypekind.Circle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Circle setYCoordinate(int value) { + public test.notypekind.Circle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -102,9 +102,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getRadius()); } - /** Helper for creating an object of type {@link Circle} from a polymorphic composition. */ - public static Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.notypekind.Circle_Impl result = new Circle_Impl(); + /** Helper for creating an object of type {@link test.notypekind.Circle} from a polymorphic composition. */ + public static test.notypekind.Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.notypekind.impl.Circle_Impl result = new Circle_Impl(); result.readContent(in); return result; } @@ -117,7 +117,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Circle} type. */ + /** XML element name representing a {@link test.notypekind.Circle} type. */ public static final String CIRCLE__XML_ELEMENT = "circle"; /** XML attribute or element name of a {@link #getRadius} property. */ @@ -139,9 +139,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.notypekind.Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); result.readContentXml(in); @@ -175,7 +176,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { + public R visit(test.notypekind.AtomicShape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java similarity index 69% rename from de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java index b58209f8..fa484c6c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java @@ -1,18 +1,18 @@ -package test.notypekind; +package test.notypekind.impl; /** * A group of shapes. */ -class Group_Impl extends Shape_Impl implements Group { +public class Group_Impl extends test.notypekind.impl.Shape_Impl implements test.notypekind.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override - protected void beforeAdd(int index, Shape element) { + protected void beforeAdd(int index, test.notypekind.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); } @Override - protected void afterRemove(int index, Shape element) { + protected void afterRemove(int index, test.notypekind.Shape element) { _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } }; @@ -20,54 +20,54 @@ protected void afterRemove(int index, Shape element) { /** * Creates a {@link Group_Impl} instance. * - * @see Group#create() + * @see test.notypekind.Group#create() */ - protected Group_Impl() { + public Group_Impl() { super(); } @Override - public final java.util.List getShapes() { + public final java.util.List getShapes() { return _shapes; } @Override - public Group setShapes(java.util.List value) { + public test.notypekind.Group setShapes(java.util.List value) { internalSetShapes(value); return this; } /** Internal setter for {@link #getShapes()} without chain call utility. */ - protected final void internalSetShapes(java.util.List value) { + protected final void internalSetShapes(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); _shapes.clear(); _shapes.addAll(value); } @Override - public Group addShape(Shape value) { + public test.notypekind.Group addShape(test.notypekind.Shape value) { internalAddShape(value); return this; } - /** Implementation of {@link #addShape(Shape)} without chain call utility. */ - protected final void internalAddShape(Shape value) { + /** Implementation of {@link #addShape(test.notypekind.Shape)} without chain call utility. */ + protected final void internalAddShape(test.notypekind.Shape value) { _shapes.add(value); } @Override - public final void removeShape(Shape value) { + public final void removeShape(test.notypekind.Shape value) { _shapes.remove(value); } @Override - public Group setXCoordinate(int value) { + public test.notypekind.Group setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Group setYCoordinate(int value) { + public test.notypekind.Group setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -97,7 +97,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(test.notypekind.Shape.class, value)); break; default: super.set(field, value); break; } } @@ -107,7 +107,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. super.writeFields(out); out.name(SHAPES__PROP); out.beginArray(); - for (Shape x : getShapes()) { + for (test.notypekind.Shape x : getShapes()) { x.writeTo(out); } out.endArray(); @@ -138,18 +138,18 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav super.writeFields(out); out.name(SHAPES__ID); { - java.util.List values = getShapes(); + java.util.List values = getShapes(); out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); - for (Shape x : values) { + for (test.notypekind.Shape x : values) { x.writeTo(out); } out.endArray(); } } - /** Helper for creating an object of type {@link Group} from a polymorphic composition. */ - public static Group readGroup_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.notypekind.Group_Impl result = new Group_Impl(); + /** Helper for creating an object of type {@link test.notypekind.Group} from a polymorphic composition. */ + public static test.notypekind.Group readGroup_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.notypekind.impl.Group_Impl result = new Group_Impl(); result.readContent(in); return result; } @@ -169,7 +169,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Group} type. */ + /** XML element name representing a {@link test.notypekind.Group} type. */ public static final String GROUP__XML_ELEMENT = "group"; /** XML attribute or element name of a {@link #getShapes} property. */ @@ -197,7 +197,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. out.writeEndElement(); } - /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.notypekind.Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); result.readContentXml(in); @@ -233,12 +233,12 @@ private void internalReadShapesListXml(javax.xml.stream.XMLStreamReader in) thro break; } - addShape(test.notypekind.Shape_Impl.readShape_XmlContent(in)); + addShape(test.notypekind.impl.Shape_Impl.readShape_XmlContent(in)); } } @Override - public R visit(Shape.Visitor v, A arg) throws E { + public R visit(test.notypekind.Shape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java similarity index 80% rename from de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java index 3ef57dad..0da2c61a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java @@ -1,9 +1,9 @@ -package test.notypekind; +package test.notypekind.impl; /** * A rectangle. */ -class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { +public class Rectangle_Impl extends test.notypekind.impl.AtomicShape_Impl implements test.notypekind.Rectangle { private int _width = 0; @@ -12,9 +12,9 @@ class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { /** * Creates a {@link Rectangle_Impl} instance. * - * @see Rectangle#create() + * @see test.notypekind.Rectangle#create() */ - protected Rectangle_Impl() { + public Rectangle_Impl() { super(); } @@ -24,7 +24,7 @@ public final int getWidth() { } @Override - public Rectangle setWidth(int value) { + public test.notypekind.Rectangle setWidth(int value) { internalSetWidth(value); return this; } @@ -41,7 +41,7 @@ public final int getHeight() { } @Override - public Rectangle setHeight(int value) { + public test.notypekind.Rectangle setHeight(int value) { internalSetHeight(value); return this; } @@ -53,13 +53,13 @@ protected final void internalSetHeight(int value) { } @Override - public Rectangle setXCoordinate(int value) { + public test.notypekind.Rectangle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Rectangle setYCoordinate(int value) { + public test.notypekind.Rectangle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -129,9 +129,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getHeight()); } - /** Helper for creating an object of type {@link Rectangle} from a polymorphic composition. */ - public static Rectangle readRectangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.notypekind.Rectangle_Impl result = new Rectangle_Impl(); + /** Helper for creating an object of type {@link test.notypekind.Rectangle} from a polymorphic composition. */ + public static test.notypekind.Rectangle readRectangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.notypekind.impl.Rectangle_Impl result = new Rectangle_Impl(); result.readContent(in); return result; } @@ -145,7 +145,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Rectangle} type. */ + /** XML element name representing a {@link test.notypekind.Rectangle} type. */ public static final String RECTANGLE__XML_ELEMENT = "rectangle"; /** XML attribute or element name of a {@link #getWidth} property. */ @@ -171,9 +171,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.notypekind.Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); result.readContentXml(in); @@ -215,7 +216,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { + public R visit(test.notypekind.AtomicShape.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java similarity index 87% rename from de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java index ef04b380..5af75e5f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java @@ -1,9 +1,9 @@ -package test.novisit; +package test.notypekind.impl; /** * An abstract base class for all shapes */ -abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements Shape { +public abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.notypekind.Shape { private int _xCoordinate = 0; @@ -12,20 +12,17 @@ abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject im /** * Creates a {@link Shape_Impl} instance. */ - protected Shape_Impl() { + public Shape_Impl() { super(); } - /** The type code of this instance. */ - public abstract TypeKind kind(); - @Override public final int getXCoordinate() { return _xCoordinate; } @Override - public Shape setXCoordinate(int value) { + public test.notypekind.Shape setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @@ -42,7 +39,7 @@ public final int getYCoordinate() { } @Override - public Shape setYCoordinate(int value) { + public test.notypekind.Shape setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -56,7 +53,7 @@ protected final void internalSetYCoordinate(int value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public Shape registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.notypekind.Shape registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -66,7 +63,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.notypekind.Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -90,7 +87,7 @@ public Object get(String field) { switch (field) { case X_COORDINATE__PROP: return getXCoordinate(); case Y_COORDINATE__PROP: return getYCoordinate(); - default: return Shape.super.get(field); + default: return test.notypekind.Shape.super.get(field); } } @@ -168,7 +165,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Shape} type. */ + /** XML element name representing a {@link test.notypekind.Shape} type. */ public static final String SHAPE__XML_ELEMENT = "shape"; /** XML attribute or element name of a {@link #getXCoordinate} property. */ @@ -191,25 +188,26 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.notypekind.Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { case Circle_Impl.CIRCLE__XML_ELEMENT: { - return test.novisit.Circle_Impl.readCircle_XmlContent(in); + return test.notypekind.impl.Circle_Impl.readCircle_XmlContent(in); } case Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - return test.novisit.Rectangle_Impl.readRectangle_XmlContent(in); + return test.notypekind.impl.Rectangle_Impl.readRectangle_XmlContent(in); } case Group_Impl.GROUP__XML_ELEMENT: { - return test.novisit.Group_Impl.readGroup_XmlContent(in); + return test.notypekind.impl.Group_Impl.readGroup_XmlContent(in); } case Car_Impl.CAR__XML_ELEMENT: { - return test.novisit.Car_Impl.readCar_XmlContent(in); + return test.notypekind.impl.Car_Impl.readCar_XmlContent(in); } default: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java similarity index 85% rename from de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/SimpleType_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java index 2e5418aa..e084acfd 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java @@ -1,9 +1,9 @@ -package test.hierarchy.data; +package test.notypekind.impl; /** * A concrete type without abstract super type. */ -class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements SimpleType { +public class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.notypekind.SimpleType { private String _str = ""; @@ -12,9 +12,9 @@ class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implem /** * Creates a {@link SimpleType_Impl} instance. * - * @see SimpleType#create() + * @see test.notypekind.SimpleType#create() */ - protected SimpleType_Impl() { + public SimpleType_Impl() { super(); } @@ -24,7 +24,7 @@ public final String getStr() { } @Override - public SimpleType setStr(String value) { + public test.notypekind.SimpleType setStr(String value) { internalSetStr(value); return this; } @@ -41,7 +41,7 @@ public final int getX() { } @Override - public SimpleType setX(int value) { + public test.notypekind.SimpleType setX(int value) { internalSetX(value); return this; } @@ -55,7 +55,7 @@ protected final void internalSetX(int value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.notypekind.SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -65,7 +65,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.notypekind.SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -94,7 +94,7 @@ public Object get(String field) { switch (field) { case STR__PROP: return getStr(); case X__PROP: return getX(); - default: return SimpleType.super.get(field); + default: return test.notypekind.SimpleType.super.get(field); } } @@ -150,9 +150,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getX()); } - /** Helper for creating an object of type {@link SimpleType} from a polymorphic composition. */ - public static SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.hierarchy.data.SimpleType_Impl result = new SimpleType_Impl(); + /** Helper for creating an object of type {@link test.notypekind.SimpleType} from a polymorphic composition. */ + public static test.notypekind.SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.notypekind.impl.SimpleType_Impl result = new SimpleType_Impl(); result.readContent(in); return result; } @@ -174,7 +174,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link SimpleType} type. */ + /** XML element name representing a {@link test.notypekind.SimpleType} type. */ public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; /** XML attribute or element name of a {@link #getStr} property. */ @@ -202,9 +202,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.notypekind.SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SimpleType_Impl result = new SimpleType_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/AtomicShape.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/AtomicShape.java index 51abf91f..acad97a8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/AtomicShape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/AtomicShape.java @@ -6,14 +6,14 @@ public interface AtomicShape extends Shape { @Override - AtomicShape setXCoordinate(int value); + test.novisit.AtomicShape setXCoordinate(int value); @Override - AtomicShape setYCoordinate(int value); + test.novisit.AtomicShape setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - AtomicShape result; + static test.novisit.AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisit.AtomicShape result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -26,15 +26,15 @@ static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throw } /** Reads a new instance from the given reader. */ - static AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.novisit.AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); int typeField = in.nextName(); assert typeField == 0; int type = in.nextInt(); - AtomicShape result; + test.novisit.AtomicShape result; switch (type) { - case Circle.CIRCLE__TYPE_ID: result = test.novisit.Circle_Impl.readCircle_Content(in); break; - case Rectangle.RECTANGLE__TYPE_ID: result = test.novisit.Rectangle_Impl.readRectangle_Content(in); break; + case test.novisit.Circle.CIRCLE__TYPE_ID: result = test.novisit.impl.Circle_Impl.readCircle_Content(in); break; + case test.novisit.Rectangle.RECTANGLE__TYPE_ID: result = test.novisit.impl.Rectangle_Impl.readRectangle_Content(in); break; default: result = null; while (in.hasNext()) {in.skipValue(); } } in.endObject(); @@ -44,7 +44,7 @@ static AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) thr /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape readAtomicShape(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.novisit.AtomicShape_Impl.readAtomicShape_XmlContent(in); + return test.novisit.impl.AtomicShape_Impl.readAtomicShape_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/AtomicShape_Impl.java deleted file mode 100644 index a4d95294..00000000 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/AtomicShape_Impl.java +++ /dev/null @@ -1,78 +0,0 @@ -package test.novisit; - -/** - * A {@link Shape} that has no sub-shapes. - */ -abstract class AtomicShape_Impl extends Shape_Impl implements AtomicShape { - - /** - * Creates a {@link AtomicShape_Impl} instance. - */ - protected AtomicShape_Impl() { - super(); - } - - @Override - public AtomicShape setXCoordinate(int value) { - internalSetXCoordinate(value); - return this; - } - - @Override - public AtomicShape setYCoordinate(int value) { - internalSetYCoordinate(value); - return this; - } - - /** XML element name representing a {@link AtomicShape} type. */ - public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; - - /** Serializes all fields that are written as XML attributes. */ - @Override - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeAttributes(out); - } - - /** Serializes all fields that are written as XML elements. */ - @Override - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeElements(out); - } - - /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static AtomicShape_Impl readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - switch (in.getLocalName()) { - case Circle_Impl.CIRCLE__XML_ELEMENT: { - return test.novisit.Circle_Impl.readCircle_XmlContent(in); - } - - case Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - return test.novisit.Rectangle_Impl.readRectangle_XmlContent(in); - } - - default: { - internalSkipUntilMatchingEndElement(in); - return null; - } - } - } - - @Override - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - default: { - super.readFieldXmlAttribute(name, value); - } - } - } - - @Override - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - default: { - super.readFieldXmlElement(in, localName); - } - } - } - -} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java index 24cb56f4..4aad5c6c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java @@ -6,13 +6,13 @@ public interface Car extends Shape { /** - * Creates a {@link Car} instance. + * Creates a {@link test.novisit.Car} instance. */ - static Car create() { - return new test.novisit.Car_Impl(); + static test.novisit.Car create() { + return new test.novisit.impl.Car_Impl(); } - /** Identifier for the {@link Car} type in JSON format. */ + /** Identifier for the {@link test.novisit.Car} type in JSON format. */ static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ @@ -24,7 +24,7 @@ static Car create() { /** @see #getBody() */ static final String BODY__PROP = "body"; - /** Identifier for the {@link Car} type in binary format. */ + /** Identifier for the {@link test.novisit.Car} type in binary format. */ static final int CAR__TYPE_ID = 4; /** Identifier for the property {@link #getWheel1()} in binary format. */ @@ -39,12 +39,12 @@ static Car create() { /** * The front wheel. */ - Circle getWheel1(); + test.novisit.Circle getWheel1(); /** * @see #getWheel1() */ - Car setWheel1(Circle value); + test.novisit.Car setWheel1(test.novisit.Circle value); /** * Checks, whether {@link #getWheel1()} has a value. @@ -54,12 +54,12 @@ static Car create() { /** * The back wheel. */ - Circle getWheel2(); + test.novisit.Circle getWheel2(); /** * @see #getWheel2() */ - Car setWheel2(Circle value); + test.novisit.Car setWheel2(test.novisit.Circle value); /** * Checks, whether {@link #getWheel2()} has a value. @@ -69,12 +69,12 @@ static Car create() { /** * The car body. */ - Rectangle getBody(); + test.novisit.Rectangle getBody(); /** * @see #getBody() */ - Car setBody(Rectangle value); + test.novisit.Car setBody(test.novisit.Rectangle value); /** * Checks, whether {@link #getBody()} has a value. @@ -82,22 +82,22 @@ static Car create() { boolean hasBody(); @Override - Car setXCoordinate(int value); + test.novisit.Car setXCoordinate(int value); @Override - Car setYCoordinate(int value); + test.novisit.Car setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.novisit.Car_Impl result = new test.novisit.Car_Impl(); + static test.novisit.Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisit.impl.Car_Impl result = new test.novisit.impl.Car_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.novisit.Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Car result = test.novisit.Car_Impl.readCar_Content(in); + test.novisit.Car result = test.novisit.impl.Car_Impl.readCar_Content(in); in.endObject(); return result; } @@ -105,7 +105,7 @@ static Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOEx /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car readCar(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.novisit.Car_Impl.readCar_XmlContent(in); + return test.novisit.impl.Car_Impl.readCar_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java index 75345e79..55b8e442 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java @@ -6,19 +6,19 @@ public interface Circle extends AtomicShape { /** - * Creates a {@link Circle} instance. + * Creates a {@link test.novisit.Circle} instance. */ - static Circle create() { - return new test.novisit.Circle_Impl(); + static test.novisit.Circle create() { + return new test.novisit.impl.Circle_Impl(); } - /** Identifier for the {@link Circle} type in JSON format. */ + /** Identifier for the {@link test.novisit.Circle} type in JSON format. */ static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ static final String RADIUS__PROP = "r"; - /** Identifier for the {@link Circle} type in binary format. */ + /** Identifier for the {@link test.novisit.Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; /** Identifier for the property {@link #getRadius()} in binary format. */ @@ -32,25 +32,25 @@ static Circle create() { /** * @see #getRadius() */ - Circle setRadius(int value); + test.novisit.Circle setRadius(int value); @Override - Circle setXCoordinate(int value); + test.novisit.Circle setXCoordinate(int value); @Override - Circle setYCoordinate(int value); + test.novisit.Circle setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.novisit.Circle_Impl result = new test.novisit.Circle_Impl(); + static test.novisit.Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisit.impl.Circle_Impl result = new test.novisit.impl.Circle_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.novisit.Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Circle result = test.novisit.Circle_Impl.readCircle_Content(in); + test.novisit.Circle result = test.novisit.impl.Circle_Impl.readCircle_Content(in); in.endObject(); return result; } @@ -58,7 +58,7 @@ static Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.i /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle readCircle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.novisit.Circle_Impl.readCircle_XmlContent(in); + return test.novisit.impl.Circle_Impl.readCircle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java index 02052c7a..f07b617a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java @@ -6,19 +6,19 @@ public interface Group extends Shape { /** - * Creates a {@link Group} instance. + * Creates a {@link test.novisit.Group} instance. */ - static Group create() { - return new test.novisit.Group_Impl(); + static test.novisit.Group create() { + return new test.novisit.impl.Group_Impl(); } - /** Identifier for the {@link Group} type in JSON format. */ + /** Identifier for the {@link test.novisit.Group} type in JSON format. */ static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ static final String SHAPES__PROP = "shapes"; - /** Identifier for the {@link Group} type in binary format. */ + /** Identifier for the {@link test.novisit.Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; /** Identifier for the property {@link #getShapes()} in binary format. */ @@ -31,40 +31,40 @@ static Group create() { * The origins of these {@link Shape}s get a coordinate offset of ({@link #getXCoordinate()}, {@link #getYCoordinate()}). *

*/ - java.util.List getShapes(); + java.util.List getShapes(); /** * @see #getShapes() */ - Group setShapes(java.util.List value); + test.novisit.Group setShapes(java.util.List value); /** * Adds a value to the {@link #getShapes()} list. */ - Group addShape(Shape value); + test.novisit.Group addShape(test.novisit.Shape value); /** * Removes a value from the {@link #getShapes()} list. */ - void removeShape(Shape value); + void removeShape(test.novisit.Shape value); @Override - Group setXCoordinate(int value); + test.novisit.Group setXCoordinate(int value); @Override - Group setYCoordinate(int value); + test.novisit.Group setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.novisit.Group_Impl result = new test.novisit.Group_Impl(); + static test.novisit.Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisit.impl.Group_Impl result = new test.novisit.impl.Group_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.novisit.Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Group result = test.novisit.Group_Impl.readGroup_Content(in); + test.novisit.Group result = test.novisit.impl.Group_Impl.readGroup_Content(in); in.endObject(); return result; } @@ -72,7 +72,7 @@ static Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io. /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group readGroup(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.novisit.Group_Impl.readGroup_XmlContent(in); + return test.novisit.impl.Group_Impl.readGroup_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java index 2426b492..776e6473 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java @@ -6,13 +6,13 @@ public interface Rectangle extends AtomicShape { /** - * Creates a {@link Rectangle} instance. + * Creates a {@link test.novisit.Rectangle} instance. */ - static Rectangle create() { - return new test.novisit.Rectangle_Impl(); + static test.novisit.Rectangle create() { + return new test.novisit.impl.Rectangle_Impl(); } - /** Identifier for the {@link Rectangle} type in JSON format. */ + /** Identifier for the {@link test.novisit.Rectangle} type in JSON format. */ static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ @@ -21,7 +21,7 @@ static Rectangle create() { /** @see #getHeight() */ static final String HEIGHT__PROP = "h"; - /** Identifier for the {@link Rectangle} type in binary format. */ + /** Identifier for the {@link test.novisit.Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; /** Identifier for the property {@link #getWidth()} in binary format. */ @@ -44,7 +44,7 @@ static Rectangle create() { /** * @see #getWidth() */ - Rectangle setWidth(int value); + test.novisit.Rectangle setWidth(int value); /** * The width of this {@link Rectangle}. @@ -56,25 +56,25 @@ static Rectangle create() { /** * @see #getHeight() */ - Rectangle setHeight(int value); + test.novisit.Rectangle setHeight(int value); @Override - Rectangle setXCoordinate(int value); + test.novisit.Rectangle setXCoordinate(int value); @Override - Rectangle setYCoordinate(int value); + test.novisit.Rectangle setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.novisit.Rectangle_Impl result = new test.novisit.Rectangle_Impl(); + static test.novisit.Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisit.impl.Rectangle_Impl result = new test.novisit.impl.Rectangle_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.novisit.Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Rectangle result = test.novisit.Rectangle_Impl.readRectangle_Content(in); + test.novisit.Rectangle result = test.novisit.impl.Rectangle_Impl.readRectangle_Content(in); in.endObject(); return result; } @@ -82,7 +82,7 @@ static Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle readRectangle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.novisit.Rectangle_Impl.readRectangle_XmlContent(in); + return test.novisit.impl.Rectangle_Impl.readRectangle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java index ddecf398..6430b030 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java @@ -5,19 +5,19 @@ */ public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { - /** Type codes for the {@link Shape} hierarchy. */ + /** Type codes for the {@link test.novisit.Shape} hierarchy. */ public enum TypeKind { - /** Type literal for {@link Circle}. */ + /** Type literal for {@link test.novisit.Circle}. */ CIRCLE, - /** Type literal for {@link Rectangle}. */ + /** Type literal for {@link test.novisit.Rectangle}. */ RECTANGLE, - /** Type literal for {@link Group}. */ + /** Type literal for {@link test.novisit.Group}. */ GROUP, - /** Type literal for {@link Car}. */ + /** Type literal for {@link test.novisit.Car}. */ CAR, ; @@ -46,7 +46,7 @@ public enum TypeKind { /** * @see #getXCoordinate() */ - Shape setXCoordinate(int value); + test.novisit.Shape setXCoordinate(int value); /** * Y coordinate of the origin of the coordinate system of this {@link Shape}. @@ -56,17 +56,17 @@ public enum TypeKind { /** * @see #getYCoordinate() */ - Shape setYCoordinate(int value); + test.novisit.Shape setYCoordinate(int value); @Override - public Shape registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.novisit.Shape registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.novisit.Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static Shape readShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - Shape result; + static test.novisit.Shape readShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisit.Shape result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -80,21 +80,21 @@ static Shape readShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IO return result; } - /** The binary identifier for this concrete type in the polymorphic {@link Shape} hierarchy. */ + /** The binary identifier for this concrete type in the polymorphic {@link test.novisit.Shape} hierarchy. */ abstract int typeId(); /** Reads a new instance from the given reader. */ - static Shape readShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.novisit.Shape readShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); int typeField = in.nextName(); assert typeField == 0; int type = in.nextInt(); - Shape result; + test.novisit.Shape result; switch (type) { - case Group.GROUP__TYPE_ID: result = test.novisit.Group_Impl.readGroup_Content(in); break; - case Car.CAR__TYPE_ID: result = test.novisit.Car_Impl.readCar_Content(in); break; - case Circle.CIRCLE__TYPE_ID: result = test.novisit.Circle_Impl.readCircle_Content(in); break; - case Rectangle.RECTANGLE__TYPE_ID: result = test.novisit.Rectangle_Impl.readRectangle_Content(in); break; + case test.novisit.Group.GROUP__TYPE_ID: result = test.novisit.impl.Group_Impl.readGroup_Content(in); break; + case test.novisit.Car.CAR__TYPE_ID: result = test.novisit.impl.Car_Impl.readCar_Content(in); break; + case test.novisit.Circle.CIRCLE__TYPE_ID: result = test.novisit.impl.Circle_Impl.readCircle_Content(in); break; + case test.novisit.Rectangle.RECTANGLE__TYPE_ID: result = test.novisit.impl.Rectangle_Impl.readRectangle_Content(in); break; default: result = null; while (in.hasNext()) {in.skipValue(); } } in.endObject(); @@ -104,7 +104,7 @@ static Shape readShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io. /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape readShape(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.novisit.Shape_Impl.readShape_XmlContent(in); + return test.novisit.impl.Shape_Impl.readShape_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType.java index 317fdf42..5195f020 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType.java @@ -6,13 +6,13 @@ public interface SimpleType extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link SimpleType} instance. + * Creates a {@link test.novisit.SimpleType} instance. */ - static SimpleType create() { - return new test.novisit.SimpleType_Impl(); + static test.novisit.SimpleType create() { + return new test.novisit.impl.SimpleType_Impl(); } - /** Identifier for the {@link SimpleType} type in JSON format. */ + /** Identifier for the {@link test.novisit.SimpleType} type in JSON format. */ static final String SIMPLE_TYPE__TYPE = "SimpleType"; /** @see #getStr() */ @@ -35,7 +35,7 @@ static SimpleType create() { /** * @see #getStr() */ - SimpleType setStr(String value); + test.novisit.SimpleType setStr(String value); /** * An int property @@ -45,25 +45,25 @@ static SimpleType create() { /** * @see #getX() */ - SimpleType setX(int value); + test.novisit.SimpleType setX(int value); @Override - public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.novisit.SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.novisit.SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.novisit.SimpleType_Impl result = new test.novisit.SimpleType_Impl(); + static test.novisit.SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisit.impl.SimpleType_Impl result = new test.novisit.impl.SimpleType_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static SimpleType readSimpleType(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.novisit.SimpleType readSimpleType(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - SimpleType result = test.novisit.SimpleType_Impl.readSimpleType_Content(in); + test.novisit.SimpleType result = test.novisit.impl.SimpleType_Impl.readSimpleType_Content(in); in.endObject(); return result; } @@ -71,7 +71,7 @@ static SimpleType readSimpleType(de.haumacher.msgbuf.binary.DataReader in) throw /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SimpleType readSimpleType(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.novisit.SimpleType_Impl.readSimpleType_XmlContent(in); + return test.novisit.impl.SimpleType_Impl.readSimpleType_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/AtomicShape_Impl.java similarity index 68% rename from de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/AtomicShape_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/AtomicShape_Impl.java index c5944510..be562b5b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/AtomicShape_Impl.java @@ -1,30 +1,30 @@ -package test.onlyxml.data; +package test.novisit.impl; /** * A {@link Shape} that has no sub-shapes. */ -abstract class AtomicShape_Impl extends Shape_Impl implements AtomicShape { +public abstract class AtomicShape_Impl extends test.novisit.impl.Shape_Impl implements test.novisit.AtomicShape { /** * Creates a {@link AtomicShape_Impl} instance. */ - protected AtomicShape_Impl() { + public AtomicShape_Impl() { super(); } @Override - public AtomicShape setXCoordinate(int value) { + public test.novisit.AtomicShape setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public AtomicShape setYCoordinate(int value) { + public test.novisit.AtomicShape setYCoordinate(int value) { internalSetYCoordinate(value); return this; } - /** XML element name representing a {@link AtomicShape} type. */ + /** XML element name representing a {@link test.novisit.AtomicShape} type. */ public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; /** Serializes all fields that are written as XML attributes. */ @@ -37,17 +37,18 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.novisit.AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape_Impl readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { case Circle_Impl.CIRCLE__XML_ELEMENT: { - return test.onlyxml.data.Circle_Impl.readCircle_XmlContent(in); + return test.novisit.impl.Circle_Impl.readCircle_XmlContent(in); } case Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - return test.onlyxml.data.Rectangle_Impl.readRectangle_XmlContent(in); + return test.novisit.impl.Rectangle_Impl.readRectangle_XmlContent(in); } default: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java similarity index 74% rename from de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java index 497825d0..a0455037 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java @@ -1,22 +1,22 @@ -package test.novisit; +package test.novisit.impl; /** * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. */ -class Car_Impl extends Shape_Impl implements Car { +public class Car_Impl extends test.novisit.impl.Shape_Impl implements test.novisit.Car { - private Circle _wheel1 = null; + private test.novisit.Circle _wheel1 = null; - private Circle _wheel2 = null; + private test.novisit.Circle _wheel2 = null; - private Rectangle _body = null; + private test.novisit.Rectangle _body = null; /** * Creates a {@link Car_Impl} instance. * - * @see Car#create() + * @see test.novisit.Car#create() */ - protected Car_Impl() { + public Car_Impl() { super(); } @@ -26,18 +26,18 @@ public TypeKind kind() { } @Override - public final Circle getWheel1() { + public final test.novisit.Circle getWheel1() { return _wheel1; } @Override - public Car setWheel1(Circle value) { + public test.novisit.Car setWheel1(test.novisit.Circle value) { internalSetWheel1(value); return this; } /** Internal setter for {@link #getWheel1()} without chain call utility. */ - protected final void internalSetWheel1(Circle value) { + protected final void internalSetWheel1(test.novisit.Circle value) { _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; } @@ -48,18 +48,18 @@ public final boolean hasWheel1() { } @Override - public final Circle getWheel2() { + public final test.novisit.Circle getWheel2() { return _wheel2; } @Override - public Car setWheel2(Circle value) { + public test.novisit.Car setWheel2(test.novisit.Circle value) { internalSetWheel2(value); return this; } /** Internal setter for {@link #getWheel2()} without chain call utility. */ - protected final void internalSetWheel2(Circle value) { + protected final void internalSetWheel2(test.novisit.Circle value) { _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; } @@ -70,18 +70,18 @@ public final boolean hasWheel2() { } @Override - public final Rectangle getBody() { + public final test.novisit.Rectangle getBody() { return _body; } @Override - public Car setBody(Rectangle value) { + public test.novisit.Car setBody(test.novisit.Rectangle value) { internalSetBody(value); return this; } /** Internal setter for {@link #getBody()} without chain call utility. */ - protected final void internalSetBody(Rectangle value) { + protected final void internalSetBody(test.novisit.Rectangle value) { _listener.beforeSet(this, BODY__PROP, value); _body = value; } @@ -92,13 +92,13 @@ public final boolean hasBody() { } @Override - public Car setXCoordinate(int value) { + public test.novisit.Car setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Car setYCoordinate(int value) { + public test.novisit.Car setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -132,9 +132,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; - case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; - case BODY__PROP: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((test.novisit.Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((test.novisit.Circle) value); break; + case BODY__PROP: internalSetBody((test.novisit.Rectangle) value); break; default: super.set(field, value); break; } } @@ -188,9 +188,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } } - /** Helper for creating an object of type {@link Car} from a polymorphic composition. */ - public static Car readCar_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.novisit.Car_Impl result = new Car_Impl(); + /** Helper for creating an object of type {@link test.novisit.Car} from a polymorphic composition. */ + public static test.novisit.Car readCar_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.novisit.impl.Car_Impl result = new Car_Impl(); result.readContent(in); return result; } @@ -205,7 +205,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Car} type. */ + /** XML element name representing a {@link test.novisit.Car} type. */ public static final String CAR__XML_ELEMENT = "car"; /** XML attribute or element name of a {@link #getWheel1} property. */ @@ -249,7 +249,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. } } - /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.novisit.Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); result.readContentXml(in); @@ -269,15 +269,15 @@ protected void readFieldXmlAttribute(String name, String value) { protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { case WHEEL_1__XML_ATTR: { - setWheel1(test.novisit.Circle_Impl.readCircle_XmlContent(in)); + setWheel1(test.novisit.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case WHEEL_2__XML_ATTR: { - setWheel2(test.novisit.Circle_Impl.readCircle_XmlContent(in)); + setWheel2(test.novisit.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case BODY__XML_ATTR: { - setBody(test.novisit.Rectangle_Impl.readRectangle_XmlContent(in)); + setBody(test.novisit.impl.Rectangle_Impl.readRectangle_XmlContent(in)); break; } default: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java similarity index 80% rename from de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java index 9a6de57f..7281b1ff 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java @@ -1,18 +1,18 @@ -package test.novisitexceptions; +package test.novisit.impl; /** * A circle {@link Shape}. */ -class Circle_Impl extends AtomicShape_Impl implements Circle { +public class Circle_Impl extends test.novisit.impl.AtomicShape_Impl implements test.novisit.Circle { private int _radius = 0; /** * Creates a {@link Circle_Impl} instance. * - * @see Circle#create() + * @see test.novisit.Circle#create() */ - protected Circle_Impl() { + public Circle_Impl() { super(); } @@ -27,7 +27,7 @@ public final int getRadius() { } @Override - public Circle setRadius(int value) { + public test.novisit.Circle setRadius(int value) { internalSetRadius(value); return this; } @@ -39,13 +39,13 @@ protected final void internalSetRadius(int value) { } @Override - public Circle setXCoordinate(int value) { + public test.novisit.Circle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Circle setYCoordinate(int value) { + public test.novisit.Circle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -107,9 +107,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getRadius()); } - /** Helper for creating an object of type {@link Circle} from a polymorphic composition. */ - public static Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.novisitexceptions.Circle_Impl result = new Circle_Impl(); + /** Helper for creating an object of type {@link test.novisit.Circle} from a polymorphic composition. */ + public static test.novisit.Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.novisit.impl.Circle_Impl result = new Circle_Impl(); result.readContent(in); return result; } @@ -122,7 +122,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Circle} type. */ + /** XML element name representing a {@link test.novisit.Circle} type. */ public static final String CIRCLE__XML_ELEMENT = "circle"; /** XML attribute or element name of a {@link #getRadius} property. */ @@ -144,9 +144,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.novisit.Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); result.readContentXml(in); @@ -179,9 +180,4 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } } - @Override - public R visit(AtomicShape.Visitor v, A arg) { - return v.visit(this, arg); - } - } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java similarity index 71% rename from de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java index 28ce56be..93c64952 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java @@ -1,18 +1,18 @@ -package test.novisit; +package test.novisit.impl; /** * A group of shapes. */ -class Group_Impl extends Shape_Impl implements Group { +public class Group_Impl extends test.novisit.impl.Shape_Impl implements test.novisit.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override - protected void beforeAdd(int index, Shape element) { + protected void beforeAdd(int index, test.novisit.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); } @Override - protected void afterRemove(int index, Shape element) { + protected void afterRemove(int index, test.novisit.Shape element) { _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } }; @@ -20,9 +20,9 @@ protected void afterRemove(int index, Shape element) { /** * Creates a {@link Group_Impl} instance. * - * @see Group#create() + * @see test.novisit.Group#create() */ - protected Group_Impl() { + public Group_Impl() { super(); } @@ -32,47 +32,47 @@ public TypeKind kind() { } @Override - public final java.util.List getShapes() { + public final java.util.List getShapes() { return _shapes; } @Override - public Group setShapes(java.util.List value) { + public test.novisit.Group setShapes(java.util.List value) { internalSetShapes(value); return this; } /** Internal setter for {@link #getShapes()} without chain call utility. */ - protected final void internalSetShapes(java.util.List value) { + protected final void internalSetShapes(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); _shapes.clear(); _shapes.addAll(value); } @Override - public Group addShape(Shape value) { + public test.novisit.Group addShape(test.novisit.Shape value) { internalAddShape(value); return this; } - /** Implementation of {@link #addShape(Shape)} without chain call utility. */ - protected final void internalAddShape(Shape value) { + /** Implementation of {@link #addShape(test.novisit.Shape)} without chain call utility. */ + protected final void internalAddShape(test.novisit.Shape value) { _shapes.add(value); } @Override - public final void removeShape(Shape value) { + public final void removeShape(test.novisit.Shape value) { _shapes.remove(value); } @Override - public Group setXCoordinate(int value) { + public test.novisit.Group setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Group setYCoordinate(int value) { + public test.novisit.Group setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -102,7 +102,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(test.novisit.Shape.class, value)); break; default: super.set(field, value); break; } } @@ -112,7 +112,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. super.writeFields(out); out.name(SHAPES__PROP); out.beginArray(); - for (Shape x : getShapes()) { + for (test.novisit.Shape x : getShapes()) { x.writeTo(out); } out.endArray(); @@ -143,18 +143,18 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav super.writeFields(out); out.name(SHAPES__ID); { - java.util.List values = getShapes(); + java.util.List values = getShapes(); out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); - for (Shape x : values) { + for (test.novisit.Shape x : values) { x.writeTo(out); } out.endArray(); } } - /** Helper for creating an object of type {@link Group} from a polymorphic composition. */ - public static Group readGroup_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.novisit.Group_Impl result = new Group_Impl(); + /** Helper for creating an object of type {@link test.novisit.Group} from a polymorphic composition. */ + public static test.novisit.Group readGroup_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.novisit.impl.Group_Impl result = new Group_Impl(); result.readContent(in); return result; } @@ -174,7 +174,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Group} type. */ + /** XML element name representing a {@link test.novisit.Group} type. */ public static final String GROUP__XML_ELEMENT = "group"; /** XML attribute or element name of a {@link #getShapes} property. */ @@ -202,7 +202,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. out.writeEndElement(); } - /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.novisit.Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); result.readContentXml(in); @@ -238,7 +238,7 @@ private void internalReadShapesListXml(javax.xml.stream.XMLStreamReader in) thro break; } - addShape(test.novisit.Shape_Impl.readShape_XmlContent(in)); + addShape(test.novisit.impl.Shape_Impl.readShape_XmlContent(in)); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java similarity index 82% rename from de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java index 08a6eeba..99925b4e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java @@ -1,9 +1,9 @@ -package test.novisitexceptions; +package test.novisit.impl; /** * A rectangle. */ -class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { +public class Rectangle_Impl extends test.novisit.impl.AtomicShape_Impl implements test.novisit.Rectangle { private int _width = 0; @@ -12,9 +12,9 @@ class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { /** * Creates a {@link Rectangle_Impl} instance. * - * @see Rectangle#create() + * @see test.novisit.Rectangle#create() */ - protected Rectangle_Impl() { + public Rectangle_Impl() { super(); } @@ -29,7 +29,7 @@ public final int getWidth() { } @Override - public Rectangle setWidth(int value) { + public test.novisit.Rectangle setWidth(int value) { internalSetWidth(value); return this; } @@ -46,7 +46,7 @@ public final int getHeight() { } @Override - public Rectangle setHeight(int value) { + public test.novisit.Rectangle setHeight(int value) { internalSetHeight(value); return this; } @@ -58,13 +58,13 @@ protected final void internalSetHeight(int value) { } @Override - public Rectangle setXCoordinate(int value) { + public test.novisit.Rectangle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Rectangle setYCoordinate(int value) { + public test.novisit.Rectangle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -134,9 +134,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getHeight()); } - /** Helper for creating an object of type {@link Rectangle} from a polymorphic composition. */ - public static Rectangle readRectangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.novisitexceptions.Rectangle_Impl result = new Rectangle_Impl(); + /** Helper for creating an object of type {@link test.novisit.Rectangle} from a polymorphic composition. */ + public static test.novisit.Rectangle readRectangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.novisit.impl.Rectangle_Impl result = new Rectangle_Impl(); result.readContent(in); return result; } @@ -150,7 +150,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Rectangle} type. */ + /** XML element name representing a {@link test.novisit.Rectangle} type. */ public static final String RECTANGLE__XML_ELEMENT = "rectangle"; /** XML attribute or element name of a {@link #getWidth} property. */ @@ -176,9 +176,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.novisit.Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); result.readContentXml(in); @@ -219,9 +220,4 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } } - @Override - public R visit(AtomicShape.Visitor v, A arg) { - return v.visit(this, arg); - } - } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java similarity index 87% rename from de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java index fa1b3d7d..2cc8e03c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java @@ -1,9 +1,9 @@ -package test.novisitexceptions; +package test.novisit.impl; /** * An abstract base class for all shapes */ -abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements Shape { +public abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.novisit.Shape { private int _xCoordinate = 0; @@ -12,7 +12,7 @@ abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject im /** * Creates a {@link Shape_Impl} instance. */ - protected Shape_Impl() { + public Shape_Impl() { super(); } @@ -25,7 +25,7 @@ public final int getXCoordinate() { } @Override - public Shape setXCoordinate(int value) { + public test.novisit.Shape setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @@ -42,7 +42,7 @@ public final int getYCoordinate() { } @Override - public Shape setYCoordinate(int value) { + public test.novisit.Shape setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -56,7 +56,7 @@ protected final void internalSetYCoordinate(int value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public Shape registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.novisit.Shape registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -66,7 +66,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.novisit.Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -90,7 +90,7 @@ public Object get(String field) { switch (field) { case X_COORDINATE__PROP: return getXCoordinate(); case Y_COORDINATE__PROP: return getYCoordinate(); - default: return Shape.super.get(field); + default: return test.novisit.Shape.super.get(field); } } @@ -168,7 +168,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Shape} type. */ + /** XML element name representing a {@link test.novisit.Shape} type. */ public static final String SHAPE__XML_ELEMENT = "shape"; /** XML attribute or element name of a {@link #getXCoordinate} property. */ @@ -191,25 +191,26 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.novisit.Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { case Circle_Impl.CIRCLE__XML_ELEMENT: { - return test.novisitexceptions.Circle_Impl.readCircle_XmlContent(in); + return test.novisit.impl.Circle_Impl.readCircle_XmlContent(in); } case Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - return test.novisitexceptions.Rectangle_Impl.readRectangle_XmlContent(in); + return test.novisit.impl.Rectangle_Impl.readRectangle_XmlContent(in); } case Group_Impl.GROUP__XML_ELEMENT: { - return test.novisitexceptions.Group_Impl.readGroup_XmlContent(in); + return test.novisit.impl.Group_Impl.readGroup_XmlContent(in); } case Car_Impl.CAR__XML_ELEMENT: { - return test.novisitexceptions.Car_Impl.readCar_XmlContent(in); + return test.novisit.impl.Car_Impl.readCar_XmlContent(in); } default: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java similarity index 85% rename from de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java index 8ced3a3f..59c56292 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java @@ -1,9 +1,9 @@ -package test.novisit; +package test.novisit.impl; /** * A concrete type without abstract super type. */ -class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements SimpleType { +public class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.novisit.SimpleType { private String _str = ""; @@ -12,9 +12,9 @@ class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implem /** * Creates a {@link SimpleType_Impl} instance. * - * @see SimpleType#create() + * @see test.novisit.SimpleType#create() */ - protected SimpleType_Impl() { + public SimpleType_Impl() { super(); } @@ -24,7 +24,7 @@ public final String getStr() { } @Override - public SimpleType setStr(String value) { + public test.novisit.SimpleType setStr(String value) { internalSetStr(value); return this; } @@ -41,7 +41,7 @@ public final int getX() { } @Override - public SimpleType setX(int value) { + public test.novisit.SimpleType setX(int value) { internalSetX(value); return this; } @@ -55,7 +55,7 @@ protected final void internalSetX(int value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.novisit.SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -65,7 +65,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.novisit.SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -94,7 +94,7 @@ public Object get(String field) { switch (field) { case STR__PROP: return getStr(); case X__PROP: return getX(); - default: return SimpleType.super.get(field); + default: return test.novisit.SimpleType.super.get(field); } } @@ -150,9 +150,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getX()); } - /** Helper for creating an object of type {@link SimpleType} from a polymorphic composition. */ - public static SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.novisit.SimpleType_Impl result = new SimpleType_Impl(); + /** Helper for creating an object of type {@link test.novisit.SimpleType} from a polymorphic composition. */ + public static test.novisit.SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.novisit.impl.SimpleType_Impl result = new SimpleType_Impl(); result.readContent(in); return result; } @@ -174,7 +174,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link SimpleType} type. */ + /** XML element name representing a {@link test.novisit.SimpleType} type. */ public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; /** XML attribute or element name of a {@link #getStr} property. */ @@ -202,9 +202,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.novisit.SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SimpleType_Impl result = new SimpleType_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/AtomicShape.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/AtomicShape.java index 8200db5c..1c1fc810 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/AtomicShape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/AtomicShape.java @@ -5,26 +5,26 @@ */ public interface AtomicShape extends Shape { - /** Visitor interface for the {@link AtomicShape} hierarchy.*/ + /** Visitor interface for the {@link test.novisitexceptions.AtomicShape} hierarchy.*/ public interface Visitor { - /** Visit case for {@link Circle}.*/ - R visit(Circle self, A arg); + /** Visit case for {@link test.novisitexceptions.Circle}.*/ + R visit(test.novisitexceptions.Circle self, A arg); - /** Visit case for {@link Rectangle}.*/ - R visit(Rectangle self, A arg); + /** Visit case for {@link test.novisitexceptions.Rectangle}.*/ + R visit(test.novisitexceptions.Rectangle self, A arg); } @Override - AtomicShape setXCoordinate(int value); + test.novisitexceptions.AtomicShape setXCoordinate(int value); @Override - AtomicShape setYCoordinate(int value); + test.novisitexceptions.AtomicShape setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - AtomicShape result; + static test.novisitexceptions.AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisitexceptions.AtomicShape result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -37,15 +37,15 @@ static AtomicShape readAtomicShape(de.haumacher.msgbuf.json.JsonReader in) throw } /** Reads a new instance from the given reader. */ - static AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.novisitexceptions.AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); int typeField = in.nextName(); assert typeField == 0; int type = in.nextInt(); - AtomicShape result; + test.novisitexceptions.AtomicShape result; switch (type) { - case Circle.CIRCLE__TYPE_ID: result = test.novisitexceptions.Circle_Impl.readCircle_Content(in); break; - case Rectangle.RECTANGLE__TYPE_ID: result = test.novisitexceptions.Rectangle_Impl.readRectangle_Content(in); break; + case test.novisitexceptions.Circle.CIRCLE__TYPE_ID: result = test.novisitexceptions.impl.Circle_Impl.readCircle_Content(in); break; + case test.novisitexceptions.Rectangle.RECTANGLE__TYPE_ID: result = test.novisitexceptions.impl.Rectangle_Impl.readRectangle_Content(in); break; default: result = null; while (in.hasNext()) {in.skipValue(); } } in.endObject(); @@ -55,7 +55,7 @@ static AtomicShape readAtomicShape(de.haumacher.msgbuf.binary.DataReader in) thr /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape readAtomicShape(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.novisitexceptions.AtomicShape_Impl.readAtomicShape_XmlContent(in); + return test.novisitexceptions.impl.AtomicShape_Impl.readAtomicShape_XmlContent(in); } /** Accepts the given visitor. */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java index 3dd4f794..90e80573 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java @@ -6,13 +6,13 @@ public interface Car extends Shape { /** - * Creates a {@link Car} instance. + * Creates a {@link test.novisitexceptions.Car} instance. */ - static Car create() { - return new test.novisitexceptions.Car_Impl(); + static test.novisitexceptions.Car create() { + return new test.novisitexceptions.impl.Car_Impl(); } - /** Identifier for the {@link Car} type in JSON format. */ + /** Identifier for the {@link test.novisitexceptions.Car} type in JSON format. */ static final String CAR__TYPE = "Car"; /** @see #getWheel1() */ @@ -24,7 +24,7 @@ static Car create() { /** @see #getBody() */ static final String BODY__PROP = "body"; - /** Identifier for the {@link Car} type in binary format. */ + /** Identifier for the {@link test.novisitexceptions.Car} type in binary format. */ static final int CAR__TYPE_ID = 4; /** Identifier for the property {@link #getWheel1()} in binary format. */ @@ -39,12 +39,12 @@ static Car create() { /** * The front wheel. */ - Circle getWheel1(); + test.novisitexceptions.Circle getWheel1(); /** * @see #getWheel1() */ - Car setWheel1(Circle value); + test.novisitexceptions.Car setWheel1(test.novisitexceptions.Circle value); /** * Checks, whether {@link #getWheel1()} has a value. @@ -54,12 +54,12 @@ static Car create() { /** * The back wheel. */ - Circle getWheel2(); + test.novisitexceptions.Circle getWheel2(); /** * @see #getWheel2() */ - Car setWheel2(Circle value); + test.novisitexceptions.Car setWheel2(test.novisitexceptions.Circle value); /** * Checks, whether {@link #getWheel2()} has a value. @@ -69,12 +69,12 @@ static Car create() { /** * The car body. */ - Rectangle getBody(); + test.novisitexceptions.Rectangle getBody(); /** * @see #getBody() */ - Car setBody(Rectangle value); + test.novisitexceptions.Car setBody(test.novisitexceptions.Rectangle value); /** * Checks, whether {@link #getBody()} has a value. @@ -82,22 +82,22 @@ static Car create() { boolean hasBody(); @Override - Car setXCoordinate(int value); + test.novisitexceptions.Car setXCoordinate(int value); @Override - Car setYCoordinate(int value); + test.novisitexceptions.Car setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.novisitexceptions.Car_Impl result = new test.novisitexceptions.Car_Impl(); + static test.novisitexceptions.Car readCar(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisitexceptions.impl.Car_Impl result = new test.novisitexceptions.impl.Car_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.novisitexceptions.Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Car result = test.novisitexceptions.Car_Impl.readCar_Content(in); + test.novisitexceptions.Car result = test.novisitexceptions.impl.Car_Impl.readCar_Content(in); in.endObject(); return result; } @@ -105,7 +105,7 @@ static Car readCar(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOEx /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car readCar(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.novisitexceptions.Car_Impl.readCar_XmlContent(in); + return test.novisitexceptions.impl.Car_Impl.readCar_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java index b2e09609..9f45efb6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java @@ -6,19 +6,19 @@ public interface Circle extends AtomicShape { /** - * Creates a {@link Circle} instance. + * Creates a {@link test.novisitexceptions.Circle} instance. */ - static Circle create() { - return new test.novisitexceptions.Circle_Impl(); + static test.novisitexceptions.Circle create() { + return new test.novisitexceptions.impl.Circle_Impl(); } - /** Identifier for the {@link Circle} type in JSON format. */ + /** Identifier for the {@link test.novisitexceptions.Circle} type in JSON format. */ static final String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ static final String RADIUS__PROP = "r"; - /** Identifier for the {@link Circle} type in binary format. */ + /** Identifier for the {@link test.novisitexceptions.Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; /** Identifier for the property {@link #getRadius()} in binary format. */ @@ -32,25 +32,25 @@ static Circle create() { /** * @see #getRadius() */ - Circle setRadius(int value); + test.novisitexceptions.Circle setRadius(int value); @Override - Circle setXCoordinate(int value); + test.novisitexceptions.Circle setXCoordinate(int value); @Override - Circle setYCoordinate(int value); + test.novisitexceptions.Circle setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.novisitexceptions.Circle_Impl result = new test.novisitexceptions.Circle_Impl(); + static test.novisitexceptions.Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisitexceptions.impl.Circle_Impl result = new test.novisitexceptions.impl.Circle_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.novisitexceptions.Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Circle result = test.novisitexceptions.Circle_Impl.readCircle_Content(in); + test.novisitexceptions.Circle result = test.novisitexceptions.impl.Circle_Impl.readCircle_Content(in); in.endObject(); return result; } @@ -58,7 +58,7 @@ static Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.i /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle readCircle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.novisitexceptions.Circle_Impl.readCircle_XmlContent(in); + return test.novisitexceptions.impl.Circle_Impl.readCircle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java index c9fd4b25..2517d469 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java @@ -6,19 +6,19 @@ public interface Group extends Shape { /** - * Creates a {@link Group} instance. + * Creates a {@link test.novisitexceptions.Group} instance. */ - static Group create() { - return new test.novisitexceptions.Group_Impl(); + static test.novisitexceptions.Group create() { + return new test.novisitexceptions.impl.Group_Impl(); } - /** Identifier for the {@link Group} type in JSON format. */ + /** Identifier for the {@link test.novisitexceptions.Group} type in JSON format. */ static final String GROUP__TYPE = "Group"; /** @see #getShapes() */ static final String SHAPES__PROP = "shapes"; - /** Identifier for the {@link Group} type in binary format. */ + /** Identifier for the {@link test.novisitexceptions.Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; /** Identifier for the property {@link #getShapes()} in binary format. */ @@ -31,40 +31,40 @@ static Group create() { * The origins of these {@link Shape}s get a coordinate offset of ({@link #getXCoordinate()}, {@link #getYCoordinate()}). *

*/ - java.util.List getShapes(); + java.util.List getShapes(); /** * @see #getShapes() */ - Group setShapes(java.util.List value); + test.novisitexceptions.Group setShapes(java.util.List value); /** * Adds a value to the {@link #getShapes()} list. */ - Group addShape(Shape value); + test.novisitexceptions.Group addShape(test.novisitexceptions.Shape value); /** * Removes a value from the {@link #getShapes()} list. */ - void removeShape(Shape value); + void removeShape(test.novisitexceptions.Shape value); @Override - Group setXCoordinate(int value); + test.novisitexceptions.Group setXCoordinate(int value); @Override - Group setYCoordinate(int value); + test.novisitexceptions.Group setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.novisitexceptions.Group_Impl result = new test.novisitexceptions.Group_Impl(); + static test.novisitexceptions.Group readGroup(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisitexceptions.impl.Group_Impl result = new test.novisitexceptions.impl.Group_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.novisitexceptions.Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Group result = test.novisitexceptions.Group_Impl.readGroup_Content(in); + test.novisitexceptions.Group result = test.novisitexceptions.impl.Group_Impl.readGroup_Content(in); in.endObject(); return result; } @@ -72,7 +72,7 @@ static Group readGroup(de.haumacher.msgbuf.binary.DataReader in) throws java.io. /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group readGroup(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.novisitexceptions.Group_Impl.readGroup_XmlContent(in); + return test.novisitexceptions.impl.Group_Impl.readGroup_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java index 85191587..93e80a91 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java @@ -6,13 +6,13 @@ public interface Rectangle extends AtomicShape { /** - * Creates a {@link Rectangle} instance. + * Creates a {@link test.novisitexceptions.Rectangle} instance. */ - static Rectangle create() { - return new test.novisitexceptions.Rectangle_Impl(); + static test.novisitexceptions.Rectangle create() { + return new test.novisitexceptions.impl.Rectangle_Impl(); } - /** Identifier for the {@link Rectangle} type in JSON format. */ + /** Identifier for the {@link test.novisitexceptions.Rectangle} type in JSON format. */ static final String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ @@ -21,7 +21,7 @@ static Rectangle create() { /** @see #getHeight() */ static final String HEIGHT__PROP = "h"; - /** Identifier for the {@link Rectangle} type in binary format. */ + /** Identifier for the {@link test.novisitexceptions.Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; /** Identifier for the property {@link #getWidth()} in binary format. */ @@ -44,7 +44,7 @@ static Rectangle create() { /** * @see #getWidth() */ - Rectangle setWidth(int value); + test.novisitexceptions.Rectangle setWidth(int value); /** * The width of this {@link Rectangle}. @@ -56,25 +56,25 @@ static Rectangle create() { /** * @see #getHeight() */ - Rectangle setHeight(int value); + test.novisitexceptions.Rectangle setHeight(int value); @Override - Rectangle setXCoordinate(int value); + test.novisitexceptions.Rectangle setXCoordinate(int value); @Override - Rectangle setYCoordinate(int value); + test.novisitexceptions.Rectangle setYCoordinate(int value); /** Reads a new instance from the given reader. */ - static Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.novisitexceptions.Rectangle_Impl result = new test.novisitexceptions.Rectangle_Impl(); + static test.novisitexceptions.Rectangle readRectangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisitexceptions.impl.Rectangle_Impl result = new test.novisitexceptions.impl.Rectangle_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.novisitexceptions.Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Rectangle result = test.novisitexceptions.Rectangle_Impl.readRectangle_Content(in); + test.novisitexceptions.Rectangle result = test.novisitexceptions.impl.Rectangle_Impl.readRectangle_Content(in); in.endObject(); return result; } @@ -82,7 +82,7 @@ static Rectangle readRectangle(de.haumacher.msgbuf.binary.DataReader in) throws /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle readRectangle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.novisitexceptions.Rectangle_Impl.readRectangle_XmlContent(in); + return test.novisitexceptions.impl.Rectangle_Impl.readRectangle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java index 72144dde..e84a53c9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java @@ -5,32 +5,32 @@ */ public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { - /** Type codes for the {@link Shape} hierarchy. */ + /** Type codes for the {@link test.novisitexceptions.Shape} hierarchy. */ public enum TypeKind { - /** Type literal for {@link Circle}. */ + /** Type literal for {@link test.novisitexceptions.Circle}. */ CIRCLE, - /** Type literal for {@link Rectangle}. */ + /** Type literal for {@link test.novisitexceptions.Rectangle}. */ RECTANGLE, - /** Type literal for {@link Group}. */ + /** Type literal for {@link test.novisitexceptions.Group}. */ GROUP, - /** Type literal for {@link Car}. */ + /** Type literal for {@link test.novisitexceptions.Car}. */ CAR, ; } - /** Visitor interface for the {@link Shape} hierarchy.*/ - public interface Visitor extends AtomicShape.Visitor { + /** Visitor interface for the {@link test.novisitexceptions.Shape} hierarchy.*/ + public interface Visitor extends test.novisitexceptions.AtomicShape.Visitor { - /** Visit case for {@link Group}.*/ - R visit(Group self, A arg); + /** Visit case for {@link test.novisitexceptions.Group}.*/ + R visit(test.novisitexceptions.Group self, A arg); - /** Visit case for {@link Car}.*/ - R visit(Car self, A arg); + /** Visit case for {@link test.novisitexceptions.Car}.*/ + R visit(test.novisitexceptions.Car self, A arg); } @@ -57,7 +57,7 @@ public interface Visitor extends AtomicShape.Visitor { /** * @see #getXCoordinate() */ - Shape setXCoordinate(int value); + test.novisitexceptions.Shape setXCoordinate(int value); /** * Y coordinate of the origin of the coordinate system of this {@link Shape}. @@ -67,17 +67,17 @@ public interface Visitor extends AtomicShape.Visitor { /** * @see #getYCoordinate() */ - Shape setYCoordinate(int value); + test.novisitexceptions.Shape setYCoordinate(int value); @Override - public Shape registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.novisitexceptions.Shape registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.novisitexceptions.Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static Shape readShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - Shape result; + static test.novisitexceptions.Shape readShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisitexceptions.Shape result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -91,21 +91,21 @@ static Shape readShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IO return result; } - /** The binary identifier for this concrete type in the polymorphic {@link Shape} hierarchy. */ + /** The binary identifier for this concrete type in the polymorphic {@link test.novisitexceptions.Shape} hierarchy. */ abstract int typeId(); /** Reads a new instance from the given reader. */ - static Shape readShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.novisitexceptions.Shape readShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); int typeField = in.nextName(); assert typeField == 0; int type = in.nextInt(); - Shape result; + test.novisitexceptions.Shape result; switch (type) { - case Group.GROUP__TYPE_ID: result = test.novisitexceptions.Group_Impl.readGroup_Content(in); break; - case Car.CAR__TYPE_ID: result = test.novisitexceptions.Car_Impl.readCar_Content(in); break; - case Circle.CIRCLE__TYPE_ID: result = test.novisitexceptions.Circle_Impl.readCircle_Content(in); break; - case Rectangle.RECTANGLE__TYPE_ID: result = test.novisitexceptions.Rectangle_Impl.readRectangle_Content(in); break; + case test.novisitexceptions.Group.GROUP__TYPE_ID: result = test.novisitexceptions.impl.Group_Impl.readGroup_Content(in); break; + case test.novisitexceptions.Car.CAR__TYPE_ID: result = test.novisitexceptions.impl.Car_Impl.readCar_Content(in); break; + case test.novisitexceptions.Circle.CIRCLE__TYPE_ID: result = test.novisitexceptions.impl.Circle_Impl.readCircle_Content(in); break; + case test.novisitexceptions.Rectangle.RECTANGLE__TYPE_ID: result = test.novisitexceptions.impl.Rectangle_Impl.readRectangle_Content(in); break; default: result = null; while (in.hasNext()) {in.skipValue(); } } in.endObject(); @@ -115,7 +115,7 @@ static Shape readShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io. /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape readShape(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.novisitexceptions.Shape_Impl.readShape_XmlContent(in); + return test.novisitexceptions.impl.Shape_Impl.readShape_XmlContent(in); } /** Accepts the given visitor. */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType.java index c3e2030d..a7e67118 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType.java @@ -6,13 +6,13 @@ public interface SimpleType extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link SimpleType} instance. + * Creates a {@link test.novisitexceptions.SimpleType} instance. */ - static SimpleType create() { - return new test.novisitexceptions.SimpleType_Impl(); + static test.novisitexceptions.SimpleType create() { + return new test.novisitexceptions.impl.SimpleType_Impl(); } - /** Identifier for the {@link SimpleType} type in JSON format. */ + /** Identifier for the {@link test.novisitexceptions.SimpleType} type in JSON format. */ static final String SIMPLE_TYPE__TYPE = "SimpleType"; /** @see #getStr() */ @@ -35,7 +35,7 @@ static SimpleType create() { /** * @see #getStr() */ - SimpleType setStr(String value); + test.novisitexceptions.SimpleType setStr(String value); /** * An int property @@ -45,25 +45,25 @@ static SimpleType create() { /** * @see #getX() */ - SimpleType setX(int value); + test.novisitexceptions.SimpleType setX(int value); @Override - public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.novisitexceptions.SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.novisitexceptions.SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.novisitexceptions.SimpleType_Impl result = new test.novisitexceptions.SimpleType_Impl(); + static test.novisitexceptions.SimpleType readSimpleType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.novisitexceptions.impl.SimpleType_Impl result = new test.novisitexceptions.impl.SimpleType_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static SimpleType readSimpleType(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.novisitexceptions.SimpleType readSimpleType(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - SimpleType result = test.novisitexceptions.SimpleType_Impl.readSimpleType_Content(in); + test.novisitexceptions.SimpleType result = test.novisitexceptions.impl.SimpleType_Impl.readSimpleType_Content(in); in.endObject(); return result; } @@ -71,7 +71,7 @@ static SimpleType readSimpleType(de.haumacher.msgbuf.binary.DataReader in) throw /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SimpleType readSimpleType(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.novisitexceptions.SimpleType_Impl.readSimpleType_XmlContent(in); + return test.novisitexceptions.impl.SimpleType_Impl.readSimpleType_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/AtomicShape_Impl.java new file mode 100644 index 00000000..b219afd6 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/AtomicShape_Impl.java @@ -0,0 +1,84 @@ +package test.novisitexceptions.impl; + +/** + * A {@link Shape} that has no sub-shapes. + */ +public abstract class AtomicShape_Impl extends test.novisitexceptions.impl.Shape_Impl implements test.novisitexceptions.AtomicShape { + + /** + * Creates a {@link AtomicShape_Impl} instance. + */ + public AtomicShape_Impl() { + super(); + } + + @Override + public test.novisitexceptions.AtomicShape setXCoordinate(int value) { + internalSetXCoordinate(value); + return this; + } + + @Override + public test.novisitexceptions.AtomicShape setYCoordinate(int value) { + internalSetYCoordinate(value); + return this; + } + + /** XML element name representing a {@link test.novisitexceptions.AtomicShape} type. */ + public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.novisitexceptions.AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static AtomicShape_Impl readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case Circle_Impl.CIRCLE__XML_ELEMENT: { + return test.novisitexceptions.impl.Circle_Impl.readCircle_XmlContent(in); + } + + case Rectangle_Impl.RECTANGLE__XML_ELEMENT: { + return test.novisitexceptions.impl.Rectangle_Impl.readRectangle_XmlContent(in); + } + + default: { + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public final R visit(test.novisitexceptions.Shape.Visitor v, A arg) { + return visit((test.novisitexceptions.AtomicShape.Visitor) v, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java similarity index 71% rename from de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java index 80685b93..95e16555 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java @@ -1,22 +1,22 @@ -package test.novisitexceptions; +package test.novisitexceptions.impl; /** * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. */ -class Car_Impl extends Shape_Impl implements Car { +public class Car_Impl extends test.novisitexceptions.impl.Shape_Impl implements test.novisitexceptions.Car { - private Circle _wheel1 = null; + private test.novisitexceptions.Circle _wheel1 = null; - private Circle _wheel2 = null; + private test.novisitexceptions.Circle _wheel2 = null; - private Rectangle _body = null; + private test.novisitexceptions.Rectangle _body = null; /** * Creates a {@link Car_Impl} instance. * - * @see Car#create() + * @see test.novisitexceptions.Car#create() */ - protected Car_Impl() { + public Car_Impl() { super(); } @@ -26,18 +26,18 @@ public TypeKind kind() { } @Override - public final Circle getWheel1() { + public final test.novisitexceptions.Circle getWheel1() { return _wheel1; } @Override - public Car setWheel1(Circle value) { + public test.novisitexceptions.Car setWheel1(test.novisitexceptions.Circle value) { internalSetWheel1(value); return this; } /** Internal setter for {@link #getWheel1()} without chain call utility. */ - protected final void internalSetWheel1(Circle value) { + protected final void internalSetWheel1(test.novisitexceptions.Circle value) { _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; } @@ -48,18 +48,18 @@ public final boolean hasWheel1() { } @Override - public final Circle getWheel2() { + public final test.novisitexceptions.Circle getWheel2() { return _wheel2; } @Override - public Car setWheel2(Circle value) { + public test.novisitexceptions.Car setWheel2(test.novisitexceptions.Circle value) { internalSetWheel2(value); return this; } /** Internal setter for {@link #getWheel2()} without chain call utility. */ - protected final void internalSetWheel2(Circle value) { + protected final void internalSetWheel2(test.novisitexceptions.Circle value) { _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; } @@ -70,18 +70,18 @@ public final boolean hasWheel2() { } @Override - public final Rectangle getBody() { + public final test.novisitexceptions.Rectangle getBody() { return _body; } @Override - public Car setBody(Rectangle value) { + public test.novisitexceptions.Car setBody(test.novisitexceptions.Rectangle value) { internalSetBody(value); return this; } /** Internal setter for {@link #getBody()} without chain call utility. */ - protected final void internalSetBody(Rectangle value) { + protected final void internalSetBody(test.novisitexceptions.Rectangle value) { _listener.beforeSet(this, BODY__PROP, value); _body = value; } @@ -92,13 +92,13 @@ public final boolean hasBody() { } @Override - public Car setXCoordinate(int value) { + public test.novisitexceptions.Car setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Car setYCoordinate(int value) { + public test.novisitexceptions.Car setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -132,9 +132,9 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case WHEEL_1__PROP: internalSetWheel1((Circle) value); break; - case WHEEL_2__PROP: internalSetWheel2((Circle) value); break; - case BODY__PROP: internalSetBody((Rectangle) value); break; + case WHEEL_1__PROP: internalSetWheel1((test.novisitexceptions.Circle) value); break; + case WHEEL_2__PROP: internalSetWheel2((test.novisitexceptions.Circle) value); break; + case BODY__PROP: internalSetBody((test.novisitexceptions.Rectangle) value); break; default: super.set(field, value); break; } } @@ -188,9 +188,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } } - /** Helper for creating an object of type {@link Car} from a polymorphic composition. */ - public static Car readCar_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.novisitexceptions.Car_Impl result = new Car_Impl(); + /** Helper for creating an object of type {@link test.novisitexceptions.Car} from a polymorphic composition. */ + public static test.novisitexceptions.Car readCar_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.novisitexceptions.impl.Car_Impl result = new Car_Impl(); result.readContent(in); return result; } @@ -205,7 +205,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Car} type. */ + /** XML element name representing a {@link test.novisitexceptions.Car} type. */ public static final String CAR__XML_ELEMENT = "car"; /** XML attribute or element name of a {@link #getWheel1} property. */ @@ -249,7 +249,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. } } - /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.novisitexceptions.Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); result.readContentXml(in); @@ -269,15 +269,15 @@ protected void readFieldXmlAttribute(String name, String value) { protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { case WHEEL_1__XML_ATTR: { - setWheel1(test.novisitexceptions.Circle_Impl.readCircle_XmlContent(in)); + setWheel1(test.novisitexceptions.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case WHEEL_2__XML_ATTR: { - setWheel2(test.novisitexceptions.Circle_Impl.readCircle_XmlContent(in)); + setWheel2(test.novisitexceptions.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case BODY__XML_ATTR: { - setBody(test.novisitexceptions.Rectangle_Impl.readRectangle_XmlContent(in)); + setBody(test.novisitexceptions.impl.Rectangle_Impl.readRectangle_XmlContent(in)); break; } default: { @@ -287,7 +287,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(Shape.Visitor v, A arg) { + public R visit(test.novisitexceptions.Shape.Visitor v, A arg) { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java similarity index 76% rename from de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java index 447a2adc..40a5ec86 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java @@ -1,18 +1,18 @@ -package test.novisit; +package test.novisitexceptions.impl; /** * A circle {@link Shape}. */ -class Circle_Impl extends AtomicShape_Impl implements Circle { +public class Circle_Impl extends test.novisitexceptions.impl.AtomicShape_Impl implements test.novisitexceptions.Circle { private int _radius = 0; /** * Creates a {@link Circle_Impl} instance. * - * @see Circle#create() + * @see test.novisitexceptions.Circle#create() */ - protected Circle_Impl() { + public Circle_Impl() { super(); } @@ -27,7 +27,7 @@ public final int getRadius() { } @Override - public Circle setRadius(int value) { + public test.novisitexceptions.Circle setRadius(int value) { internalSetRadius(value); return this; } @@ -39,13 +39,13 @@ protected final void internalSetRadius(int value) { } @Override - public Circle setXCoordinate(int value) { + public test.novisitexceptions.Circle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Circle setYCoordinate(int value) { + public test.novisitexceptions.Circle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -107,9 +107,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getRadius()); } - /** Helper for creating an object of type {@link Circle} from a polymorphic composition. */ - public static Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.novisit.Circle_Impl result = new Circle_Impl(); + /** Helper for creating an object of type {@link test.novisitexceptions.Circle} from a polymorphic composition. */ + public static test.novisitexceptions.Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.novisitexceptions.impl.Circle_Impl result = new Circle_Impl(); result.readContent(in); return result; } @@ -122,7 +122,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Circle} type. */ + /** XML element name representing a {@link test.novisitexceptions.Circle} type. */ public static final String CIRCLE__XML_ELEMENT = "circle"; /** XML attribute or element name of a {@link #getRadius} property. */ @@ -144,9 +144,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.novisitexceptions.Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); result.readContentXml(in); @@ -179,4 +180,9 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } } + @Override + public R visit(test.novisitexceptions.AtomicShape.Visitor v, A arg) { + return v.visit(this, arg); + } + } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java similarity index 68% rename from de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java index c548d878..57bc4aa3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java @@ -1,18 +1,18 @@ -package test.novisitexceptions; +package test.novisitexceptions.impl; /** * A group of shapes. */ -class Group_Impl extends Shape_Impl implements Group { +public class Group_Impl extends test.novisitexceptions.impl.Shape_Impl implements test.novisitexceptions.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override - protected void beforeAdd(int index, Shape element) { + protected void beforeAdd(int index, test.novisitexceptions.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); } @Override - protected void afterRemove(int index, Shape element) { + protected void afterRemove(int index, test.novisitexceptions.Shape element) { _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } }; @@ -20,9 +20,9 @@ protected void afterRemove(int index, Shape element) { /** * Creates a {@link Group_Impl} instance. * - * @see Group#create() + * @see test.novisitexceptions.Group#create() */ - protected Group_Impl() { + public Group_Impl() { super(); } @@ -32,47 +32,47 @@ public TypeKind kind() { } @Override - public final java.util.List getShapes() { + public final java.util.List getShapes() { return _shapes; } @Override - public Group setShapes(java.util.List value) { + public test.novisitexceptions.Group setShapes(java.util.List value) { internalSetShapes(value); return this; } /** Internal setter for {@link #getShapes()} without chain call utility. */ - protected final void internalSetShapes(java.util.List value) { + protected final void internalSetShapes(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); _shapes.clear(); _shapes.addAll(value); } @Override - public Group addShape(Shape value) { + public test.novisitexceptions.Group addShape(test.novisitexceptions.Shape value) { internalAddShape(value); return this; } - /** Implementation of {@link #addShape(Shape)} without chain call utility. */ - protected final void internalAddShape(Shape value) { + /** Implementation of {@link #addShape(test.novisitexceptions.Shape)} without chain call utility. */ + protected final void internalAddShape(test.novisitexceptions.Shape value) { _shapes.add(value); } @Override - public final void removeShape(Shape value) { + public final void removeShape(test.novisitexceptions.Shape value) { _shapes.remove(value); } @Override - public Group setXCoordinate(int value) { + public test.novisitexceptions.Group setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Group setYCoordinate(int value) { + public test.novisitexceptions.Group setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -102,7 +102,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(Shape.class, value)); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(test.novisitexceptions.Shape.class, value)); break; default: super.set(field, value); break; } } @@ -112,7 +112,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. super.writeFields(out); out.name(SHAPES__PROP); out.beginArray(); - for (Shape x : getShapes()) { + for (test.novisitexceptions.Shape x : getShapes()) { x.writeTo(out); } out.endArray(); @@ -143,18 +143,18 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav super.writeFields(out); out.name(SHAPES__ID); { - java.util.List values = getShapes(); + java.util.List values = getShapes(); out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); - for (Shape x : values) { + for (test.novisitexceptions.Shape x : values) { x.writeTo(out); } out.endArray(); } } - /** Helper for creating an object of type {@link Group} from a polymorphic composition. */ - public static Group readGroup_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.novisitexceptions.Group_Impl result = new Group_Impl(); + /** Helper for creating an object of type {@link test.novisitexceptions.Group} from a polymorphic composition. */ + public static test.novisitexceptions.Group readGroup_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.novisitexceptions.impl.Group_Impl result = new Group_Impl(); result.readContent(in); return result; } @@ -174,7 +174,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Group} type. */ + /** XML element name representing a {@link test.novisitexceptions.Group} type. */ public static final String GROUP__XML_ELEMENT = "group"; /** XML attribute or element name of a {@link #getShapes} property. */ @@ -202,7 +202,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. out.writeEndElement(); } - /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.novisitexceptions.Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); result.readContentXml(in); @@ -238,12 +238,12 @@ private void internalReadShapesListXml(javax.xml.stream.XMLStreamReader in) thro break; } - addShape(test.novisitexceptions.Shape_Impl.readShape_XmlContent(in)); + addShape(test.novisitexceptions.impl.Shape_Impl.readShape_XmlContent(in)); } } @Override - public R visit(Shape.Visitor v, A arg) { + public R visit(test.novisitexceptions.Shape.Visitor v, A arg) { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java similarity index 79% rename from de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java index 3548e137..3d0ad51d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java @@ -1,9 +1,9 @@ -package test.hierarchy.data; +package test.novisitexceptions.impl; /** * A rectangle. */ -class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { +public class Rectangle_Impl extends test.novisitexceptions.impl.AtomicShape_Impl implements test.novisitexceptions.Rectangle { private int _width = 0; @@ -12,9 +12,9 @@ class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { /** * Creates a {@link Rectangle_Impl} instance. * - * @see Rectangle#create() + * @see test.novisitexceptions.Rectangle#create() */ - protected Rectangle_Impl() { + public Rectangle_Impl() { super(); } @@ -29,7 +29,7 @@ public final int getWidth() { } @Override - public Rectangle setWidth(int value) { + public test.novisitexceptions.Rectangle setWidth(int value) { internalSetWidth(value); return this; } @@ -46,7 +46,7 @@ public final int getHeight() { } @Override - public Rectangle setHeight(int value) { + public test.novisitexceptions.Rectangle setHeight(int value) { internalSetHeight(value); return this; } @@ -58,23 +58,17 @@ protected final void internalSetHeight(int value) { } @Override - public Rectangle setXCoordinate(int value) { + public test.novisitexceptions.Rectangle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Rectangle setYCoordinate(int value) { + public test.novisitexceptions.Rectangle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } - @Override - public Rectangle setColor(Color value) { - internalSetColor(value); - return this; - } - @Override public String jsonType() { return RECTANGLE__TYPE; @@ -140,9 +134,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getHeight()); } - /** Helper for creating an object of type {@link Rectangle} from a polymorphic composition. */ - public static Rectangle readRectangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.hierarchy.data.Rectangle_Impl result = new Rectangle_Impl(); + /** Helper for creating an object of type {@link test.novisitexceptions.Rectangle} from a polymorphic composition. */ + public static test.novisitexceptions.Rectangle readRectangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.novisitexceptions.impl.Rectangle_Impl result = new Rectangle_Impl(); result.readContent(in); return result; } @@ -156,7 +150,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Rectangle} type. */ + /** XML element name representing a {@link test.novisitexceptions.Rectangle} type. */ public static final String RECTANGLE__XML_ELEMENT = "rectangle"; /** XML attribute or element name of a {@link #getWidth} property. */ @@ -182,9 +176,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.novisitexceptions.Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); result.readContentXml(in); @@ -226,7 +221,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(AtomicShape.Visitor v, A arg) throws E { + public R visit(test.novisitexceptions.AtomicShape.Visitor v, A arg) { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java similarity index 85% rename from de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java index 95203059..4e5c9f9f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java @@ -1,9 +1,9 @@ -package test.notypekind; +package test.novisitexceptions.impl; /** * An abstract base class for all shapes */ -abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements Shape { +public abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.novisitexceptions.Shape { private int _xCoordinate = 0; @@ -12,17 +12,20 @@ abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject im /** * Creates a {@link Shape_Impl} instance. */ - protected Shape_Impl() { + public Shape_Impl() { super(); } + /** The type code of this instance. */ + public abstract TypeKind kind(); + @Override public final int getXCoordinate() { return _xCoordinate; } @Override - public Shape setXCoordinate(int value) { + public test.novisitexceptions.Shape setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @@ -39,7 +42,7 @@ public final int getYCoordinate() { } @Override - public Shape setYCoordinate(int value) { + public test.novisitexceptions.Shape setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -53,7 +56,7 @@ protected final void internalSetYCoordinate(int value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public Shape registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.novisitexceptions.Shape registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -63,7 +66,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.novisitexceptions.Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -87,7 +90,7 @@ public Object get(String field) { switch (field) { case X_COORDINATE__PROP: return getXCoordinate(); case Y_COORDINATE__PROP: return getYCoordinate(); - default: return Shape.super.get(field); + default: return test.novisitexceptions.Shape.super.get(field); } } @@ -165,7 +168,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link Shape} type. */ + /** XML element name representing a {@link test.novisitexceptions.Shape} type. */ public static final String SHAPE__XML_ELEMENT = "shape"; /** XML attribute or element name of a {@link #getXCoordinate} property. */ @@ -188,25 +191,26 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.novisitexceptions.Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { case Circle_Impl.CIRCLE__XML_ELEMENT: { - return test.notypekind.Circle_Impl.readCircle_XmlContent(in); + return test.novisitexceptions.impl.Circle_Impl.readCircle_XmlContent(in); } case Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - return test.notypekind.Rectangle_Impl.readRectangle_XmlContent(in); + return test.novisitexceptions.impl.Rectangle_Impl.readRectangle_XmlContent(in); } case Group_Impl.GROUP__XML_ELEMENT: { - return test.notypekind.Group_Impl.readGroup_XmlContent(in); + return test.novisitexceptions.impl.Group_Impl.readGroup_XmlContent(in); } case Car_Impl.CAR__XML_ELEMENT: { - return test.notypekind.Car_Impl.readCar_XmlContent(in); + return test.novisitexceptions.impl.Car_Impl.readCar_XmlContent(in); } default: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java similarity index 84% rename from de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java index 7d4a9fc2..c28a09ba 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java @@ -1,9 +1,9 @@ -package test.novisitexceptions; +package test.novisitexceptions.impl; /** * A concrete type without abstract super type. */ -class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements SimpleType { +public class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.novisitexceptions.SimpleType { private String _str = ""; @@ -12,9 +12,9 @@ class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implem /** * Creates a {@link SimpleType_Impl} instance. * - * @see SimpleType#create() + * @see test.novisitexceptions.SimpleType#create() */ - protected SimpleType_Impl() { + public SimpleType_Impl() { super(); } @@ -24,7 +24,7 @@ public final String getStr() { } @Override - public SimpleType setStr(String value) { + public test.novisitexceptions.SimpleType setStr(String value) { internalSetStr(value); return this; } @@ -41,7 +41,7 @@ public final int getX() { } @Override - public SimpleType setX(int value) { + public test.novisitexceptions.SimpleType setX(int value) { internalSetX(value); return this; } @@ -55,7 +55,7 @@ protected final void internalSetX(int value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.novisitexceptions.SimpleType registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -65,7 +65,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.novisitexceptions.SimpleType unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -94,7 +94,7 @@ public Object get(String field) { switch (field) { case STR__PROP: return getStr(); case X__PROP: return getX(); - default: return SimpleType.super.get(field); + default: return test.novisitexceptions.SimpleType.super.get(field); } } @@ -150,9 +150,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getX()); } - /** Helper for creating an object of type {@link SimpleType} from a polymorphic composition. */ - public static SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.novisitexceptions.SimpleType_Impl result = new SimpleType_Impl(); + /** Helper for creating an object of type {@link test.novisitexceptions.SimpleType} from a polymorphic composition. */ + public static test.novisitexceptions.SimpleType readSimpleType_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.novisitexceptions.impl.SimpleType_Impl result = new SimpleType_Impl(); result.readContent(in); return result; } @@ -174,7 +174,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link SimpleType} type. */ + /** XML element name representing a {@link test.novisitexceptions.SimpleType} type. */ public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; /** XML attribute or element name of a {@link #getStr} property. */ @@ -202,9 +202,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.novisitexceptions.SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SimpleType_Impl result = new SimpleType_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java index 202bffd8..987136fe 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java @@ -3,13 +3,13 @@ public interface NullableValues extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.data.ReflectiveDataObject, de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link NullableValues} instance. + * Creates a {@link test.nullable.data.NullableValues} instance. */ - static NullableValues create() { - return new test.nullable.data.NullableValues_Impl(); + static test.nullable.data.NullableValues create() { + return new test.nullable.data.impl.NullableValues_Impl(); } - /** Identifier for the {@link NullableValues} type in JSON format. */ + /** Identifier for the {@link test.nullable.data.NullableValues} type in JSON format. */ static final String NULLABLE_VALUES__TYPE = "NullableValues"; /** @see #getInt() */ @@ -65,7 +65,7 @@ static NullableValues create() { /** * @see #getInt() */ - NullableValues setInt(Integer value); + test.nullable.data.NullableValues setInt(Integer value); /** * Checks, whether {@link #getInt()} has a value. @@ -77,7 +77,7 @@ static NullableValues create() { /** * @see #getLong() */ - NullableValues setLong(Long value); + test.nullable.data.NullableValues setLong(Long value); /** * Checks, whether {@link #getLong()} has a value. @@ -89,7 +89,7 @@ static NullableValues create() { /** * @see #getBoolean() */ - NullableValues setBoolean(Boolean value); + test.nullable.data.NullableValues setBoolean(Boolean value); /** * Checks, whether {@link #getBoolean()} has a value. @@ -101,7 +101,7 @@ static NullableValues create() { /** * @see #getString() */ - NullableValues setString(String value); + test.nullable.data.NullableValues setString(String value); /** * Checks, whether {@link #getString()} has a value. @@ -113,12 +113,12 @@ static NullableValues create() { /** * @see #getIntList() */ - NullableValues setIntList(java.util.List value); + test.nullable.data.NullableValues setIntList(java.util.List value); /** * Adds a value to the {@link #getIntList()} list. */ - NullableValues addIntList(int value); + test.nullable.data.NullableValues addIntList(int value); /** * Removes a value from the {@link #getIntList()} list. @@ -135,12 +135,12 @@ static NullableValues create() { /** * @see #getStringList() */ - NullableValues setStringList(java.util.List value); + test.nullable.data.NullableValues setStringList(java.util.List value); /** * Adds a value to the {@link #getStringList()} list. */ - NullableValues addStringList(String value); + test.nullable.data.NullableValues addStringList(String value); /** * Removes a value from the {@link #getStringList()} list. @@ -157,12 +157,12 @@ static NullableValues create() { /** * @see #getStringIntMap() */ - NullableValues setStringIntMap(java.util.Map value); + test.nullable.data.NullableValues setStringIntMap(java.util.Map value); /** * Adds a key value pair to the {@link #getStringIntMap()} map. */ - NullableValues putStringIntMap(String key, int value); + test.nullable.data.NullableValues putStringIntMap(String key, int value); /** * Removes a key from the {@link #getStringIntMap()} map. @@ -174,12 +174,12 @@ static NullableValues create() { */ boolean hasStringIntMap(); - Decision getOptionalDecision(); + test.nullable.data.Decision getOptionalDecision(); /** * @see #getOptionalDecision() */ - NullableValues setOptionalDecision(Decision value); + test.nullable.data.NullableValues setOptionalDecision(test.nullable.data.Decision value); /** * Checks, whether {@link #getOptionalDecision()} has a value. @@ -187,16 +187,16 @@ static NullableValues create() { boolean hasOptionalDecision(); /** Reads a new instance from the given reader. */ - static NullableValues readNullableValues(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.nullable.data.NullableValues_Impl result = new test.nullable.data.NullableValues_Impl(); + static test.nullable.data.NullableValues readNullableValues(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nullable.data.impl.NullableValues_Impl result = new test.nullable.data.impl.NullableValues_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static NullableValues readNullableValues(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.nullable.data.NullableValues readNullableValues(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - NullableValues result = test.nullable.data.NullableValues_Impl.readNullableValues_Content(in); + test.nullable.data.NullableValues result = test.nullable.data.impl.NullableValues_Impl.readNullableValues_Content(in); in.endObject(); return result; } @@ -204,7 +204,7 @@ static NullableValues readNullableValues(de.haumacher.msgbuf.binary.DataReader i /** Creates a new {@link NullableValues} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static NullableValues readNullableValues(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.nullable.data.NullableValues_Impl.readNullableValues_XmlContent(in); + return test.nullable.data.impl.NullableValues_Impl.readNullableValues_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java similarity index 89% rename from de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java index 04c43bce..17a6c0f5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java @@ -1,6 +1,6 @@ -package test.nullable.data; +package test.nullable.data.impl; -class NullableValues_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements NullableValues { +public class NullableValues_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nullable.data.NullableValues { private Integer _int = null; @@ -16,14 +16,14 @@ class NullableValues_Impl extends de.haumacher.msgbuf.data.AbstractDataObject im private java.util.Map _stringIntMap = null; - private Decision _optionalDecision = null; + private test.nullable.data.Decision _optionalDecision = null; /** * Creates a {@link NullableValues_Impl} instance. * - * @see NullableValues#create() + * @see test.nullable.data.NullableValues#create() */ - protected NullableValues_Impl() { + public NullableValues_Impl() { super(); } @@ -33,7 +33,7 @@ public final Integer getInt() { } @Override - public NullableValues setInt(Integer value) { + public test.nullable.data.NullableValues setInt(Integer value) { internalSetInt(value); return this; } @@ -54,7 +54,7 @@ public final Long getLong() { } @Override - public NullableValues setLong(Long value) { + public test.nullable.data.NullableValues setLong(Long value) { internalSetLong(value); return this; } @@ -75,7 +75,7 @@ public final Boolean getBoolean() { } @Override - public NullableValues setBoolean(Boolean value) { + public test.nullable.data.NullableValues setBoolean(Boolean value) { internalSetBoolean(value); return this; } @@ -96,7 +96,7 @@ public final String getString() { } @Override - public NullableValues setString(String value) { + public test.nullable.data.NullableValues setString(String value) { internalSetString(value); return this; } @@ -117,7 +117,7 @@ public final java.util.List getIntList() { } @Override - public NullableValues setIntList(java.util.List value) { + public test.nullable.data.NullableValues setIntList(java.util.List value) { internalSetIntList(value); return this; } @@ -130,7 +130,7 @@ protected final void internalSetIntList(java.util.List value) } @Override - public NullableValues addIntList(int value) { + public test.nullable.data.NullableValues addIntList(int value) { internalAddIntList(value); return this; } @@ -158,7 +158,7 @@ public final java.util.List getStringList() { } @Override - public NullableValues setStringList(java.util.List value) { + public test.nullable.data.NullableValues setStringList(java.util.List value) { internalSetStringList(value); return this; } @@ -171,7 +171,7 @@ protected final void internalSetStringList(java.util.List valu } @Override - public NullableValues addStringList(String value) { + public test.nullable.data.NullableValues addStringList(String value) { internalAddStringList(value); return this; } @@ -199,7 +199,7 @@ public final java.util.Map getStringIntMap() { } @Override - public NullableValues setStringIntMap(java.util.Map value) { + public test.nullable.data.NullableValues setStringIntMap(java.util.Map value) { internalSetStringIntMap(value); return this; } @@ -212,7 +212,7 @@ protected final void internalSetStringIntMap(java.util.Map valu } @Override - public NullableValues putStringIntMap(String key, int value) { + public test.nullable.data.NullableValues putStringIntMap(String key, int value) { internalPutStringIntMap(key, value); return this; } @@ -238,18 +238,18 @@ public final boolean hasStringIntMap() { } @Override - public final Decision getOptionalDecision() { + public final test.nullable.data.Decision getOptionalDecision() { return _optionalDecision; } @Override - public NullableValues setOptionalDecision(Decision value) { + public test.nullable.data.NullableValues setOptionalDecision(test.nullable.data.Decision value) { internalSetOptionalDecision(value); return this; } /** Internal setter for {@link #getOptionalDecision()} without chain call utility. */ - protected final void internalSetOptionalDecision(Decision value) { + protected final void internalSetOptionalDecision(test.nullable.data.Decision value) { _optionalDecision = value; } @@ -290,7 +290,7 @@ public Object get(String field) { case STRING_LIST__PROP: return getStringList(); case STRING_INT_MAP__PROP: return getStringIntMap(); case OPTIONAL_DECISION__PROP: return getOptionalDecision(); - default: return NullableValues.super.get(field); + default: return test.nullable.data.NullableValues.super.get(field); } } @@ -304,7 +304,7 @@ public void set(String field, Object value) { case INT_LIST__PROP: internalSetIntList(de.haumacher.msgbuf.util.Conversions.asList(Integer.class, value)); break; case STRING_LIST__PROP: internalSetStringList(de.haumacher.msgbuf.util.Conversions.asList(String.class, value)); break; case STRING_INT_MAP__PROP: internalSetStringIntMap((java.util.Map) value); break; - case OPTIONAL_DECISION__PROP: internalSetOptionalDecision((Decision) value); break; + case OPTIONAL_DECISION__PROP: internalSetOptionalDecision((test.nullable.data.Decision) value); break; } } @@ -461,9 +461,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } } - /** Helper for creating an object of type {@link NullableValues} from a polymorphic composition. */ - public static NullableValues readNullableValues_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.nullable.data.NullableValues_Impl result = new NullableValues_Impl(); + /** Helper for creating an object of type {@link test.nullable.data.NullableValues} from a polymorphic composition. */ + public static test.nullable.data.NullableValues readNullableValues_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nullable.data.impl.NullableValues_Impl result = new NullableValues_Impl(); result.readContent(in); return result; } @@ -523,7 +523,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link NullableValues} type. */ + /** XML element name representing a {@link test.nullable.data.NullableValues} type. */ public static final String NULLABLE_VALUES__XML_ELEMENT = "nullable-values"; /** XML attribute or element name of a {@link #getInt} property. */ @@ -574,9 +574,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link NullableValues} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.nullable.data.NullableValues} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static NullableValues_Impl readNullableValues_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { NullableValues_Impl result = new NullableValues_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java b/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java index 5c19d22c..015ed7dd 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java @@ -3,32 +3,32 @@ public interface SampleMessage extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link SampleMessage} instance. + * Creates a {@link test.oneoffield.data.SampleMessage} instance. */ - static SampleMessage create() { - return new test.oneoffield.data.SampleMessage_Impl(); + static test.oneoffield.data.SampleMessage create() { + return new test.oneoffield.data.impl.SampleMessage_Impl(); } - /** Identifier for the {@link SampleMessage} type in JSON format. */ + /** Identifier for the {@link test.oneoffield.data.SampleMessage} type in JSON format. */ static final String SAMPLE_MESSAGE__TYPE = "SampleMessage"; @Override - public SampleMessage registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.oneoffield.data.SampleMessage registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public SampleMessage unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.oneoffield.data.SampleMessage unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static SampleMessage readSampleMessage(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.oneoffield.data.SampleMessage_Impl result = new test.oneoffield.data.SampleMessage_Impl(); + static test.oneoffield.data.SampleMessage readSampleMessage(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.oneoffield.data.impl.SampleMessage_Impl result = new test.oneoffield.data.impl.SampleMessage_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static SampleMessage readSampleMessage(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.oneoffield.data.SampleMessage readSampleMessage(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - SampleMessage result = test.oneoffield.data.SampleMessage_Impl.readSampleMessage_Content(in); + test.oneoffield.data.SampleMessage result = test.oneoffield.data.impl.SampleMessage_Impl.readSampleMessage_Content(in); in.endObject(); return result; } @@ -36,7 +36,7 @@ static SampleMessage readSampleMessage(de.haumacher.msgbuf.binary.DataReader in) /** Creates a new {@link SampleMessage} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SampleMessage readSampleMessage(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.oneoffield.data.SampleMessage_Impl.readSampleMessage_XmlContent(in); + return test.oneoffield.data.impl.SampleMessage_Impl.readSampleMessage_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/impl/SampleMessage_Impl.java similarity index 80% rename from de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/impl/SampleMessage_Impl.java index c632b29b..08e95ae8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/impl/SampleMessage_Impl.java @@ -1,20 +1,20 @@ -package test.oneoffield.data; +package test.oneoffield.data.impl; -class SampleMessage_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements SampleMessage { +public class SampleMessage_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.oneoffield.data.SampleMessage { /** * Creates a {@link SampleMessage_Impl} instance. * - * @see SampleMessage#create() + * @see test.oneoffield.data.SampleMessage#create() */ - protected SampleMessage_Impl() { + public SampleMessage_Impl() { super(); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public SampleMessage registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.oneoffield.data.SampleMessage registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -24,7 +24,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public SampleMessage unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.oneoffield.data.SampleMessage unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -61,9 +61,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav // No fields to write, hook for subclasses. } - /** Helper for creating an object of type {@link SampleMessage} from a polymorphic composition. */ - public static SampleMessage readSampleMessage_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.oneoffield.data.SampleMessage_Impl result = new SampleMessage_Impl(); + /** Helper for creating an object of type {@link test.oneoffield.data.SampleMessage} from a polymorphic composition. */ + public static test.oneoffield.data.SampleMessage readSampleMessage_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.oneoffield.data.impl.SampleMessage_Impl result = new SampleMessage_Impl(); result.readContent(in); return result; } @@ -83,7 +83,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link SampleMessage} type. */ + /** XML element name representing a {@link test.oneoffield.data.SampleMessage} type. */ public static final String SAMPLE_MESSAGE__XML_ELEMENT = "sample-message"; @Override @@ -103,9 +103,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link SampleMessage} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.oneoffield.data.SampleMessage} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SampleMessage_Impl readSampleMessage_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SampleMessage_Impl result = new SampleMessage_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/AtomicShape.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/AtomicShape.java index 4d0736f3..0206e583 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/AtomicShape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/AtomicShape.java @@ -6,15 +6,15 @@ public interface AtomicShape extends Shape { @Override - AtomicShape setXCoordinate(int value); + test.onlyxml.data.AtomicShape setXCoordinate(int value); @Override - AtomicShape setYCoordinate(int value); + test.onlyxml.data.AtomicShape setYCoordinate(int value); /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape readAtomicShape(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.onlyxml.data.AtomicShape_Impl.readAtomicShape_XmlContent(in); + return test.onlyxml.data.impl.AtomicShape_Impl.readAtomicShape_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Car.java index 6603a678..9abf1016 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Car.java @@ -6,21 +6,21 @@ public interface Car extends Shape { /** - * Creates a {@link Car} instance. + * Creates a {@link test.onlyxml.data.Car} instance. */ - static Car create() { - return new test.onlyxml.data.Car_Impl(); + static test.onlyxml.data.Car create() { + return new test.onlyxml.data.impl.Car_Impl(); } /** * The front wheel. */ - Circle getWheel1(); + test.onlyxml.data.Circle getWheel1(); /** * @see #getWheel1() */ - Car setWheel1(Circle value); + test.onlyxml.data.Car setWheel1(test.onlyxml.data.Circle value); /** * Checks, whether {@link #getWheel1()} has a value. @@ -30,12 +30,12 @@ static Car create() { /** * The back wheel. */ - Circle getWheel2(); + test.onlyxml.data.Circle getWheel2(); /** * @see #getWheel2() */ - Car setWheel2(Circle value); + test.onlyxml.data.Car setWheel2(test.onlyxml.data.Circle value); /** * Checks, whether {@link #getWheel2()} has a value. @@ -45,12 +45,12 @@ static Car create() { /** * The car body. */ - Rectangle getBody(); + test.onlyxml.data.Rectangle getBody(); /** * @see #getBody() */ - Car setBody(Rectangle value); + test.onlyxml.data.Car setBody(test.onlyxml.data.Rectangle value); /** * Checks, whether {@link #getBody()} has a value. @@ -58,15 +58,15 @@ static Car create() { boolean hasBody(); @Override - Car setXCoordinate(int value); + test.onlyxml.data.Car setXCoordinate(int value); @Override - Car setYCoordinate(int value); + test.onlyxml.data.Car setYCoordinate(int value); /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car readCar(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.onlyxml.data.Car_Impl.readCar_XmlContent(in); + return test.onlyxml.data.impl.Car_Impl.readCar_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Circle.java index 15a0661c..2b00706e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Circle.java @@ -6,10 +6,10 @@ public interface Circle extends AtomicShape { /** - * Creates a {@link Circle} instance. + * Creates a {@link test.onlyxml.data.Circle} instance. */ - static Circle create() { - return new test.onlyxml.data.Circle_Impl(); + static test.onlyxml.data.Circle create() { + return new test.onlyxml.data.impl.Circle_Impl(); } /** @@ -20,18 +20,18 @@ static Circle create() { /** * @see #getRadius() */ - Circle setRadius(int value); + test.onlyxml.data.Circle setRadius(int value); @Override - Circle setXCoordinate(int value); + test.onlyxml.data.Circle setXCoordinate(int value); @Override - Circle setYCoordinate(int value); + test.onlyxml.data.Circle setYCoordinate(int value); /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle readCircle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.onlyxml.data.Circle_Impl.readCircle_XmlContent(in); + return test.onlyxml.data.impl.Circle_Impl.readCircle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Group.java index a1ae3e9d..0513ca62 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Group.java @@ -6,10 +6,10 @@ public interface Group extends Shape { /** - * Creates a {@link Group} instance. + * Creates a {@link test.onlyxml.data.Group} instance. */ - static Group create() { - return new test.onlyxml.data.Group_Impl(); + static test.onlyxml.data.Group create() { + return new test.onlyxml.data.impl.Group_Impl(); } /** @@ -19,33 +19,33 @@ static Group create() { * The origins of these {@link Shape}s get a coordinate offset of ({@link #getXCoordinate()}, {@link #getYCoordinate()}). *

*/ - java.util.List getShapes(); + java.util.List getShapes(); /** * @see #getShapes() */ - Group setShapes(java.util.List value); + test.onlyxml.data.Group setShapes(java.util.List value); /** * Adds a value to the {@link #getShapes()} list. */ - Group addShape(Shape value); + test.onlyxml.data.Group addShape(test.onlyxml.data.Shape value); /** * Removes a value from the {@link #getShapes()} list. */ - void removeShape(Shape value); + void removeShape(test.onlyxml.data.Shape value); @Override - Group setXCoordinate(int value); + test.onlyxml.data.Group setXCoordinate(int value); @Override - Group setYCoordinate(int value); + test.onlyxml.data.Group setYCoordinate(int value); /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group readGroup(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.onlyxml.data.Group_Impl.readGroup_XmlContent(in); + return test.onlyxml.data.impl.Group_Impl.readGroup_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Optional.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Optional.java index 80d0eef3..df03b997 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Optional.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Optional.java @@ -6,10 +6,10 @@ public interface Optional extends Shape { /** - * Creates a {@link Optional} instance. + * Creates a {@link test.onlyxml.data.Optional} instance. */ - static Optional create() { - return new test.onlyxml.data.Optional_Impl(); + static test.onlyxml.data.Optional create() { + return new test.onlyxml.data.impl.Optional_Impl(); } /** @@ -20,17 +20,17 @@ static Optional create() { /** * @see #isHidden() */ - Optional setHidden(boolean value); + test.onlyxml.data.Optional setHidden(boolean value); /** * A {@link Shape} that can be dynamically hidden.. */ - Shape getShape(); + test.onlyxml.data.Shape getShape(); /** * @see #getShape() */ - Optional setShape(Shape value); + test.onlyxml.data.Optional setShape(test.onlyxml.data.Shape value); /** * Checks, whether {@link #getShape()} has a value. @@ -38,15 +38,15 @@ static Optional create() { boolean hasShape(); @Override - Optional setXCoordinate(int value); + test.onlyxml.data.Optional setXCoordinate(int value); @Override - Optional setYCoordinate(int value); + test.onlyxml.data.Optional setYCoordinate(int value); /** Creates a new {@link Optional} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Optional readOptional(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.onlyxml.data.Optional_Impl.readOptional_XmlContent(in); + return test.onlyxml.data.impl.Optional_Impl.readOptional_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Rectangle.java index 02ab5336..6ce7287c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Rectangle.java @@ -6,10 +6,10 @@ public interface Rectangle extends AtomicShape { /** - * Creates a {@link Rectangle} instance. + * Creates a {@link test.onlyxml.data.Rectangle} instance. */ - static Rectangle create() { - return new test.onlyxml.data.Rectangle_Impl(); + static test.onlyxml.data.Rectangle create() { + return new test.onlyxml.data.impl.Rectangle_Impl(); } /** @@ -26,7 +26,7 @@ static Rectangle create() { /** * @see #getWidth() */ - Rectangle setWidth(int value); + test.onlyxml.data.Rectangle setWidth(int value); /** * The width of this {@link Rectangle}. @@ -38,18 +38,18 @@ static Rectangle create() { /** * @see #getHeight() */ - Rectangle setHeight(int value); + test.onlyxml.data.Rectangle setHeight(int value); @Override - Rectangle setXCoordinate(int value); + test.onlyxml.data.Rectangle setXCoordinate(int value); @Override - Rectangle setYCoordinate(int value); + test.onlyxml.data.Rectangle setYCoordinate(int value); /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle readRectangle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.onlyxml.data.Rectangle_Impl.readRectangle_XmlContent(in); + return test.onlyxml.data.impl.Rectangle_Impl.readRectangle_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Shape.java index 89cfd044..759909d2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Shape.java @@ -13,7 +13,7 @@ public interface Shape extends de.haumacher.msgbuf.xml.XmlSerializable { /** * @see #getXCoordinate() */ - Shape setXCoordinate(int value); + test.onlyxml.data.Shape setXCoordinate(int value); /** * Y coordinate of the origin of the coordinate system of this {@link Shape}. @@ -23,12 +23,12 @@ public interface Shape extends de.haumacher.msgbuf.xml.XmlSerializable { /** * @see #getYCoordinate() */ - Shape setYCoordinate(int value); + test.onlyxml.data.Shape setYCoordinate(int value); /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape readShape(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.onlyxml.data.Shape_Impl.readShape_XmlContent(in); + return test.onlyxml.data.impl.Shape_Impl.readShape_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/SimpleType.java index 1b759789..510317f9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/SimpleType.java @@ -6,10 +6,10 @@ public interface SimpleType extends de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link SimpleType} instance. + * Creates a {@link test.onlyxml.data.SimpleType} instance. */ - static SimpleType create() { - return new test.onlyxml.data.SimpleType_Impl(); + static test.onlyxml.data.SimpleType create() { + return new test.onlyxml.data.impl.SimpleType_Impl(); } /** @@ -20,7 +20,7 @@ static SimpleType create() { /** * @see #getStr() */ - SimpleType setStr(String value); + test.onlyxml.data.SimpleType setStr(String value); /** * An int property @@ -30,12 +30,12 @@ static SimpleType create() { /** * @see #getX() */ - SimpleType setX(int value); + test.onlyxml.data.SimpleType setX(int value); /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SimpleType readSimpleType(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.onlyxml.data.SimpleType_Impl.readSimpleType_XmlContent(in); + return test.onlyxml.data.impl.SimpleType_Impl.readSimpleType_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/AtomicShape_Impl.java similarity index 67% rename from de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/AtomicShape_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/AtomicShape_Impl.java index 912178f4..3ad43460 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/AtomicShape_Impl.java @@ -1,30 +1,30 @@ -package test.novisitexceptions; +package test.onlyxml.data.impl; /** * A {@link Shape} that has no sub-shapes. */ -abstract class AtomicShape_Impl extends Shape_Impl implements AtomicShape { +public abstract class AtomicShape_Impl extends test.onlyxml.data.impl.Shape_Impl implements test.onlyxml.data.AtomicShape { /** * Creates a {@link AtomicShape_Impl} instance. */ - protected AtomicShape_Impl() { + public AtomicShape_Impl() { super(); } @Override - public AtomicShape setXCoordinate(int value) { + public test.onlyxml.data.AtomicShape setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public AtomicShape setYCoordinate(int value) { + public test.onlyxml.data.AtomicShape setYCoordinate(int value) { internalSetYCoordinate(value); return this; } - /** XML element name representing a {@link AtomicShape} type. */ + /** XML element name representing a {@link test.onlyxml.data.AtomicShape} type. */ public static final String ATOMIC_SHAPE__XML_ELEMENT = "atomic-shape"; /** Serializes all fields that are written as XML attributes. */ @@ -37,17 +37,18 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.onlyxml.data.AtomicShape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AtomicShape_Impl readAtomicShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { case Circle_Impl.CIRCLE__XML_ELEMENT: { - return test.novisitexceptions.Circle_Impl.readCircle_XmlContent(in); + return test.onlyxml.data.impl.Circle_Impl.readCircle_XmlContent(in); } case Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - return test.novisitexceptions.Rectangle_Impl.readRectangle_XmlContent(in); + return test.onlyxml.data.impl.Rectangle_Impl.readRectangle_XmlContent(in); } default: { @@ -75,9 +76,4 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } } - @Override - public final R visit(Shape.Visitor v, A arg) { - return visit((AtomicShape.Visitor) v, arg); - } - } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Car_Impl.java similarity index 67% rename from de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Car_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Car_Impl.java index 22242652..4ef67b4d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Car_Impl.java @@ -1,38 +1,38 @@ -package test.onlyxml.data; +package test.onlyxml.data.impl; /** * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. */ -class Car_Impl extends Shape_Impl implements Car { +public class Car_Impl extends test.onlyxml.data.impl.Shape_Impl implements test.onlyxml.data.Car { - private Circle _wheel1 = null; + private test.onlyxml.data.Circle _wheel1 = null; - private Circle _wheel2 = null; + private test.onlyxml.data.Circle _wheel2 = null; - private Rectangle _body = null; + private test.onlyxml.data.Rectangle _body = null; /** * Creates a {@link Car_Impl} instance. * - * @see Car#create() + * @see test.onlyxml.data.Car#create() */ - protected Car_Impl() { + public Car_Impl() { super(); } @Override - public final Circle getWheel1() { + public final test.onlyxml.data.Circle getWheel1() { return _wheel1; } @Override - public Car setWheel1(Circle value) { + public test.onlyxml.data.Car setWheel1(test.onlyxml.data.Circle value) { internalSetWheel1(value); return this; } /** Internal setter for {@link #getWheel1()} without chain call utility. */ - protected final void internalSetWheel1(Circle value) { + protected final void internalSetWheel1(test.onlyxml.data.Circle value) { _wheel1 = value; } @@ -42,18 +42,18 @@ public final boolean hasWheel1() { } @Override - public final Circle getWheel2() { + public final test.onlyxml.data.Circle getWheel2() { return _wheel2; } @Override - public Car setWheel2(Circle value) { + public test.onlyxml.data.Car setWheel2(test.onlyxml.data.Circle value) { internalSetWheel2(value); return this; } /** Internal setter for {@link #getWheel2()} without chain call utility. */ - protected final void internalSetWheel2(Circle value) { + protected final void internalSetWheel2(test.onlyxml.data.Circle value) { _wheel2 = value; } @@ -63,18 +63,18 @@ public final boolean hasWheel2() { } @Override - public final Rectangle getBody() { + public final test.onlyxml.data.Rectangle getBody() { return _body; } @Override - public Car setBody(Rectangle value) { + public test.onlyxml.data.Car setBody(test.onlyxml.data.Rectangle value) { internalSetBody(value); return this; } /** Internal setter for {@link #getBody()} without chain call utility. */ - protected final void internalSetBody(Rectangle value) { + protected final void internalSetBody(test.onlyxml.data.Rectangle value) { _body = value; } @@ -84,18 +84,18 @@ public final boolean hasBody() { } @Override - public Car setXCoordinate(int value) { + public test.onlyxml.data.Car setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Car setYCoordinate(int value) { + public test.onlyxml.data.Car setYCoordinate(int value) { internalSetYCoordinate(value); return this; } - /** XML element name representing a {@link Car} type. */ + /** XML element name representing a {@link test.onlyxml.data.Car} type. */ public static final String CAR__XML_ELEMENT = "car"; /** XML attribute or element name of a {@link #getWheel1} property. */ @@ -139,7 +139,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. } } - /** Creates a new {@link Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.onlyxml.data.Car} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Car_Impl readCar_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Car_Impl result = new Car_Impl(); result.readContentXml(in); @@ -159,15 +159,15 @@ protected void readFieldXmlAttribute(String name, String value) { protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { case WHEEL_1__XML_ATTR: { - setWheel1(test.onlyxml.data.Circle_Impl.readCircle_XmlContent(in)); + setWheel1(test.onlyxml.data.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case WHEEL_2__XML_ATTR: { - setWheel2(test.onlyxml.data.Circle_Impl.readCircle_XmlContent(in)); + setWheel2(test.onlyxml.data.impl.Circle_Impl.readCircle_XmlContent(in)); break; } case BODY__XML_ATTR: { - setBody(test.onlyxml.data.Rectangle_Impl.readRectangle_XmlContent(in)); + setBody(test.onlyxml.data.impl.Rectangle_Impl.readRectangle_XmlContent(in)); break; } default: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Circle_Impl.java similarity index 75% rename from de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Circle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Circle_Impl.java index 1b5a8c14..2a61633d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Circle_Impl.java @@ -1,18 +1,18 @@ -package test.onlyxml.data; +package test.onlyxml.data.impl; /** * A circle {@link Shape}. */ -class Circle_Impl extends AtomicShape_Impl implements Circle { +public class Circle_Impl extends test.onlyxml.data.impl.AtomicShape_Impl implements test.onlyxml.data.Circle { private int _radius = 0; /** * Creates a {@link Circle_Impl} instance. * - * @see Circle#create() + * @see test.onlyxml.data.Circle#create() */ - protected Circle_Impl() { + public Circle_Impl() { super(); } @@ -22,7 +22,7 @@ public final int getRadius() { } @Override - public Circle setRadius(int value) { + public test.onlyxml.data.Circle setRadius(int value) { internalSetRadius(value); return this; } @@ -33,18 +33,18 @@ protected final void internalSetRadius(int value) { } @Override - public Circle setXCoordinate(int value) { + public test.onlyxml.data.Circle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Circle setYCoordinate(int value) { + public test.onlyxml.data.Circle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } - /** XML element name representing a {@link Circle} type. */ + /** XML element name representing a {@link test.onlyxml.data.Circle} type. */ public static final String CIRCLE__XML_ELEMENT = "circle"; /** XML attribute or element name of a {@link #getRadius} property. */ @@ -66,9 +66,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.onlyxml.data.Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Circle_Impl result = new Circle_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Group_Impl.java similarity index 57% rename from de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Group_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Group_Impl.java index 75856d55..50a88fc4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Group_Impl.java @@ -1,68 +1,68 @@ -package test.onlyxml.data; +package test.onlyxml.data.impl; /** * A group of shapes. */ -class Group_Impl extends Shape_Impl implements Group { +public class Group_Impl extends test.onlyxml.data.impl.Shape_Impl implements test.onlyxml.data.Group { - private final java.util.List _shapes = new java.util.ArrayList<>(); + private final java.util.List _shapes = new java.util.ArrayList<>(); /** * Creates a {@link Group_Impl} instance. * - * @see Group#create() + * @see test.onlyxml.data.Group#create() */ - protected Group_Impl() { + public Group_Impl() { super(); } @Override - public final java.util.List getShapes() { + public final java.util.List getShapes() { return _shapes; } @Override - public Group setShapes(java.util.List value) { + public test.onlyxml.data.Group setShapes(java.util.List value) { internalSetShapes(value); return this; } /** Internal setter for {@link #getShapes()} without chain call utility. */ - protected final void internalSetShapes(java.util.List value) { + protected final void internalSetShapes(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); _shapes.clear(); _shapes.addAll(value); } @Override - public Group addShape(Shape value) { + public test.onlyxml.data.Group addShape(test.onlyxml.data.Shape value) { internalAddShape(value); return this; } - /** Implementation of {@link #addShape(Shape)} without chain call utility. */ - protected final void internalAddShape(Shape value) { + /** Implementation of {@link #addShape(test.onlyxml.data.Shape)} without chain call utility. */ + protected final void internalAddShape(test.onlyxml.data.Shape value) { _shapes.add(value); } @Override - public final void removeShape(Shape value) { + public final void removeShape(test.onlyxml.data.Shape value) { _shapes.remove(value); } @Override - public Group setXCoordinate(int value) { + public test.onlyxml.data.Group setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Group setYCoordinate(int value) { + public test.onlyxml.data.Group setYCoordinate(int value) { internalSetYCoordinate(value); return this; } - /** XML element name representing a {@link Group} type. */ + /** XML element name representing a {@link test.onlyxml.data.Group} type. */ public static final String GROUP__XML_ELEMENT = "group"; /** XML attribute or element name of a {@link #getShapes} property. */ @@ -90,7 +90,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. out.writeEndElement(); } - /** Creates a new {@link Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.onlyxml.data.Group} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Group_Impl readGroup_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Group_Impl result = new Group_Impl(); result.readContentXml(in); @@ -109,24 +109,24 @@ protected void readFieldXmlAttribute(String name, String value) { @Override protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { - case test.onlyxml.data.Circle_Impl.CIRCLE__XML_ELEMENT: { - addShape(test.onlyxml.data.Circle_Impl.readCircle_XmlContent(in)); + case test.onlyxml.data.impl.Circle_Impl.CIRCLE__XML_ELEMENT: { + addShape(test.onlyxml.data.impl.Circle_Impl.readCircle_XmlContent(in)); break; } - case test.onlyxml.data.Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - addShape(test.onlyxml.data.Rectangle_Impl.readRectangle_XmlContent(in)); + case test.onlyxml.data.impl.Rectangle_Impl.RECTANGLE__XML_ELEMENT: { + addShape(test.onlyxml.data.impl.Rectangle_Impl.readRectangle_XmlContent(in)); break; } - case test.onlyxml.data.Group_Impl.GROUP__XML_ELEMENT: { - addShape(test.onlyxml.data.Group_Impl.readGroup_XmlContent(in)); + case test.onlyxml.data.impl.Group_Impl.GROUP__XML_ELEMENT: { + addShape(test.onlyxml.data.impl.Group_Impl.readGroup_XmlContent(in)); break; } - case test.onlyxml.data.Optional_Impl.OPTIONAL__XML_ELEMENT: { - addShape(test.onlyxml.data.Optional_Impl.readOptional_XmlContent(in)); + case test.onlyxml.data.impl.Optional_Impl.OPTIONAL__XML_ELEMENT: { + addShape(test.onlyxml.data.impl.Optional_Impl.readOptional_XmlContent(in)); break; } - case test.onlyxml.data.Car_Impl.CAR__XML_ELEMENT: { - addShape(test.onlyxml.data.Car_Impl.readCar_XmlContent(in)); + case test.onlyxml.data.impl.Car_Impl.CAR__XML_ELEMENT: { + addShape(test.onlyxml.data.impl.Car_Impl.readCar_XmlContent(in)); break; } case SHAPES__XML_ATTR: { @@ -146,7 +146,7 @@ private void internalReadShapesListXml(javax.xml.stream.XMLStreamReader in) thro break; } - addShape(test.onlyxml.data.Shape_Impl.readShape_XmlContent(in)); + addShape(test.onlyxml.data.impl.Shape_Impl.readShape_XmlContent(in)); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Optional_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Optional_Impl.java similarity index 62% rename from de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Optional_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Optional_Impl.java index a49343c3..b99e5fb0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Optional_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Optional_Impl.java @@ -1,20 +1,20 @@ -package test.onlyxml.data; +package test.onlyxml.data.impl; /** * A shape that can be dynamically hidden. */ -class Optional_Impl extends Shape_Impl implements Optional { +public class Optional_Impl extends test.onlyxml.data.impl.Shape_Impl implements test.onlyxml.data.Optional { private boolean _hidden = false; - private Shape _shape = null; + private test.onlyxml.data.Shape _shape = null; /** * Creates a {@link Optional_Impl} instance. * - * @see Optional#create() + * @see test.onlyxml.data.Optional#create() */ - protected Optional_Impl() { + public Optional_Impl() { super(); } @@ -24,7 +24,7 @@ public final boolean isHidden() { } @Override - public Optional setHidden(boolean value) { + public test.onlyxml.data.Optional setHidden(boolean value) { internalSetHidden(value); return this; } @@ -35,18 +35,18 @@ protected final void internalSetHidden(boolean value) { } @Override - public final Shape getShape() { + public final test.onlyxml.data.Shape getShape() { return _shape; } @Override - public Optional setShape(Shape value) { + public test.onlyxml.data.Optional setShape(test.onlyxml.data.Shape value) { internalSetShape(value); return this; } /** Internal setter for {@link #getShape()} without chain call utility. */ - protected final void internalSetShape(Shape value) { + protected final void internalSetShape(test.onlyxml.data.Shape value) { _shape = value; } @@ -56,18 +56,18 @@ public final boolean hasShape() { } @Override - public Optional setXCoordinate(int value) { + public test.onlyxml.data.Optional setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Optional setYCoordinate(int value) { + public test.onlyxml.data.Optional setYCoordinate(int value) { internalSetYCoordinate(value); return this; } - /** XML element name representing a {@link Optional} type. */ + /** XML element name representing a {@link test.onlyxml.data.Optional} type. */ public static final String OPTIONAL__XML_ELEMENT = "optional"; /** XML attribute or element name of a {@link #isHidden} property. */ @@ -99,7 +99,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. } } - /** Creates a new {@link Optional} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.onlyxml.data.Optional} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Optional_Impl readOptional_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Optional_Impl result = new Optional_Impl(); result.readContentXml(in); @@ -126,29 +126,29 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l setHidden(Boolean.parseBoolean(in.getElementText())); break; } - case test.onlyxml.data.Circle_Impl.CIRCLE__XML_ELEMENT: { - setShape(test.onlyxml.data.Circle_Impl.readCircle_XmlContent(in)); + case test.onlyxml.data.impl.Circle_Impl.CIRCLE__XML_ELEMENT: { + setShape(test.onlyxml.data.impl.Circle_Impl.readCircle_XmlContent(in)); break; } - case test.onlyxml.data.Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - setShape(test.onlyxml.data.Rectangle_Impl.readRectangle_XmlContent(in)); + case test.onlyxml.data.impl.Rectangle_Impl.RECTANGLE__XML_ELEMENT: { + setShape(test.onlyxml.data.impl.Rectangle_Impl.readRectangle_XmlContent(in)); break; } - case test.onlyxml.data.Group_Impl.GROUP__XML_ELEMENT: { - setShape(test.onlyxml.data.Group_Impl.readGroup_XmlContent(in)); + case test.onlyxml.data.impl.Group_Impl.GROUP__XML_ELEMENT: { + setShape(test.onlyxml.data.impl.Group_Impl.readGroup_XmlContent(in)); break; } - case test.onlyxml.data.Optional_Impl.OPTIONAL__XML_ELEMENT: { - setShape(test.onlyxml.data.Optional_Impl.readOptional_XmlContent(in)); + case test.onlyxml.data.impl.Optional_Impl.OPTIONAL__XML_ELEMENT: { + setShape(test.onlyxml.data.impl.Optional_Impl.readOptional_XmlContent(in)); break; } - case test.onlyxml.data.Car_Impl.CAR__XML_ELEMENT: { - setShape(test.onlyxml.data.Car_Impl.readCar_XmlContent(in)); + case test.onlyxml.data.impl.Car_Impl.CAR__XML_ELEMENT: { + setShape(test.onlyxml.data.impl.Car_Impl.readCar_XmlContent(in)); break; } case SHAPE__XML_ATTR: { in.nextTag(); - setShape(test.onlyxml.data.Shape_Impl.readShape_XmlContent(in)); + setShape(test.onlyxml.data.impl.Shape_Impl.readShape_XmlContent(in)); internalSkipUntilMatchingEndElement(in); break; } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Rectangle_Impl.java similarity index 78% rename from de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Rectangle_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Rectangle_Impl.java index ebb8dde5..2a5c647c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Rectangle_Impl.java @@ -1,9 +1,9 @@ -package test.onlyxml.data; +package test.onlyxml.data.impl; /** * A rectangle. */ -class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { +public class Rectangle_Impl extends test.onlyxml.data.impl.AtomicShape_Impl implements test.onlyxml.data.Rectangle { private int _width = 0; @@ -12,9 +12,9 @@ class Rectangle_Impl extends AtomicShape_Impl implements Rectangle { /** * Creates a {@link Rectangle_Impl} instance. * - * @see Rectangle#create() + * @see test.onlyxml.data.Rectangle#create() */ - protected Rectangle_Impl() { + public Rectangle_Impl() { super(); } @@ -24,7 +24,7 @@ public final int getWidth() { } @Override - public Rectangle setWidth(int value) { + public test.onlyxml.data.Rectangle setWidth(int value) { internalSetWidth(value); return this; } @@ -40,7 +40,7 @@ public final int getHeight() { } @Override - public Rectangle setHeight(int value) { + public test.onlyxml.data.Rectangle setHeight(int value) { internalSetHeight(value); return this; } @@ -51,18 +51,18 @@ protected final void internalSetHeight(int value) { } @Override - public Rectangle setXCoordinate(int value) { + public test.onlyxml.data.Rectangle setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @Override - public Rectangle setYCoordinate(int value) { + public test.onlyxml.data.Rectangle setYCoordinate(int value) { internalSetYCoordinate(value); return this; } - /** XML element name representing a {@link Rectangle} type. */ + /** XML element name representing a {@link test.onlyxml.data.Rectangle} type. */ public static final String RECTANGLE__XML_ELEMENT = "rectangle"; /** XML attribute or element name of a {@link #getWidth} property. */ @@ -88,9 +88,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.onlyxml.data.Rectangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Rectangle_Impl readRectangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { Rectangle_Impl result = new Rectangle_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Shape_Impl.java similarity index 82% rename from de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Shape_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Shape_Impl.java index 324034fc..0308197f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Shape_Impl.java @@ -1,9 +1,9 @@ -package test.onlyxml.data; +package test.onlyxml.data.impl; /** * An abstract base class for all shapes */ -abstract class Shape_Impl implements Shape { +public abstract class Shape_Impl implements test.onlyxml.data.Shape { private int _xCoordinate = 0; @@ -12,7 +12,7 @@ abstract class Shape_Impl implements Shape { /** * Creates a {@link Shape_Impl} instance. */ - protected Shape_Impl() { + public Shape_Impl() { super(); } @@ -22,7 +22,7 @@ public final int getXCoordinate() { } @Override - public Shape setXCoordinate(int value) { + public test.onlyxml.data.Shape setXCoordinate(int value) { internalSetXCoordinate(value); return this; } @@ -38,7 +38,7 @@ public final int getYCoordinate() { } @Override - public Shape setYCoordinate(int value) { + public test.onlyxml.data.Shape setYCoordinate(int value) { internalSetYCoordinate(value); return this; } @@ -48,7 +48,7 @@ protected final void internalSetYCoordinate(int value) { _yCoordinate = value; } - /** XML element name representing a {@link Shape} type. */ + /** XML element name representing a {@link test.onlyxml.data.Shape} type. */ public static final String SHAPE__XML_ELEMENT = "shape"; /** XML attribute or element name of a {@link #getXCoordinate} property. */ @@ -71,29 +71,30 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.onlyxml.data.Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { case Circle_Impl.CIRCLE__XML_ELEMENT: { - return test.onlyxml.data.Circle_Impl.readCircle_XmlContent(in); + return test.onlyxml.data.impl.Circle_Impl.readCircle_XmlContent(in); } case Rectangle_Impl.RECTANGLE__XML_ELEMENT: { - return test.onlyxml.data.Rectangle_Impl.readRectangle_XmlContent(in); + return test.onlyxml.data.impl.Rectangle_Impl.readRectangle_XmlContent(in); } case Group_Impl.GROUP__XML_ELEMENT: { - return test.onlyxml.data.Group_Impl.readGroup_XmlContent(in); + return test.onlyxml.data.impl.Group_Impl.readGroup_XmlContent(in); } case Optional_Impl.OPTIONAL__XML_ELEMENT: { - return test.onlyxml.data.Optional_Impl.readOptional_XmlContent(in); + return test.onlyxml.data.impl.Optional_Impl.readOptional_XmlContent(in); } case Car_Impl.CAR__XML_ELEMENT: { - return test.onlyxml.data.Car_Impl.readCar_XmlContent(in); + return test.onlyxml.data.impl.Car_Impl.readCar_XmlContent(in); } default: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/SimpleType_Impl.java similarity index 86% rename from de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/SimpleType_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/SimpleType_Impl.java index 88d82c7a..68c042b1 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/SimpleType_Impl.java @@ -1,9 +1,9 @@ -package test.onlyxml.data; +package test.onlyxml.data.impl; /** * A concrete type without abstract super type. */ -class SimpleType_Impl implements SimpleType { +public class SimpleType_Impl implements test.onlyxml.data.SimpleType { private String _str = ""; @@ -12,9 +12,9 @@ class SimpleType_Impl implements SimpleType { /** * Creates a {@link SimpleType_Impl} instance. * - * @see SimpleType#create() + * @see test.onlyxml.data.SimpleType#create() */ - protected SimpleType_Impl() { + public SimpleType_Impl() { super(); } @@ -24,7 +24,7 @@ public final String getStr() { } @Override - public SimpleType setStr(String value) { + public test.onlyxml.data.SimpleType setStr(String value) { internalSetStr(value); return this; } @@ -40,7 +40,7 @@ public final int getX() { } @Override - public SimpleType setX(int value) { + public test.onlyxml.data.SimpleType setX(int value) { internalSetX(value); return this; } @@ -50,7 +50,7 @@ protected final void internalSetX(int value) { _x = value; } - /** XML element name representing a {@link SimpleType} type. */ + /** XML element name representing a {@link test.onlyxml.data.SimpleType} type. */ public static final String SIMPLE_TYPE__XML_ELEMENT = "simple-type"; /** XML attribute or element name of a {@link #getStr} property. */ @@ -78,9 +78,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.onlyxml.data.SimpleType} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SimpleType_Impl readSimpleType_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SimpleType_Impl result = new SimpleType_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java index 2919ee96..f66b85a6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java @@ -70,32 +70,32 @@ public static EnumAllowingAlias readEnumAllowingAlias(de.haumacher.msgbuf.binary } /** - * Creates a {@link MyMessage1} instance. + * Creates a {@link test.options.data.MyMessage1} instance. */ - static MyMessage1 create() { - return new test.options.data.MyMessage1_Impl(); + static test.options.data.MyMessage1 create() { + return new test.options.data.impl.MyMessage1_Impl(); } - /** Identifier for the {@link MyMessage1} type in JSON format. */ + /** Identifier for the {@link test.options.data.MyMessage1} type in JSON format. */ static final String MY_MESSAGE_1__TYPE = "MyMessage1"; @Override - public MyMessage1 registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.options.data.MyMessage1 registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public MyMessage1 unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.options.data.MyMessage1 unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static MyMessage1 readMyMessage1(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.options.data.MyMessage1_Impl result = new test.options.data.MyMessage1_Impl(); + static test.options.data.MyMessage1 readMyMessage1(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.options.data.impl.MyMessage1_Impl result = new test.options.data.impl.MyMessage1_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static MyMessage1 readMyMessage1(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.options.data.MyMessage1 readMyMessage1(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - MyMessage1 result = test.options.data.MyMessage1_Impl.readMyMessage1_Content(in); + test.options.data.MyMessage1 result = test.options.data.impl.MyMessage1_Impl.readMyMessage1_Content(in); in.endObject(); return result; } @@ -103,7 +103,7 @@ static MyMessage1 readMyMessage1(de.haumacher.msgbuf.binary.DataReader in) throw /** Creates a new {@link MyMessage1} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static MyMessage1 readMyMessage1(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.options.data.MyMessage1_Impl.readMyMessage1_XmlContent(in); + return test.options.data.impl.MyMessage1_Impl.readMyMessage1_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java index 8103f108..d44b1bda 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java @@ -66,32 +66,32 @@ public static EnumNotAllowingAlias readEnumNotAllowingAlias(de.haumacher.msgbuf. } /** - * Creates a {@link MyMessage2} instance. + * Creates a {@link test.options.data.MyMessage2} instance. */ - static MyMessage2 create() { - return new test.options.data.MyMessage2_Impl(); + static test.options.data.MyMessage2 create() { + return new test.options.data.impl.MyMessage2_Impl(); } - /** Identifier for the {@link MyMessage2} type in JSON format. */ + /** Identifier for the {@link test.options.data.MyMessage2} type in JSON format. */ static final String MY_MESSAGE_2__TYPE = "MyMessage2"; @Override - public MyMessage2 registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.options.data.MyMessage2 registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public MyMessage2 unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.options.data.MyMessage2 unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static MyMessage2 readMyMessage2(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.options.data.MyMessage2_Impl result = new test.options.data.MyMessage2_Impl(); + static test.options.data.MyMessage2 readMyMessage2(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.options.data.impl.MyMessage2_Impl result = new test.options.data.impl.MyMessage2_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static MyMessage2 readMyMessage2(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.options.data.MyMessage2 readMyMessage2(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - MyMessage2 result = test.options.data.MyMessage2_Impl.readMyMessage2_Content(in); + test.options.data.MyMessage2 result = test.options.data.impl.MyMessage2_Impl.readMyMessage2_Content(in); in.endObject(); return result; } @@ -99,7 +99,7 @@ static MyMessage2 readMyMessage2(de.haumacher.msgbuf.binary.DataReader in) throw /** Creates a new {@link MyMessage2} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static MyMessage2 readMyMessage2(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.options.data.MyMessage2_Impl.readMyMessage2_XmlContent(in); + return test.options.data.impl.MyMessage2_Impl.readMyMessage2_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/impl/MyMessage1_Impl.java similarity index 81% rename from de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/options/data/impl/MyMessage1_Impl.java index f5102941..289d7f21 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/impl/MyMessage1_Impl.java @@ -1,20 +1,20 @@ -package test.options.data; +package test.options.data.impl; -class MyMessage1_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements MyMessage1 { +public class MyMessage1_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.options.data.MyMessage1 { /** * Creates a {@link MyMessage1_Impl} instance. * - * @see MyMessage1#create() + * @see test.options.data.MyMessage1#create() */ - protected MyMessage1_Impl() { + public MyMessage1_Impl() { super(); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public MyMessage1 registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.options.data.MyMessage1 registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -24,7 +24,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public MyMessage1 unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.options.data.MyMessage1 unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -61,9 +61,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav // No fields to write, hook for subclasses. } - /** Helper for creating an object of type {@link MyMessage1} from a polymorphic composition. */ - public static MyMessage1 readMyMessage1_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.options.data.MyMessage1_Impl result = new MyMessage1_Impl(); + /** Helper for creating an object of type {@link test.options.data.MyMessage1} from a polymorphic composition. */ + public static test.options.data.MyMessage1 readMyMessage1_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.options.data.impl.MyMessage1_Impl result = new MyMessage1_Impl(); result.readContent(in); return result; } @@ -83,7 +83,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link MyMessage1} type. */ + /** XML element name representing a {@link test.options.data.MyMessage1} type. */ public static final String MY_MESSAGE_1__XML_ELEMENT = "my-message-1"; @Override @@ -103,9 +103,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link MyMessage1} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.options.data.MyMessage1} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static MyMessage1_Impl readMyMessage1_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { MyMessage1_Impl result = new MyMessage1_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/impl/MyMessage2_Impl.java similarity index 81% rename from de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/options/data/impl/MyMessage2_Impl.java index e8058b33..91220e12 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/impl/MyMessage2_Impl.java @@ -1,20 +1,20 @@ -package test.options.data; +package test.options.data.impl; -class MyMessage2_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements MyMessage2 { +public class MyMessage2_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.options.data.MyMessage2 { /** * Creates a {@link MyMessage2_Impl} instance. * - * @see MyMessage2#create() + * @see test.options.data.MyMessage2#create() */ - protected MyMessage2_Impl() { + public MyMessage2_Impl() { super(); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public MyMessage2 registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.options.data.MyMessage2 registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -24,7 +24,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public MyMessage2 unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.options.data.MyMessage2 unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -61,9 +61,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav // No fields to write, hook for subclasses. } - /** Helper for creating an object of type {@link MyMessage2} from a polymorphic composition. */ - public static MyMessage2 readMyMessage2_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.options.data.MyMessage2_Impl result = new MyMessage2_Impl(); + /** Helper for creating an object of type {@link test.options.data.MyMessage2} from a polymorphic composition. */ + public static test.options.data.MyMessage2 readMyMessage2_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.options.data.impl.MyMessage2_Impl result = new MyMessage2_Impl(); result.readContent(in); return result; } @@ -83,7 +83,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link MyMessage2} type. */ + /** XML element name representing a {@link test.options.data.MyMessage2} type. */ public static final String MY_MESSAGE_2__XML_ELEMENT = "my-message-2"; @Override @@ -103,9 +103,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link MyMessage2} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.options.data.MyMessage2} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static MyMessage2_Impl readMyMessage2_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { MyMessage2_Impl result = new MyMessage2_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java index 2eb53d37..0271b5e6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java @@ -3,13 +3,13 @@ public interface A extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link A} instance. + * Creates a {@link test.references.data.A} instance. */ - static A create() { - return new test.references.data.A_Impl(); + static test.references.data.A create() { + return new test.references.data.impl.A_Impl(); } - /** Identifier for the {@link A} type in JSON format. */ + /** Identifier for the {@link test.references.data.A} type in JSON format. */ static final String A__TYPE = "A"; /** @see #getName() */ @@ -65,116 +65,116 @@ static A create() { /** * @see #getName() */ - A setName(String value); + test.references.data.A setName(String value); - A getContents(); + test.references.data.A getContents(); /** * @see #getContents() */ - A setContents(A value); + test.references.data.A setContents(test.references.data.A value); /** * Checks, whether {@link #getContents()} has a value. */ boolean hasContents(); - java.util.List
getChildren(); + java.util.List getChildren(); /** * @see #getChildren() */ - A setChildren(java.util.List value); + test.references.data.A setChildren(java.util.List value); /** * Adds a value to the {@link #getChildren()} list. */ - A addChildren(A value); + test.references.data.A addChildren(test.references.data.A value); /** * Removes a value from the {@link #getChildren()} list. */ - void removeChildren(A value); + void removeChildren(test.references.data.A value); - java.util.List getBs(); + java.util.List getBs(); /** * @see #getBs() */ - A setBs(java.util.List value); + test.references.data.A setBs(java.util.List value); /** * Adds a value to the {@link #getBs()} list. */ - A addBs(B value); + test.references.data.A addBs(test.references.data.B value); /** * Removes a value from the {@link #getBs()} list. */ - void removeBs(B value); + void removeBs(test.references.data.B value); - B getB(); + test.references.data.B getB(); /** * @see #getB() */ - A setB(B value); + test.references.data.A setB(test.references.data.B value); /** * Checks, whether {@link #getB()} has a value. */ boolean hasB(); - A getOther(); + test.references.data.A getOther(); /** * @see #getOther() */ - A setOther(A value); + test.references.data.A setOther(test.references.data.A value); /** * Checks, whether {@link #getOther()} has a value. */ boolean hasOther(); - java.util.List getOthers(); + java.util.List getOthers(); /** * @see #getOthers() */ - A setOthers(java.util.List value); + test.references.data.A setOthers(java.util.List value); /** * Adds a value to the {@link #getOthers()} list. */ - A addOthers(A value); + test.references.data.A addOthers(test.references.data.A value); /** * Removes a value from the {@link #getOthers()} list. */ - void removeOthers(A value); + void removeOthers(test.references.data.A value); - java.util.List getInOther(); + java.util.List getInOther(); - java.util.List getInOthers(); + java.util.List getInOthers(); @Override - public A registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.references.data.A registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public A unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.references.data.A unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static A readA(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.references.data.A_Impl result = new test.references.data.A_Impl(); + static test.references.data.A readA(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.references.data.impl.A_Impl result = new test.references.data.impl.A_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static A readA(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.references.data.A readA(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - A result = test.references.data.A_Impl.readA_Content(in); + test.references.data.A result = test.references.data.impl.A_Impl.readA_Content(in); in.endObject(); return result; } @@ -182,7 +182,7 @@ static A readA(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOExcept /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static A readA(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.references.data.A_Impl.readA_XmlContent(in); + return test.references.data.impl.A_Impl.readA_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java index 85daad9f..6dbd6eaf 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java @@ -3,13 +3,13 @@ public interface B extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link B} instance. + * Creates a {@link test.references.data.B} instance. */ - static B create() { - return new test.references.data.B_Impl(); + static test.references.data.B create() { + return new test.references.data.impl.B_Impl(); } - /** Identifier for the {@link B} type in JSON format. */ + /** Identifier for the {@link test.references.data.B} type in JSON format. */ static final String B__TYPE = "B"; /** @see #getName() */ @@ -29,29 +29,29 @@ static B create() { /** * @see #getName() */ - B setName(String value); + test.references.data.B setName(String value); - java.util.List getInBs(); + java.util.List getInBs(); - java.util.List getInB(); + java.util.List getInB(); @Override - public B registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.references.data.B registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public B unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.references.data.B unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static B readB(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.references.data.B_Impl result = new test.references.data.B_Impl(); + static test.references.data.B readB(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.references.data.impl.B_Impl result = new test.references.data.impl.B_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static B readB(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.references.data.B readB(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - B result = test.references.data.B_Impl.readB_Content(in); + test.references.data.B result = test.references.data.impl.B_Impl.readB_Content(in); in.endObject(); return result; } @@ -59,7 +59,7 @@ static B readB(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOExcept /** Creates a new {@link B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static B readB(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.references.data.B_Impl.readB_XmlContent(in); + return test.references.data.impl.B_Impl.readB_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java similarity index 69% rename from de.haumacher.msgbuf.generator/src/test/java/test/references/data/A_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java index 5c51079b..3b711273 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java @@ -1,75 +1,75 @@ -package test.references.data; +package test.references.data.impl; -class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements A { +public class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.references.data.A { private String _name = ""; - private A _contents = null; + private test.references.data.A _contents = null; - private final java.util.List _children = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _children = new de.haumacher.msgbuf.util.ReferenceList() { @Override - protected void beforeAdd(int index, A element) { + protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(A_Impl.this, CHILDREN__PROP, index, element); } @Override - protected void afterRemove(int index, A element) { + protected void afterRemove(int index, test.references.data.A element) { _listener.afterRemove(A_Impl.this, CHILDREN__PROP, index, element); } }; - private final java.util.List _bs = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _bs = new de.haumacher.msgbuf.util.ReferenceList() { @Override - protected void beforeAdd(int index, B element) { + protected void beforeAdd(int index, test.references.data.B element) { _listener.beforeAdd(A_Impl.this, BS__PROP, index, element); - ((B_Impl) element).addInBs(A_Impl.this); + ((test.references.data.impl.B_Impl) element).addInBs(A_Impl.this); } @Override - protected void afterRemove(int index, B element) { - ((B_Impl) element).removeInBs(A_Impl.this); + protected void afterRemove(int index, test.references.data.B element) { + ((test.references.data.impl.B_Impl) element).removeInBs(A_Impl.this); _listener.afterRemove(A_Impl.this, BS__PROP, index, element); } }; - private B _b = null; + private test.references.data.B _b = null; - private A _other = null; + private test.references.data.A _other = null; - private final java.util.List _others = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _others = new de.haumacher.msgbuf.util.ReferenceList() { @Override - protected void beforeAdd(int index, A element) { + protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(A_Impl.this, OTHERS__PROP, index, element); - ((A_Impl) element).addInOthers(A_Impl.this); + ((test.references.data.impl.A_Impl) element).addInOthers(A_Impl.this); } @Override - protected void afterRemove(int index, A element) { - ((A_Impl) element).removeInOthers(A_Impl.this); + protected void afterRemove(int index, test.references.data.A element) { + ((test.references.data.impl.A_Impl) element).removeInOthers(A_Impl.this); _listener.afterRemove(A_Impl.this, OTHERS__PROP, index, element); } }; - private final java.util.List _inOther = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _inOther = new de.haumacher.msgbuf.util.ReferenceList() { @Override - protected void beforeAdd(int index, A element) { + protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(A_Impl.this, IN_OTHER__PROP, index, element); } @Override - protected void afterRemove(int index, A element) { + protected void afterRemove(int index, test.references.data.A element) { _listener.afterRemove(A_Impl.this, IN_OTHER__PROP, index, element); } }; - private final java.util.List _inOthers = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _inOthers = new de.haumacher.msgbuf.util.ReferenceList() { @Override - protected void beforeAdd(int index, A element) { + protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(A_Impl.this, IN_OTHERS__PROP, index, element); } @Override - protected void afterRemove(int index, A element) { + protected void afterRemove(int index, test.references.data.A element) { _listener.afterRemove(A_Impl.this, IN_OTHERS__PROP, index, element); } }; @@ -77,9 +77,9 @@ protected void afterRemove(int index, A element) { /** * Creates a {@link A_Impl} instance. * - * @see A#create() + * @see test.references.data.A#create() */ - protected A_Impl() { + public A_Impl() { super(); } @@ -89,7 +89,7 @@ public final String getName() { } @Override - public A setName(String value) { + public test.references.data.A setName(String value) { internalSetName(value); return this; } @@ -101,18 +101,18 @@ protected final void internalSetName(String value) { } @Override - public final A getContents() { + public final test.references.data.A getContents() { return _contents; } @Override - public A setContents(A value) { + public test.references.data.A setContents(test.references.data.A value) { internalSetContents(value); return this; } /** Internal setter for {@link #getContents()} without chain call utility. */ - protected final void internalSetContents(A value) { + protected final void internalSetContents(test.references.data.A value) { _listener.beforeSet(this, CONTENTS__PROP, value); _contents = value; } @@ -123,93 +123,93 @@ public final boolean hasContents() { } @Override - public final java.util.List getChildren() { + public final java.util.List getChildren() { return _children; } @Override - public A setChildren(java.util.List value) { + public test.references.data.A setChildren(java.util.List value) { internalSetChildren(value); return this; } /** Internal setter for {@link #getChildren()} without chain call utility. */ - protected final void internalSetChildren(java.util.List value) { + protected final void internalSetChildren(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'children' cannot be null."); _children.clear(); _children.addAll(value); } @Override - public A addChildren(A value) { + public test.references.data.A addChildren(test.references.data.A value) { internalAddChildren(value); return this; } - /** Implementation of {@link #addChildren(A)} without chain call utility. */ - protected final void internalAddChildren(A value) { + /** Implementation of {@link #addChildren(test.references.data.A)} without chain call utility. */ + protected final void internalAddChildren(test.references.data.A value) { _children.add(value); } @Override - public final void removeChildren(A value) { + public final void removeChildren(test.references.data.A value) { _children.remove(value); } @Override - public final java.util.List getBs() { + public final java.util.List getBs() { return _bs; } @Override - public A setBs(java.util.List value) { + public test.references.data.A setBs(java.util.List value) { internalSetBs(value); return this; } /** Internal setter for {@link #getBs()} without chain call utility. */ - protected final void internalSetBs(java.util.List value) { + protected final void internalSetBs(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'bs' cannot be null."); _bs.clear(); _bs.addAll(value); } @Override - public A addBs(B value) { + public test.references.data.A addBs(test.references.data.B value) { internalAddBs(value); return this; } - /** Implementation of {@link #addBs(B)} without chain call utility. */ - protected final void internalAddBs(B value) { + /** Implementation of {@link #addBs(test.references.data.B)} without chain call utility. */ + protected final void internalAddBs(test.references.data.B value) { _bs.add(value); } @Override - public final void removeBs(B value) { + public final void removeBs(test.references.data.B value) { _bs.remove(value); } @Override - public final B getB() { + public final test.references.data.B getB() { return _b; } @Override - public A setB(B value) { + public test.references.data.A setB(test.references.data.B value) { internalSetB(value); return this; } /** Internal setter for {@link #getB()} without chain call utility. */ - protected final void internalSetB(B value) { + protected final void internalSetB(test.references.data.B value) { _listener.beforeSet(this, B__PROP, value); if (_b != null) { - ((B_Impl) _b).removeInB(this); + ((test.references.data.impl.B_Impl) _b).removeInB(this); } _b = value; if (value != null) { - ((B_Impl) value).addInB(this); + ((test.references.data.impl.B_Impl) value).addInB(this); } } @@ -219,25 +219,25 @@ public final boolean hasB() { } @Override - public final A getOther() { + public final test.references.data.A getOther() { return _other; } @Override - public A setOther(A value) { + public test.references.data.A setOther(test.references.data.A value) { internalSetOther(value); return this; } /** Internal setter for {@link #getOther()} without chain call utility. */ - protected final void internalSetOther(A value) { + protected final void internalSetOther(test.references.data.A value) { _listener.beforeSet(this, OTHER__PROP, value); if (_other != null) { - ((A_Impl) _other).removeInOther(this); + ((test.references.data.impl.A_Impl) _other).removeInOther(this); } _other = value; if (value != null) { - ((A_Impl) value).addInOther(this); + ((test.references.data.impl.A_Impl) value).addInOther(this); } } @@ -247,105 +247,105 @@ public final boolean hasOther() { } @Override - public final java.util.List getOthers() { + public final java.util.List getOthers() { return _others; } @Override - public A setOthers(java.util.List value) { + public test.references.data.A setOthers(java.util.List value) { internalSetOthers(value); return this; } /** Internal setter for {@link #getOthers()} without chain call utility. */ - protected final void internalSetOthers(java.util.List value) { + protected final void internalSetOthers(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'others' cannot be null."); _others.clear(); _others.addAll(value); } @Override - public A addOthers(A value) { + public test.references.data.A addOthers(test.references.data.A value) { internalAddOthers(value); return this; } - /** Implementation of {@link #addOthers(A)} without chain call utility. */ - protected final void internalAddOthers(A value) { + /** Implementation of {@link #addOthers(test.references.data.A)} without chain call utility. */ + protected final void internalAddOthers(test.references.data.A value) { _others.add(value); } @Override - public final void removeOthers(A value) { + public final void removeOthers(test.references.data.A value) { _others.remove(value); } @Override - public final java.util.List getInOther() { + public final java.util.List getInOther() { return _inOther; } - A setInOther(java.util.List value) { + test.references.data.A setInOther(java.util.List value) { internalSetInOther(value); return this; } /** Internal setter for {@link #getInOther()} without chain call utility. */ - protected final void internalSetInOther(java.util.List value) { + protected final void internalSetInOther(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'inOther' cannot be null."); _inOther.clear(); _inOther.addAll(value); } - A addInOther(A value) { + test.references.data.A addInOther(test.references.data.A value) { internalAddInOther(value); return this; } - /** Implementation of {@link #addInOther(A)} without chain call utility. */ - protected final void internalAddInOther(A value) { + /** Implementation of {@link #addInOther(test.references.data.A)} without chain call utility. */ + protected final void internalAddInOther(test.references.data.A value) { _inOther.add(value); } - final void removeInOther(A value) { + final void removeInOther(test.references.data.A value) { _inOther.remove(value); } @Override - public final java.util.List getInOthers() { + public final java.util.List getInOthers() { return _inOthers; } - A setInOthers(java.util.List value) { + test.references.data.A setInOthers(java.util.List value) { internalSetInOthers(value); return this; } /** Internal setter for {@link #getInOthers()} without chain call utility. */ - protected final void internalSetInOthers(java.util.List value) { + protected final void internalSetInOthers(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'inOthers' cannot be null."); _inOthers.clear(); _inOthers.addAll(value); } - A addInOthers(A value) { + test.references.data.A addInOthers(test.references.data.A value) { internalAddInOthers(value); return this; } - /** Implementation of {@link #addInOthers(A)} without chain call utility. */ - protected final void internalAddInOthers(A value) { + /** Implementation of {@link #addInOthers(test.references.data.A)} without chain call utility. */ + protected final void internalAddInOthers(test.references.data.A value) { _inOthers.add(value); } - final void removeInOthers(A value) { + final void removeInOthers(test.references.data.A value) { _inOthers.remove(value); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public A registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.references.data.A registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -355,7 +355,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public A unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.references.data.A unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -398,7 +398,7 @@ public Object get(String field) { case OTHERS__PROP: return getOthers(); case IN_OTHER__PROP: return getInOther(); case IN_OTHERS__PROP: return getInOthers(); - default: return A.super.get(field); + default: return test.references.data.A.super.get(field); } } @@ -406,12 +406,12 @@ public Object get(String field) { public void set(String field, Object value) { switch (field) { case NAME__PROP: internalSetName((String) value); break; - case CONTENTS__PROP: internalSetContents((A) value); break; - case CHILDREN__PROP: internalSetChildren(de.haumacher.msgbuf.util.Conversions.asList(A.class, value)); break; - case BS__PROP: internalSetBs(de.haumacher.msgbuf.util.Conversions.asList(B.class, value)); break; - case B__PROP: internalSetB((B) value); break; - case OTHER__PROP: internalSetOther((A) value); break; - case OTHERS__PROP: internalSetOthers(de.haumacher.msgbuf.util.Conversions.asList(A.class, value)); break; + case CONTENTS__PROP: internalSetContents((test.references.data.A) value); break; + case CHILDREN__PROP: internalSetChildren(de.haumacher.msgbuf.util.Conversions.asList(test.references.data.A.class, value)); break; + case BS__PROP: internalSetBs(de.haumacher.msgbuf.util.Conversions.asList(test.references.data.B.class, value)); break; + case B__PROP: internalSetB((test.references.data.B) value); break; + case OTHER__PROP: internalSetOther((test.references.data.A) value); break; + case OTHERS__PROP: internalSetOthers(de.haumacher.msgbuf.util.Conversions.asList(test.references.data.A.class, value)); break; } } @@ -431,13 +431,13 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. } out.name(CHILDREN__PROP); out.beginArray(); - for (A x : getChildren()) { + for (test.references.data.A x : getChildren()) { x.writeTo(out); } out.endArray(); out.name(BS__PROP); out.beginArray(); - for (B x : getBs()) { + for (test.references.data.B x : getBs()) { x.writeTo(out); } out.endArray(); @@ -451,7 +451,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. } out.name(OTHERS__PROP); out.beginArray(); - for (A x : getOthers()) { + for (test.references.data.A x : getOthers()) { x.writeTo(out); } out.endArray(); @@ -515,18 +515,18 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } out.name(CHILDREN__ID); { - java.util.List values = getChildren(); + java.util.List values = getChildren(); out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); - for (A x : values) { + for (test.references.data.A x : values) { x.writeTo(out); } out.endArray(); } out.name(BS__ID); { - java.util.List values = getBs(); + java.util.List values = getBs(); out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); - for (B x : values) { + for (test.references.data.B x : values) { x.writeTo(out); } out.endArray(); @@ -541,18 +541,18 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } out.name(OTHERS__ID); { - java.util.List values = getOthers(); + java.util.List values = getOthers(); out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); - for (A x : values) { + for (test.references.data.A x : values) { x.writeTo(out); } out.endArray(); } } - /** Helper for creating an object of type {@link A} from a polymorphic composition. */ - public static A readA_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.references.data.A_Impl result = new A_Impl(); + /** Helper for creating an object of type {@link test.references.data.A} from a polymorphic composition. */ + public static test.references.data.A readA_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.references.data.impl.A_Impl result = new A_Impl(); result.readContent(in); return result; } @@ -600,7 +600,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link A} type. */ + /** XML element name representing a {@link test.references.data.A} type. */ public static final String A__XML_ELEMENT = "a"; /** XML attribute or element name of a {@link #getName} property. */ @@ -690,7 +690,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. out.writeEndElement(); } - /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.references.data.A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static A_Impl readA_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { A_Impl result = new A_Impl(); result.readContentXml(in); @@ -738,7 +738,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l break; } case CONTENTS__XML_ATTR: { - setContents(test.references.data.A_Impl.readA_XmlContent(in)); + setContents(test.references.data.impl.A_Impl.readA_XmlContent(in)); break; } case CHILDREN__XML_ATTR: { @@ -750,11 +750,11 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l break; } case B__XML_ATTR: { - setB(test.references.data.B_Impl.readB_XmlContent(in)); + setB(test.references.data.impl.B_Impl.readB_XmlContent(in)); break; } case OTHER__XML_ATTR: { - setOther(test.references.data.A_Impl.readA_XmlContent(in)); + setOther(test.references.data.impl.A_Impl.readA_XmlContent(in)); break; } case OTHERS__XML_ATTR: { @@ -792,7 +792,7 @@ private void internalReadChildrenListXml(javax.xml.stream.XMLStreamReader in) th break; } - addChildren(test.references.data.A_Impl.readA_XmlContent(in)); + addChildren(test.references.data.impl.A_Impl.readA_XmlContent(in)); } } @@ -803,7 +803,7 @@ private void internalReadBsListXml(javax.xml.stream.XMLStreamReader in) throws j break; } - addBs(test.references.data.B_Impl.readB_XmlContent(in)); + addBs(test.references.data.impl.B_Impl.readB_XmlContent(in)); } } @@ -814,7 +814,7 @@ private void internalReadOthersListXml(javax.xml.stream.XMLStreamReader in) thro break; } - addOthers(test.references.data.A_Impl.readA_XmlContent(in)); + addOthers(test.references.data.impl.A_Impl.readA_XmlContent(in)); } } @@ -825,7 +825,7 @@ private void internalReadInOtherListXml(javax.xml.stream.XMLStreamReader in) thr break; } - addInOther(test.references.data.A_Impl.readA_XmlContent(in)); + addInOther(test.references.data.impl.A_Impl.readA_XmlContent(in)); } } @@ -836,7 +836,7 @@ private void internalReadInOthersListXml(javax.xml.stream.XMLStreamReader in) th break; } - addInOthers(test.references.data.A_Impl.readA_XmlContent(in)); + addInOthers(test.references.data.impl.A_Impl.readA_XmlContent(in)); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java similarity index 75% rename from de.haumacher.msgbuf.generator/src/test/java/test/references/data/B_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java index 3340d3b1..b31e5a1e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java @@ -1,29 +1,29 @@ -package test.references.data; +package test.references.data.impl; -class B_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements B { +public class B_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.references.data.B { private String _name = ""; - private final java.util.List _inBs = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _inBs = new de.haumacher.msgbuf.util.ReferenceList() { @Override - protected void beforeAdd(int index, A element) { + protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(B_Impl.this, IN_BS__PROP, index, element); } @Override - protected void afterRemove(int index, A element) { + protected void afterRemove(int index, test.references.data.A element) { _listener.afterRemove(B_Impl.this, IN_BS__PROP, index, element); } }; - private final java.util.List _inB = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _inB = new de.haumacher.msgbuf.util.ReferenceList() { @Override - protected void beforeAdd(int index, A element) { + protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(B_Impl.this, IN_B__PROP, index, element); } @Override - protected void afterRemove(int index, A element) { + protected void afterRemove(int index, test.references.data.A element) { _listener.afterRemove(B_Impl.this, IN_B__PROP, index, element); } }; @@ -31,9 +31,9 @@ protected void afterRemove(int index, A element) { /** * Creates a {@link B_Impl} instance. * - * @see B#create() + * @see test.references.data.B#create() */ - protected B_Impl() { + public B_Impl() { super(); } @@ -43,7 +43,7 @@ public final String getName() { } @Override - public B setName(String value) { + public test.references.data.B setName(String value) { internalSetName(value); return this; } @@ -55,71 +55,71 @@ protected final void internalSetName(String value) { } @Override - public final java.util.List getInBs() { + public final java.util.List getInBs() { return _inBs; } - B setInBs(java.util.List value) { + test.references.data.B setInBs(java.util.List value) { internalSetInBs(value); return this; } /** Internal setter for {@link #getInBs()} without chain call utility. */ - protected final void internalSetInBs(java.util.List value) { + protected final void internalSetInBs(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'inBs' cannot be null."); _inBs.clear(); _inBs.addAll(value); } - B addInBs(A value) { + test.references.data.B addInBs(test.references.data.A value) { internalAddInBs(value); return this; } - /** Implementation of {@link #addInBs(A)} without chain call utility. */ - protected final void internalAddInBs(A value) { + /** Implementation of {@link #addInBs(test.references.data.A)} without chain call utility. */ + protected final void internalAddInBs(test.references.data.A value) { _inBs.add(value); } - final void removeInBs(A value) { + final void removeInBs(test.references.data.A value) { _inBs.remove(value); } @Override - public final java.util.List getInB() { + public final java.util.List getInB() { return _inB; } - B setInB(java.util.List value) { + test.references.data.B setInB(java.util.List value) { internalSetInB(value); return this; } /** Internal setter for {@link #getInB()} without chain call utility. */ - protected final void internalSetInB(java.util.List value) { + protected final void internalSetInB(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'inB' cannot be null."); _inB.clear(); _inB.addAll(value); } - B addInB(A value) { + test.references.data.B addInB(test.references.data.A value) { internalAddInB(value); return this; } - /** Implementation of {@link #addInB(A)} without chain call utility. */ - protected final void internalAddInB(A value) { + /** Implementation of {@link #addInB(test.references.data.A)} without chain call utility. */ + protected final void internalAddInB(test.references.data.A value) { _inB.add(value); } - final void removeInB(A value) { + final void removeInB(test.references.data.A value) { _inB.remove(value); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public B registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.references.data.B registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -129,7 +129,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public B unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.references.data.B unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -160,7 +160,7 @@ public Object get(String field) { case NAME__PROP: return getName(); case IN_BS__PROP: return getInBs(); case IN_B__PROP: return getInB(); - default: return B.super.get(field); + default: return test.references.data.B.super.get(field); } } @@ -210,9 +210,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getName()); } - /** Helper for creating an object of type {@link B} from a polymorphic composition. */ - public static B readB_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.references.data.B_Impl result = new B_Impl(); + /** Helper for creating an object of type {@link test.references.data.B} from a polymorphic composition. */ + public static test.references.data.B readB_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.references.data.impl.B_Impl result = new B_Impl(); result.readContent(in); return result; } @@ -233,7 +233,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link B} type. */ + /** XML element name representing a {@link test.references.data.B} type. */ public static final String B__XML_ELEMENT = "b"; /** XML attribute or element name of a {@link #getName} property. */ @@ -275,7 +275,7 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. out.writeEndElement(); } - /** Creates a new {@link B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.references.data.B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static B_Impl readB_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { B_Impl result = new B_Impl(); result.readContentXml(in); @@ -353,7 +353,7 @@ private void internalReadInBsListXml(javax.xml.stream.XMLStreamReader in) throws break; } - addInBs(test.references.data.A_Impl.readA_XmlContent(in)); + addInBs(test.references.data.impl.A_Impl.readA_XmlContent(in)); } } @@ -364,7 +364,7 @@ private void internalReadInBListXml(javax.xml.stream.XMLStreamReader in) throws break; } - addInB(test.references.data.A_Impl.readA_XmlContent(in)); + addInB(test.references.data.impl.A_Impl.readA_XmlContent(in)); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java index 75be9fdd..3bfa35c2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java @@ -3,13 +3,13 @@ public interface SearchRequest extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { /** - * Creates a {@link SearchRequest} instance. + * Creates a {@link test.types.data.SearchRequest} instance. */ - static SearchRequest create() { - return new test.types.data.SearchRequest_Impl(); + static test.types.data.SearchRequest create() { + return new test.types.data.impl.SearchRequest_Impl(); } - /** Identifier for the {@link SearchRequest} type in JSON format. */ + /** Identifier for the {@link test.types.data.SearchRequest} type in JSON format. */ static final String SEARCH_REQUEST__TYPE = "SearchRequest"; /** @see #getQuery() */ @@ -35,39 +35,39 @@ static SearchRequest create() { /** * @see #getQuery() */ - SearchRequest setQuery(String value); + test.types.data.SearchRequest setQuery(String value); int getPageNumber(); /** * @see #getPageNumber() */ - SearchRequest setPageNumber(int value); + test.types.data.SearchRequest setPageNumber(int value); int getResultPerPage(); /** * @see #getResultPerPage() */ - SearchRequest setResultPerPage(int value); + test.types.data.SearchRequest setResultPerPage(int value); @Override - public SearchRequest registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.types.data.SearchRequest registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public SearchRequest unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.types.data.SearchRequest unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static SearchRequest readSearchRequest(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.types.data.SearchRequest_Impl result = new test.types.data.SearchRequest_Impl(); + static test.types.data.SearchRequest readSearchRequest(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.types.data.impl.SearchRequest_Impl result = new test.types.data.impl.SearchRequest_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static SearchRequest readSearchRequest(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.types.data.SearchRequest readSearchRequest(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - SearchRequest result = test.types.data.SearchRequest_Impl.readSearchRequest_Content(in); + test.types.data.SearchRequest result = test.types.data.impl.SearchRequest_Impl.readSearchRequest_Content(in); in.endObject(); return result; } @@ -75,7 +75,7 @@ static SearchRequest readSearchRequest(de.haumacher.msgbuf.binary.DataReader in) /** Creates a new {@link SearchRequest} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SearchRequest readSearchRequest(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.types.data.SearchRequest_Impl.readSearchRequest_XmlContent(in); + return test.types.data.impl.SearchRequest_Impl.readSearchRequest_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java similarity index 86% rename from de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java index f457bf40..5c0a80b7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java @@ -1,10 +1,6 @@ -package test.comments.data; +package test.types.data.impl; -/** - * SearchRequest represents a search query, with {@link #getPageNumber() pagination options} to - * indicate which results to include in the response. - */ -class SearchRequest_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements SearchRequest { +public class SearchRequest_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.types.data.SearchRequest { private String _query = ""; @@ -15,9 +11,9 @@ class SearchRequest_Impl extends de.haumacher.msgbuf.data.AbstractDataObject imp /** * Creates a {@link SearchRequest_Impl} instance. * - * @see SearchRequest#create() + * @see test.types.data.SearchRequest#create() */ - protected SearchRequest_Impl() { + public SearchRequest_Impl() { super(); } @@ -27,7 +23,7 @@ public final String getQuery() { } @Override - public SearchRequest setQuery(String value) { + public test.types.data.SearchRequest setQuery(String value) { internalSetQuery(value); return this; } @@ -44,7 +40,7 @@ public final int getPageNumber() { } @Override - public SearchRequest setPageNumber(int value) { + public test.types.data.SearchRequest setPageNumber(int value) { internalSetPageNumber(value); return this; } @@ -61,7 +57,7 @@ public final int getResultPerPage() { } @Override - public SearchRequest setResultPerPage(int value) { + public test.types.data.SearchRequest setResultPerPage(int value) { internalSetResultPerPage(value); return this; } @@ -75,7 +71,7 @@ protected final void internalSetResultPerPage(int value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public SearchRequest registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.types.data.SearchRequest registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -85,7 +81,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public SearchRequest unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.types.data.SearchRequest unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -116,7 +112,7 @@ public Object get(String field) { case QUERY__PROP: return getQuery(); case PAGE_NUMBER__PROP: return getPageNumber(); case RESULT_PER_PAGE__PROP: return getResultPerPage(); - default: return SearchRequest.super.get(field); + default: return test.types.data.SearchRequest.super.get(field); } } @@ -178,9 +174,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getResultPerPage()); } - /** Helper for creating an object of type {@link SearchRequest} from a polymorphic composition. */ - public static SearchRequest readSearchRequest_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.comments.data.SearchRequest_Impl result = new SearchRequest_Impl(); + /** Helper for creating an object of type {@link test.types.data.SearchRequest} from a polymorphic composition. */ + public static test.types.data.SearchRequest readSearchRequest_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.types.data.impl.SearchRequest_Impl result = new SearchRequest_Impl(); result.readContent(in); return result; } @@ -203,7 +199,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link SearchRequest} type. */ + /** XML element name representing a {@link test.types.data.SearchRequest} type. */ public static final String SEARCH_REQUEST__XML_ELEMENT = "search-request"; /** XML attribute or element name of a {@link #getQuery} property. */ @@ -235,9 +231,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link SearchRequest} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.types.data.SearchRequest} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SearchRequest_Impl readSearchRequest_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SearchRequest_Impl result = new SearchRequest_Impl(); result.readContentXml(in); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java index 1cb883d2..3eb49c32 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java @@ -3,19 +3,19 @@ public interface AnnotatedMessage extends BaseMsg { /** - * Creates a {@link AnnotatedMessage} instance. + * Creates a {@link test.underscorename.AnnotatedMessage} instance. */ - static AnnotatedMessage create() { - return new test.underscorename.AnnotatedMessage_Impl(); + static test.underscorename.AnnotatedMessage create() { + return new test.underscorename.impl.AnnotatedMessage_Impl(); } - /** Identifier for the {@link AnnotatedMessage} type in JSON format. */ + /** Identifier for the {@link test.underscorename.AnnotatedMessage} type in JSON format. */ static final String ANNOTATED_MESSAGE__TYPE = "m1"; /** @see #getAnnotatedField() */ static final String ANNOTATED_FIELD__PROP = "f1"; - /** Identifier for the {@link AnnotatedMessage} type in binary format. */ + /** Identifier for the {@link test.underscorename.AnnotatedMessage} type in binary format. */ static final int ANNOTATED_MESSAGE__TYPE_ID = 2; /** Identifier for the property {@link #getAnnotatedField()} in binary format. */ @@ -26,19 +26,19 @@ static AnnotatedMessage create() { /** * @see #getAnnotatedField() */ - AnnotatedMessage setAnnotatedField(String value); + test.underscorename.AnnotatedMessage setAnnotatedField(String value); /** Reads a new instance from the given reader. */ - static AnnotatedMessage readannotated_message(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.underscorename.AnnotatedMessage_Impl result = new test.underscorename.AnnotatedMessage_Impl(); + static test.underscorename.AnnotatedMessage readannotated_message(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.underscorename.impl.AnnotatedMessage_Impl result = new test.underscorename.impl.AnnotatedMessage_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static AnnotatedMessage readannotated_message(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.underscorename.AnnotatedMessage readannotated_message(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - AnnotatedMessage result = test.underscorename.AnnotatedMessage_Impl.readannotated_message_Content(in); + test.underscorename.AnnotatedMessage result = test.underscorename.impl.AnnotatedMessage_Impl.readannotated_message_Content(in); in.endObject(); return result; } @@ -46,7 +46,7 @@ static AnnotatedMessage readannotated_message(de.haumacher.msgbuf.binary.DataRea /** Creates a new {@link AnnotatedMessage} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AnnotatedMessage readAnnotated_message(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.underscorename.AnnotatedMessage_Impl.readAnnotated_message_XmlContent(in); + return test.underscorename.impl.AnnotatedMessage_Impl.readAnnotated_message_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/BaseMsg.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/BaseMsg.java index 017851b8..0e7b9417 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/BaseMsg.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/BaseMsg.java @@ -2,26 +2,26 @@ public interface BaseMsg extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { - /** Type codes for the {@link BaseMsg} hierarchy. */ + /** Type codes for the {@link test.underscorename.BaseMsg} hierarchy. */ public enum TypeKind { - /** Type literal for {@link SomeName}. */ + /** Type literal for {@link test.underscorename.SomeName}. */ SOME_NAME, - /** Type literal for {@link AnnotatedMessage}. */ + /** Type literal for {@link test.underscorename.AnnotatedMessage}. */ ANNOTATED_MESSAGE, ; } - /** Visitor interface for the {@link BaseMsg} hierarchy.*/ + /** Visitor interface for the {@link test.underscorename.BaseMsg} hierarchy.*/ public interface Visitor { - /** Visit case for {@link SomeName}.*/ - R visit(SomeName self, A arg) throws E; + /** Visit case for {@link test.underscorename.SomeName}.*/ + R visit(test.underscorename.SomeName self, A arg) throws E; - /** Visit case for {@link AnnotatedMessage}.*/ - R visit(AnnotatedMessage self, A arg) throws E; + /** Visit case for {@link test.underscorename.AnnotatedMessage}.*/ + R visit(test.underscorename.AnnotatedMessage self, A arg) throws E; } @@ -29,14 +29,14 @@ public interface Visitor { TypeKind kind(); @Override - public BaseMsg registerListener(de.haumacher.msgbuf.observer.Listener l); + public test.underscorename.BaseMsg registerListener(de.haumacher.msgbuf.observer.Listener l); @Override - public BaseMsg unregisterListener(de.haumacher.msgbuf.observer.Listener l); + public test.underscorename.BaseMsg unregisterListener(de.haumacher.msgbuf.observer.Listener l); /** Reads a new instance from the given reader. */ - static BaseMsg readbase_msg(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - BaseMsg result; + static test.underscorename.BaseMsg readbase_msg(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.underscorename.BaseMsg result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -48,19 +48,19 @@ static BaseMsg readbase_msg(de.haumacher.msgbuf.json.JsonReader in) throws java. return result; } - /** The binary identifier for this concrete type in the polymorphic {@link BaseMsg} hierarchy. */ + /** The binary identifier for this concrete type in the polymorphic {@link test.underscorename.BaseMsg} hierarchy. */ abstract int typeId(); /** Reads a new instance from the given reader. */ - static BaseMsg readbase_msg(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.underscorename.BaseMsg readbase_msg(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); int typeField = in.nextName(); assert typeField == 0; int type = in.nextInt(); - BaseMsg result; + test.underscorename.BaseMsg result; switch (type) { - case SomeName.SOME_NAME__TYPE_ID: result = test.underscorename.SomeName_Impl.readsome_name_Content(in); break; - case AnnotatedMessage.ANNOTATED_MESSAGE__TYPE_ID: result = test.underscorename.AnnotatedMessage_Impl.readannotated_message_Content(in); break; + case test.underscorename.SomeName.SOME_NAME__TYPE_ID: result = test.underscorename.impl.SomeName_Impl.readsome_name_Content(in); break; + case test.underscorename.AnnotatedMessage.ANNOTATED_MESSAGE__TYPE_ID: result = test.underscorename.impl.AnnotatedMessage_Impl.readannotated_message_Content(in); break; default: result = null; while (in.hasNext()) {in.skipValue(); } } in.endObject(); @@ -70,7 +70,7 @@ static BaseMsg readbase_msg(de.haumacher.msgbuf.binary.DataReader in) throws jav /** Creates a new {@link BaseMsg} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static BaseMsg readBase_msg(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.underscorename.BaseMsg_Impl.readBase_msg_XmlContent(in); + return test.underscorename.impl.BaseMsg_Impl.readBase_msg_XmlContent(in); } /** Accepts the given visitor. */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java index fbb34a65..70b97f05 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java @@ -3,19 +3,19 @@ public interface SomeName extends BaseMsg { /** - * Creates a {@link SomeName} instance. + * Creates a {@link test.underscorename.SomeName} instance. */ - static SomeName create() { - return new test.underscorename.SomeName_Impl(); + static test.underscorename.SomeName create() { + return new test.underscorename.impl.SomeName_Impl(); } - /** Identifier for the {@link SomeName} type in JSON format. */ + /** Identifier for the {@link test.underscorename.SomeName} type in JSON format. */ static final String SOME_NAME__TYPE = "some_name"; /** @see #getMyField() */ static final String MY_FIELD__PROP = "my_field"; - /** Identifier for the {@link SomeName} type in binary format. */ + /** Identifier for the {@link test.underscorename.SomeName} type in binary format. */ static final int SOME_NAME__TYPE_ID = 1; /** Identifier for the property {@link #getMyField()} in binary format. */ @@ -26,19 +26,19 @@ static SomeName create() { /** * @see #getMyField() */ - SomeName setMyField(String value); + test.underscorename.SomeName setMyField(String value); /** Reads a new instance from the given reader. */ - static SomeName readsome_name(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - test.underscorename.SomeName_Impl result = new test.underscorename.SomeName_Impl(); + static test.underscorename.SomeName readsome_name(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.underscorename.impl.SomeName_Impl result = new test.underscorename.impl.SomeName_Impl(); result.readContent(in); return result; } /** Reads a new instance from the given reader. */ - static SomeName readsome_name(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + static test.underscorename.SomeName readsome_name(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - SomeName result = test.underscorename.SomeName_Impl.readsome_name_Content(in); + test.underscorename.SomeName result = test.underscorename.impl.SomeName_Impl.readsome_name_Content(in); in.endObject(); return result; } @@ -46,7 +46,7 @@ static SomeName readsome_name(de.haumacher.msgbuf.binary.DataReader in) throws j /** Creates a new {@link SomeName} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SomeName readSome_name(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); - return test.underscorename.SomeName_Impl.readSome_name_XmlContent(in); + return test.underscorename.impl.SomeName_Impl.readSome_name_XmlContent(in); } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java similarity index 78% rename from de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java index d0c6e44f..1beb94c0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java @@ -1,15 +1,15 @@ -package test.underscorename; +package test.underscorename.impl; -class AnnotatedMessage_Impl extends BaseMsg_Impl implements AnnotatedMessage { +public class AnnotatedMessage_Impl extends test.underscorename.impl.BaseMsg_Impl implements test.underscorename.AnnotatedMessage { private String _annotatedField = ""; /** * Creates a {@link AnnotatedMessage_Impl} instance. * - * @see AnnotatedMessage#create() + * @see test.underscorename.AnnotatedMessage#create() */ - protected AnnotatedMessage_Impl() { + public AnnotatedMessage_Impl() { super(); } @@ -24,7 +24,7 @@ public final String getAnnotatedField() { } @Override - public AnnotatedMessage setAnnotatedField(String value) { + public test.underscorename.AnnotatedMessage setAnnotatedField(String value) { internalSetAnnotatedField(value); return this; } @@ -92,9 +92,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getAnnotatedField()); } - /** Helper for creating an object of type {@link AnnotatedMessage} from a polymorphic composition. */ - public static AnnotatedMessage readannotated_message_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.underscorename.AnnotatedMessage_Impl result = new AnnotatedMessage_Impl(); + /** Helper for creating an object of type {@link test.underscorename.AnnotatedMessage} from a polymorphic composition. */ + public static test.underscorename.AnnotatedMessage readannotated_message_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.underscorename.impl.AnnotatedMessage_Impl result = new AnnotatedMessage_Impl(); result.readContent(in); return result; } @@ -107,7 +107,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link AnnotatedMessage} type. */ + /** XML element name representing a {@link test.underscorename.AnnotatedMessage} type. */ public static final String ANNOTATED_MESSAGE__XML_ELEMENT = "m1"; /** XML attribute or element name of a {@link #getAnnotatedField} property. */ @@ -129,9 +129,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link AnnotatedMessage} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.underscorename.AnnotatedMessage} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static AnnotatedMessage_Impl readAnnotated_message_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { AnnotatedMessage_Impl result = new AnnotatedMessage_Impl(); result.readContentXml(in); @@ -165,7 +166,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(BaseMsg.Visitor v, A arg) throws E { + public R visit(test.underscorename.BaseMsg.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/BaseMsg_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/BaseMsg_Impl.java similarity index 84% rename from de.haumacher.msgbuf.generator/src/test/java/test/underscorename/BaseMsg_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/BaseMsg_Impl.java index fefb438e..5c780b68 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/BaseMsg_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/BaseMsg_Impl.java @@ -1,11 +1,11 @@ -package test.underscorename; +package test.underscorename.impl; -abstract class BaseMsg_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements BaseMsg { +public abstract class BaseMsg_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.underscorename.BaseMsg { /** * Creates a {@link BaseMsg_Impl} instance. */ - protected BaseMsg_Impl() { + public BaseMsg_Impl() { super(); } @@ -15,7 +15,7 @@ protected BaseMsg_Impl() { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public BaseMsg registerListener(de.haumacher.msgbuf.observer.Listener l) { + public test.underscorename.BaseMsg registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -25,7 +25,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public BaseMsg unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public test.underscorename.BaseMsg unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -77,7 +77,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link BaseMsg} type. */ + /** XML element name representing a {@link test.underscorename.BaseMsg} type. */ public static final String BASE_MSG__XML_ELEMENT = "base-msg"; @Override @@ -92,17 +92,18 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. } - /** Creates a new {@link BaseMsg} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.underscorename.BaseMsg} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static BaseMsg_Impl readBase_msg_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { switch (in.getLocalName()) { case SomeName_Impl.SOME_NAME__XML_ELEMENT: { - return test.underscorename.SomeName_Impl.readSome_name_XmlContent(in); + return test.underscorename.impl.SomeName_Impl.readSome_name_XmlContent(in); } case AnnotatedMessage_Impl.ANNOTATED_MESSAGE__XML_ELEMENT: { - return test.underscorename.AnnotatedMessage_Impl.readAnnotated_message_XmlContent(in); + return test.underscorename.impl.AnnotatedMessage_Impl.readAnnotated_message_XmlContent(in); } default: { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java similarity index 78% rename from de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName_Impl.java rename to de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java index a43aa28d..1a849651 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java @@ -1,15 +1,15 @@ -package test.underscorename; +package test.underscorename.impl; -class SomeName_Impl extends BaseMsg_Impl implements SomeName { +public class SomeName_Impl extends test.underscorename.impl.BaseMsg_Impl implements test.underscorename.SomeName { private String _myField = ""; /** * Creates a {@link SomeName_Impl} instance. * - * @see SomeName#create() + * @see test.underscorename.SomeName#create() */ - protected SomeName_Impl() { + public SomeName_Impl() { super(); } @@ -24,7 +24,7 @@ public final String getMyField() { } @Override - public SomeName setMyField(String value) { + public test.underscorename.SomeName setMyField(String value) { internalSetMyField(value); return this; } @@ -92,9 +92,9 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.value(getMyField()); } - /** Helper for creating an object of type {@link SomeName} from a polymorphic composition. */ - public static SomeName readsome_name_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { - test.underscorename.SomeName_Impl result = new SomeName_Impl(); + /** Helper for creating an object of type {@link test.underscorename.SomeName} from a polymorphic composition. */ + public static test.underscorename.SomeName readsome_name_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.underscorename.impl.SomeName_Impl result = new SomeName_Impl(); result.readContent(in); return result; } @@ -107,7 +107,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link SomeName} type. */ + /** XML element name representing a {@link test.underscorename.SomeName} type. */ public static final String SOME_NAME__XML_ELEMENT = "some-name"; /** XML attribute or element name of a {@link #getMyField} property. */ @@ -129,9 +129,10 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java @Override protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeElements(out); + // No element fields. } - /** Creates a new {@link SomeName} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + /** Creates a new {@link test.underscorename.SomeName} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SomeName_Impl readSome_name_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { SomeName_Impl result = new SomeName_Impl(); result.readContentXml(in); @@ -165,7 +166,7 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l } @Override - public R visit(BaseMsg.Visitor v, A arg) throws E { + public R visit(test.underscorename.BaseMsg.Visitor v, A arg) throws E { return v.visit(this, arg); } From 8689a1727ae4d72daff735ac1511130a5c62a3f0 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 1 Jan 2023 22:18:40 +0100 Subject: [PATCH 031/207] Fixed modifiers of constants in interfaces. --- .../msgbuf/generator/MessageGenerator.java | 6 +++--- .../test/comments/data/SearchRequest.java | 8 ++++---- .../test/enumeration/data/SearchRequest.java | 10 +++++----- .../src/test/java/test/graph/data/Car.java | 8 ++++---- .../src/test/java/test/graph/data/Circle.java | 4 ++-- .../src/test/java/test/graph/data/Group.java | 4 ++-- .../test/java/test/graph/data/Rectangle.java | 6 +++--- .../src/test/java/test/graph/data/Shape.java | 4 ++-- .../test/java/test/graph/data/SimpleType.java | 6 +++--- .../test/java/test/hierarchy/data/Car.java | 8 ++++---- .../test/java/test/hierarchy/data/Circle.java | 4 ++-- .../test/java/test/hierarchy/data/Group.java | 4 ++-- .../java/test/hierarchy/data/Optional.java | 6 +++--- .../java/test/hierarchy/data/Rectangle.java | 6 +++--- .../test/java/test/hierarchy/data/Shape.java | 6 +++--- .../java/test/hierarchy/data/SimpleType.java | 6 +++--- .../src/test/java/test/innertypeclash/A.java | 10 +++++----- .../src/test/java/test/innertypeclash/B.java | 10 +++++----- .../test/java/test/lowercasemessage/A.java | 12 +++++------ .../java/test/maptype/data/MyMessage.java | 6 +++--- .../test/java/test/maptype/data/Project.java | 6 +++--- .../java/test/nested/data/SearchResponse.java | 12 +++++------ .../src/test/java/test/nojson/Car.java | 8 ++++---- .../src/test/java/test/nojson/Circle.java | 4 ++-- .../src/test/java/test/nojson/Group.java | 4 ++-- .../src/test/java/test/nojson/Rectangle.java | 6 +++--- .../src/test/java/test/nojson/Shape.java | 4 ++-- .../src/test/java/test/nojson/SimpleType.java | 6 +++--- .../src/test/java/test/nolistener/Car.java | 8 ++++---- .../src/test/java/test/nolistener/Circle.java | 4 ++-- .../src/test/java/test/nolistener/Group.java | 4 ++-- .../test/java/test/nolistener/Rectangle.java | 6 +++--- .../src/test/java/test/nolistener/Shape.java | 4 ++-- .../test/java/test/nolistener/SimpleType.java | 6 +++--- .../src/test/java/test/notypekind/Car.java | 8 ++++---- .../src/test/java/test/notypekind/Circle.java | 4 ++-- .../src/test/java/test/notypekind/Group.java | 4 ++-- .../test/java/test/notypekind/Rectangle.java | 6 +++--- .../src/test/java/test/notypekind/Shape.java | 4 ++-- .../test/java/test/notypekind/SimpleType.java | 6 +++--- .../src/test/java/test/novisit/Car.java | 8 ++++---- .../src/test/java/test/novisit/Circle.java | 4 ++-- .../src/test/java/test/novisit/Group.java | 4 ++-- .../src/test/java/test/novisit/Rectangle.java | 6 +++--- .../src/test/java/test/novisit/Shape.java | 4 ++-- .../test/java/test/novisit/SimpleType.java | 6 +++--- .../test/java/test/novisitexceptions/Car.java | 8 ++++---- .../java/test/novisitexceptions/Circle.java | 4 ++-- .../java/test/novisitexceptions/Group.java | 4 ++-- .../test/novisitexceptions/Rectangle.java | 6 +++--- .../java/test/novisitexceptions/Shape.java | 4 ++-- .../test/novisitexceptions/SimpleType.java | 6 +++--- .../test/nullable/data/NullableValues.java | 18 ++++++++--------- .../test/oneoffield/data/SampleMessage.java | 2 +- .../java/test/options/data/MyMessage1.java | 2 +- .../java/test/options/data/MyMessage2.java | 2 +- .../src/test/java/test/references/data/A.java | 20 +++++++++---------- .../src/test/java/test/references/data/B.java | 8 ++++---- .../java/test/types/data/SearchRequest.java | 8 ++++---- .../test/underscorename/AnnotatedMessage.java | 4 ++-- .../java/test/underscorename/SomeName.java | 4 ++-- 61 files changed, 190 insertions(+), 190 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 6cb3d76e..70e57ef8 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -405,13 +405,13 @@ private void generateConstants() { if ((_json || _reflection) && !_def.isAbstract()) { nl(); line("/** Identifier for the {@link " + qTypeName(_def) + "} type in JSON format. */"); - line((_noInterfaces ? "public " : "") + "static final String " + jsonTypeConstant(_def) + " = " + jsonTypeID(_def) + ";"); + line((_noInterfaces ? "public static final " : "") + "String " + jsonTypeConstant(_def) + " = " + jsonTypeID(_def) + ";"); } } if (_json || _reflection) { if (_interface || _noInterfaces) { - String modifier = _reflection ? (_noInterfaces ? "public " : "") : "private "; + String modifier = _reflection ? (_noInterfaces ? "public " : "") : (_noInterfaces ? "private " : ""); for (Field field : getFields()) { if (!_reflection && field.isTransient()) { @@ -419,7 +419,7 @@ private void generateConstants() { } nl(); line("/** @see #" + getterCall(field) + " */"); - line(modifier + "static final String " + constant(field) + " = " + getFieldNameString(field) + ";"); + line(modifier + (_noInterfaces ? "static final " : "") + "String " + constant(field) + " = " + getFieldNameString(field) + ";"); } } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java index 0e43b6bb..37a5d779 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/SearchRequest.java @@ -14,16 +14,16 @@ static test.comments.data.SearchRequest create() { } /** Identifier for the {@link test.comments.data.SearchRequest} type in JSON format. */ - static final String SEARCH_REQUEST__TYPE = "SearchRequest"; + String SEARCH_REQUEST__TYPE = "SearchRequest"; /** @see #getQuery() */ - static final String QUERY__PROP = "query"; + String QUERY__PROP = "query"; /** @see #getPageNumber() */ - static final String PAGE_NUMBER__PROP = "page_number"; + String PAGE_NUMBER__PROP = "page_number"; /** @see #getResultPerPage() */ - static final String RESULT_PER_PAGE__PROP = "result_per_page"; + String RESULT_PER_PAGE__PROP = "result_per_page"; /** Identifier for the property {@link #getQuery()} in binary format. */ static final int QUERY__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java index d06e0883..d4371d9b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/SearchRequest.java @@ -98,19 +98,19 @@ static test.enumeration.data.SearchRequest create() { } /** Identifier for the {@link test.enumeration.data.SearchRequest} type in JSON format. */ - static final String SEARCH_REQUEST__TYPE = "SearchRequest"; + String SEARCH_REQUEST__TYPE = "SearchRequest"; /** @see #getQuery() */ - static final String QUERY__PROP = "query"; + String QUERY__PROP = "query"; /** @see #getPageNumber() */ - static final String PAGE_NUMBER__PROP = "page_number"; + String PAGE_NUMBER__PROP = "page_number"; /** @see #getResultPerPage() */ - static final String RESULT_PER_PAGE__PROP = "result_per_page"; + String RESULT_PER_PAGE__PROP = "result_per_page"; /** @see #getCorpus() */ - static final String CORPUS__PROP = "corpus"; + String CORPUS__PROP = "corpus"; /** Identifier for the property {@link #getQuery()} in binary format. */ static final int QUERY__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java index f48eb2e5..83431e7a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Car.java @@ -13,16 +13,16 @@ static test.graph.data.Car create() { } /** Identifier for the {@link test.graph.data.Car} type in JSON format. */ - static final String CAR__TYPE = "Car"; + String CAR__TYPE = "Car"; /** @see #getWheel1() */ - static final String WHEEL_1__PROP = "wheel1"; + String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - static final String WHEEL_2__PROP = "wheel2"; + String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - static final String BODY__PROP = "body"; + String BODY__PROP = "body"; /** * The front wheel. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java index 48002eac..7ec8d638 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Circle.java @@ -13,10 +13,10 @@ static test.graph.data.Circle create() { } /** Identifier for the {@link test.graph.data.Circle} type in JSON format. */ - static final String CIRCLE__TYPE = "Circle"; + String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ - static final String RADIUS__PROP = "r"; + String RADIUS__PROP = "r"; /** * The radius of this {@link Circle} around its coordinate origin at ({@link #getXCoordinate()}, {@link #getYCoordinate()}). diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java index 5794c8f6..a80c1230 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Group.java @@ -13,10 +13,10 @@ static test.graph.data.Group create() { } /** Identifier for the {@link test.graph.data.Group} type in JSON format. */ - static final String GROUP__TYPE = "Group"; + String GROUP__TYPE = "Group"; /** @see #getShapes() */ - static final String SHAPES__PROP = "shapes"; + String SHAPES__PROP = "shapes"; /** * All {@link Shape}s in this {@link Group}. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java index a16060a9..2cc4372e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Rectangle.java @@ -13,13 +13,13 @@ static test.graph.data.Rectangle create() { } /** Identifier for the {@link test.graph.data.Rectangle} type in JSON format. */ - static final String RECTANGLE__TYPE = "Rectangle"; + String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ - static final String WIDTH__PROP = "w"; + String WIDTH__PROP = "w"; /** @see #getHeight() */ - static final String HEIGHT__PROP = "h"; + String HEIGHT__PROP = "h"; /** * The width of this {@link Rectangle}. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java index 9d2bfcf3..d8de4c65 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/Shape.java @@ -35,10 +35,10 @@ public interface Visitor extends test.graph.data.Atomic } /** @see #getXCoordinate() */ - static final String X_COORDINATE__PROP = "x"; + String X_COORDINATE__PROP = "x"; /** @see #getYCoordinate() */ - static final String Y_COORDINATE__PROP = "y"; + String Y_COORDINATE__PROP = "y"; /** The type code of this instance. */ TypeKind kind(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/SimpleType.java index 667f8494..5fba7698 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/SimpleType.java @@ -13,13 +13,13 @@ static test.graph.data.SimpleType create() { } /** Identifier for the {@link test.graph.data.SimpleType} type in JSON format. */ - static final String SIMPLE_TYPE__TYPE = "SimpleType"; + String SIMPLE_TYPE__TYPE = "SimpleType"; /** @see #getStr() */ - static final String STR__PROP = "str"; + String STR__PROP = "str"; /** @see #getX() */ - static final String X__PROP = "x"; + String X__PROP = "x"; /** * A string property diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java index a5572a6e..d6b6be44 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Car.java @@ -13,16 +13,16 @@ static test.hierarchy.data.Car create() { } /** Identifier for the {@link test.hierarchy.data.Car} type in JSON format. */ - static final String CAR__TYPE = "Car"; + String CAR__TYPE = "Car"; /** @see #getWheel1() */ - static final String WHEEL_1__PROP = "wheel1"; + String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - static final String WHEEL_2__PROP = "wheel2"; + String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - static final String BODY__PROP = "body"; + String BODY__PROP = "body"; /** Identifier for the {@link test.hierarchy.data.Car} type in binary format. */ static final int CAR__TYPE_ID = 5; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java index 7d2a80ca..a23dffc8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Circle.java @@ -13,10 +13,10 @@ static test.hierarchy.data.Circle create() { } /** Identifier for the {@link test.hierarchy.data.Circle} type in JSON format. */ - static final String CIRCLE__TYPE = "Circle"; + String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ - static final String RADIUS__PROP = "r"; + String RADIUS__PROP = "r"; /** Identifier for the {@link test.hierarchy.data.Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java index 5873171e..2749bdb6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Group.java @@ -13,10 +13,10 @@ static test.hierarchy.data.Group create() { } /** Identifier for the {@link test.hierarchy.data.Group} type in JSON format. */ - static final String GROUP__TYPE = "Group"; + String GROUP__TYPE = "Group"; /** @see #getShapes() */ - static final String SHAPES__PROP = "shapes"; + String SHAPES__PROP = "shapes"; /** Identifier for the {@link test.hierarchy.data.Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java index 40205f40..7aabdee1 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java @@ -13,13 +13,13 @@ static test.hierarchy.data.Optional create() { } /** Identifier for the {@link test.hierarchy.data.Optional} type in JSON format. */ - static final String OPTIONAL__TYPE = "Optional"; + String OPTIONAL__TYPE = "Optional"; /** @see #isHidden() */ - static final String HIDDEN__PROP = "hidden"; + String HIDDEN__PROP = "hidden"; /** @see #getShape() */ - static final String SHAPE__PROP = "shape"; + String SHAPE__PROP = "shape"; /** Identifier for the {@link test.hierarchy.data.Optional} type in binary format. */ static final int OPTIONAL__TYPE_ID = 4; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java index c8d22b31..a1f23e58 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Rectangle.java @@ -13,13 +13,13 @@ static test.hierarchy.data.Rectangle create() { } /** Identifier for the {@link test.hierarchy.data.Rectangle} type in JSON format. */ - static final String RECTANGLE__TYPE = "Rectangle"; + String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ - static final String WIDTH__PROP = "w"; + String WIDTH__PROP = "w"; /** @see #getHeight() */ - static final String HEIGHT__PROP = "h"; + String HEIGHT__PROP = "h"; /** Identifier for the {@link test.hierarchy.data.Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java index 57711305..3b9a2246 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Shape.java @@ -41,13 +41,13 @@ public interface Visitor extends test.hierarchy.data.At } /** @see #getXCoordinate() */ - static final String X_COORDINATE__PROP = "x"; + String X_COORDINATE__PROP = "x"; /** @see #getYCoordinate() */ - static final String Y_COORDINATE__PROP = "y"; + String Y_COORDINATE__PROP = "y"; /** @see #getColor() */ - static final String COLOR__PROP = "color"; + String COLOR__PROP = "color"; /** Identifier for the property {@link #getXCoordinate()} in binary format. */ static final int X_COORDINATE__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/SimpleType.java index 964ca360..85c54e71 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/SimpleType.java @@ -13,13 +13,13 @@ static test.hierarchy.data.SimpleType create() { } /** Identifier for the {@link test.hierarchy.data.SimpleType} type in JSON format. */ - static final String SIMPLE_TYPE__TYPE = "SimpleType"; + String SIMPLE_TYPE__TYPE = "SimpleType"; /** @see #getStr() */ - static final String STR__PROP = "str"; + String STR__PROP = "str"; /** @see #getX() */ - static final String X__PROP = "x"; + String X__PROP = "x"; /** Identifier for the property {@link #getStr()} in binary format. */ static final int STR__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java index 09e5424c..f16ac301 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/A.java @@ -11,7 +11,7 @@ static test.innertypeclash.A.C create() { } /** Identifier for the {@link test.innertypeclash.A.C} type in JSON format. */ - static final String C__TYPE = "C"; + String C__TYPE = "C"; @Override public test.innertypeclash.A.C registerListener(de.haumacher.msgbuf.observer.Listener l); @@ -50,16 +50,16 @@ static test.innertypeclash.A create() { } /** Identifier for the {@link test.innertypeclash.A} type in JSON format. */ - static final String A__TYPE = "A"; + String A__TYPE = "A"; /** @see #getAc() */ - static final String AC__PROP = "ac"; + String AC__PROP = "ac"; /** @see #getBc() */ - static final String BC__PROP = "bc"; + String BC__PROP = "bc"; /** @see #getC() */ - static final String C__PROP = "c"; + String C__PROP = "c"; /** Identifier for the property {@link #getAc()} in binary format. */ static final int AC__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java index 619ec4a7..539ef0bd 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/B.java @@ -11,7 +11,7 @@ static test.innertypeclash.B.C create() { } /** Identifier for the {@link test.innertypeclash.B.C} type in JSON format. */ - static final String C__TYPE = "C"; + String C__TYPE = "C"; @Override public test.innertypeclash.B.C registerListener(de.haumacher.msgbuf.observer.Listener l); @@ -50,16 +50,16 @@ static test.innertypeclash.B create() { } /** Identifier for the {@link test.innertypeclash.B} type in JSON format. */ - static final String B__TYPE = "B"; + String B__TYPE = "B"; /** @see #getAc() */ - static final String AC__PROP = "ac"; + String AC__PROP = "ac"; /** @see #getBc() */ - static final String BC__PROP = "bc"; + String BC__PROP = "bc"; /** @see #getC() */ - static final String C__PROP = "c"; + String C__PROP = "c"; /** Identifier for the property {@link #getAc()} in binary format. */ static final int AC__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java index b1758a52..3358f53e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/A.java @@ -11,13 +11,13 @@ static test.lowercasemessage.A.B create() { } /** Identifier for the {@link test.lowercasemessage.A.B} type in JSON format. */ - static final String B__TYPE = "b"; + String B__TYPE = "b"; /** @see #getA1() */ - static final String A_1__PROP = "a1"; + String A_1__PROP = "a1"; /** @see #getB1() */ - static final String B_1__PROP = "b1"; + String B_1__PROP = "b1"; /** Identifier for the property {@link #getA1()} in binary format. */ static final int A_1__ID = 1; @@ -86,13 +86,13 @@ static test.lowercasemessage.A create() { } /** Identifier for the {@link test.lowercasemessage.A} type in JSON format. */ - static final String A__TYPE = "a"; + String A__TYPE = "a"; /** @see #getA1() */ - static final String A_1__PROP = "a1"; + String A_1__PROP = "a1"; /** @see #getB1() */ - static final String B_1__PROP = "b1"; + String B_1__PROP = "b1"; /** Identifier for the property {@link #getA1()} in binary format. */ static final int A_1__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java index 844ca565..bf9db025 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java @@ -10,13 +10,13 @@ static test.maptype.data.MyMessage create() { } /** Identifier for the {@link test.maptype.data.MyMessage} type in JSON format. */ - static final String MY_MESSAGE__TYPE = "MyMessage"; + String MY_MESSAGE__TYPE = "MyMessage"; /** @see #getProjects() */ - static final String PROJECTS__PROP = "projects"; + String PROJECTS__PROP = "projects"; /** @see #getRating() */ - static final String RATING__PROP = "rating"; + String RATING__PROP = "rating"; /** Identifier for the property {@link #getProjects()} in binary format. */ static final int PROJECTS__ID = 3; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java index c88112e7..38929d91 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/Project.java @@ -10,13 +10,13 @@ static test.maptype.data.Project create() { } /** Identifier for the {@link test.maptype.data.Project} type in JSON format. */ - static final String PROJECT__TYPE = "Project"; + String PROJECT__TYPE = "Project"; /** @see #getName() */ - static final String NAME__PROP = "name"; + String NAME__PROP = "name"; /** @see #getCost() */ - static final String COST__PROP = "cost"; + String COST__PROP = "cost"; /** Identifier for the property {@link #getName()} in binary format. */ static final int NAME__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java index 97321fc3..5f4fdabe 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/SearchResponse.java @@ -11,16 +11,16 @@ static test.nested.data.SearchResponse.Result create() { } /** Identifier for the {@link test.nested.data.SearchResponse.Result} type in JSON format. */ - static final String RESULT__TYPE = "Result"; + String RESULT__TYPE = "Result"; /** @see #getUrl() */ - static final String URL__PROP = "url"; + String URL__PROP = "url"; /** @see #getTitle() */ - static final String TITLE__PROP = "title"; + String TITLE__PROP = "title"; /** @see #getSnippets() */ - static final String SNIPPETS__PROP = "snippets"; + String SNIPPETS__PROP = "snippets"; /** Identifier for the property {@link #getUrl()} in binary format. */ static final int URL__ID = 1; @@ -99,10 +99,10 @@ static test.nested.data.SearchResponse create() { } /** Identifier for the {@link test.nested.data.SearchResponse} type in JSON format. */ - static final String SEARCH_RESPONSE__TYPE = "SearchResponse"; + String SEARCH_RESPONSE__TYPE = "SearchResponse"; /** @see #getResults() */ - static final String RESULTS__PROP = "results"; + String RESULTS__PROP = "results"; /** Identifier for the property {@link #getResults()} in binary format. */ static final int RESULTS__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java index e9aaf29f..47816960 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Car.java @@ -13,16 +13,16 @@ static test.nojson.Car create() { } /** Identifier for the {@link test.nojson.Car} type in JSON format. */ - static final String CAR__TYPE = "Car"; + String CAR__TYPE = "Car"; /** @see #getWheel1() */ - static final String WHEEL_1__PROP = "wheel1"; + String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - static final String WHEEL_2__PROP = "wheel2"; + String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - static final String BODY__PROP = "body"; + String BODY__PROP = "body"; /** Identifier for the {@link test.nojson.Car} type in binary format. */ static final int CAR__TYPE_ID = 4; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java index 6004b96d..9c62646b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Circle.java @@ -13,10 +13,10 @@ static test.nojson.Circle create() { } /** Identifier for the {@link test.nojson.Circle} type in JSON format. */ - static final String CIRCLE__TYPE = "Circle"; + String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ - static final String RADIUS__PROP = "r"; + String RADIUS__PROP = "r"; /** Identifier for the {@link test.nojson.Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java index 6c64a1f3..044390cf 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Group.java @@ -13,10 +13,10 @@ static test.nojson.Group create() { } /** Identifier for the {@link test.nojson.Group} type in JSON format. */ - static final String GROUP__TYPE = "Group"; + String GROUP__TYPE = "Group"; /** @see #getShapes() */ - static final String SHAPES__PROP = "shapes"; + String SHAPES__PROP = "shapes"; /** Identifier for the {@link test.nojson.Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java index 8e4c6cc5..7a73f9d1 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Rectangle.java @@ -13,13 +13,13 @@ static test.nojson.Rectangle create() { } /** Identifier for the {@link test.nojson.Rectangle} type in JSON format. */ - static final String RECTANGLE__TYPE = "Rectangle"; + String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ - static final String WIDTH__PROP = "w"; + String WIDTH__PROP = "w"; /** @see #getHeight() */ - static final String HEIGHT__PROP = "h"; + String HEIGHT__PROP = "h"; /** Identifier for the {@link test.nojson.Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java index 5902cfee..ffacf3e9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/Shape.java @@ -35,10 +35,10 @@ public interface Visitor extends test.nojson.AtomicShap } /** @see #getXCoordinate() */ - static final String X_COORDINATE__PROP = "x"; + String X_COORDINATE__PROP = "x"; /** @see #getYCoordinate() */ - static final String Y_COORDINATE__PROP = "y"; + String Y_COORDINATE__PROP = "y"; /** Identifier for the property {@link #getXCoordinate()} in binary format. */ static final int X_COORDINATE__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/SimpleType.java index e37c3186..e1e862fa 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/SimpleType.java @@ -13,13 +13,13 @@ static test.nojson.SimpleType create() { } /** Identifier for the {@link test.nojson.SimpleType} type in JSON format. */ - static final String SIMPLE_TYPE__TYPE = "SimpleType"; + String SIMPLE_TYPE__TYPE = "SimpleType"; /** @see #getStr() */ - static final String STR__PROP = "str"; + String STR__PROP = "str"; /** @see #getX() */ - static final String X__PROP = "x"; + String X__PROP = "x"; /** Identifier for the property {@link #getStr()} in binary format. */ static final int STR__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java index 08e6d751..2c38e2cd 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Car.java @@ -13,16 +13,16 @@ static test.nolistener.Car create() { } /** Identifier for the {@link test.nolistener.Car} type in JSON format. */ - static final String CAR__TYPE = "Car"; + String CAR__TYPE = "Car"; /** @see #getWheel1() */ - static final String WHEEL_1__PROP = "wheel1"; + String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - static final String WHEEL_2__PROP = "wheel2"; + String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - static final String BODY__PROP = "body"; + String BODY__PROP = "body"; /** Identifier for the {@link test.nolistener.Car} type in binary format. */ static final int CAR__TYPE_ID = 4; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java index 4a5b04ba..6bfb37fe 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Circle.java @@ -13,10 +13,10 @@ static test.nolistener.Circle create() { } /** Identifier for the {@link test.nolistener.Circle} type in JSON format. */ - static final String CIRCLE__TYPE = "Circle"; + String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ - static final String RADIUS__PROP = "r"; + String RADIUS__PROP = "r"; /** Identifier for the {@link test.nolistener.Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java index b4b5b1e0..10d93259 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Group.java @@ -13,10 +13,10 @@ static test.nolistener.Group create() { } /** Identifier for the {@link test.nolistener.Group} type in JSON format. */ - static final String GROUP__TYPE = "Group"; + String GROUP__TYPE = "Group"; /** @see #getShapes() */ - static final String SHAPES__PROP = "shapes"; + String SHAPES__PROP = "shapes"; /** Identifier for the {@link test.nolistener.Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java index baaa7a30..0aea5c7d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Rectangle.java @@ -13,13 +13,13 @@ static test.nolistener.Rectangle create() { } /** Identifier for the {@link test.nolistener.Rectangle} type in JSON format. */ - static final String RECTANGLE__TYPE = "Rectangle"; + String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ - static final String WIDTH__PROP = "w"; + String WIDTH__PROP = "w"; /** @see #getHeight() */ - static final String HEIGHT__PROP = "h"; + String HEIGHT__PROP = "h"; /** Identifier for the {@link test.nolistener.Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java index 1d5ed00a..d1648400 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/Shape.java @@ -35,10 +35,10 @@ public interface Visitor extends test.nolistener.Atomic } /** @see #getXCoordinate() */ - static final String X_COORDINATE__PROP = "x"; + String X_COORDINATE__PROP = "x"; /** @see #getYCoordinate() */ - static final String Y_COORDINATE__PROP = "y"; + String Y_COORDINATE__PROP = "y"; /** Identifier for the property {@link #getXCoordinate()} in binary format. */ static final int X_COORDINATE__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/SimpleType.java index b7c99aa1..47f391d8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/SimpleType.java @@ -13,13 +13,13 @@ static test.nolistener.SimpleType create() { } /** Identifier for the {@link test.nolistener.SimpleType} type in JSON format. */ - static final String SIMPLE_TYPE__TYPE = "SimpleType"; + String SIMPLE_TYPE__TYPE = "SimpleType"; /** @see #getStr() */ - static final String STR__PROP = "str"; + String STR__PROP = "str"; /** @see #getX() */ - static final String X__PROP = "x"; + String X__PROP = "x"; /** Identifier for the property {@link #getStr()} in binary format. */ static final int STR__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java index f0c54d1d..379b4f6d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Car.java @@ -13,16 +13,16 @@ static test.notypekind.Car create() { } /** Identifier for the {@link test.notypekind.Car} type in JSON format. */ - static final String CAR__TYPE = "Car"; + String CAR__TYPE = "Car"; /** @see #getWheel1() */ - static final String WHEEL_1__PROP = "wheel1"; + String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - static final String WHEEL_2__PROP = "wheel2"; + String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - static final String BODY__PROP = "body"; + String BODY__PROP = "body"; /** Identifier for the {@link test.notypekind.Car} type in binary format. */ static final int CAR__TYPE_ID = 4; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java index c0c8ac27..74b73ac0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Circle.java @@ -13,10 +13,10 @@ static test.notypekind.Circle create() { } /** Identifier for the {@link test.notypekind.Circle} type in JSON format. */ - static final String CIRCLE__TYPE = "Circle"; + String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ - static final String RADIUS__PROP = "r"; + String RADIUS__PROP = "r"; /** Identifier for the {@link test.notypekind.Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java index b0353afc..ab361730 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Group.java @@ -13,10 +13,10 @@ static test.notypekind.Group create() { } /** Identifier for the {@link test.notypekind.Group} type in JSON format. */ - static final String GROUP__TYPE = "Group"; + String GROUP__TYPE = "Group"; /** @see #getShapes() */ - static final String SHAPES__PROP = "shapes"; + String SHAPES__PROP = "shapes"; /** Identifier for the {@link test.notypekind.Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java index dc1970b2..75bc4e8c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Rectangle.java @@ -13,13 +13,13 @@ static test.notypekind.Rectangle create() { } /** Identifier for the {@link test.notypekind.Rectangle} type in JSON format. */ - static final String RECTANGLE__TYPE = "Rectangle"; + String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ - static final String WIDTH__PROP = "w"; + String WIDTH__PROP = "w"; /** @see #getHeight() */ - static final String HEIGHT__PROP = "h"; + String HEIGHT__PROP = "h"; /** Identifier for the {@link test.notypekind.Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java index 98cff04b..ff712917 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/Shape.java @@ -17,10 +17,10 @@ public interface Visitor extends test.notypekind.Atomic } /** @see #getXCoordinate() */ - static final String X_COORDINATE__PROP = "x"; + String X_COORDINATE__PROP = "x"; /** @see #getYCoordinate() */ - static final String Y_COORDINATE__PROP = "y"; + String Y_COORDINATE__PROP = "y"; /** Identifier for the property {@link #getXCoordinate()} in binary format. */ static final int X_COORDINATE__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/SimpleType.java index c54c96ad..c36879e4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/SimpleType.java @@ -13,13 +13,13 @@ static test.notypekind.SimpleType create() { } /** Identifier for the {@link test.notypekind.SimpleType} type in JSON format. */ - static final String SIMPLE_TYPE__TYPE = "SimpleType"; + String SIMPLE_TYPE__TYPE = "SimpleType"; /** @see #getStr() */ - static final String STR__PROP = "str"; + String STR__PROP = "str"; /** @see #getX() */ - static final String X__PROP = "x"; + String X__PROP = "x"; /** Identifier for the property {@link #getStr()} in binary format. */ static final int STR__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java index 4aad5c6c..1ef76968 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Car.java @@ -13,16 +13,16 @@ static test.novisit.Car create() { } /** Identifier for the {@link test.novisit.Car} type in JSON format. */ - static final String CAR__TYPE = "Car"; + String CAR__TYPE = "Car"; /** @see #getWheel1() */ - static final String WHEEL_1__PROP = "wheel1"; + String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - static final String WHEEL_2__PROP = "wheel2"; + String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - static final String BODY__PROP = "body"; + String BODY__PROP = "body"; /** Identifier for the {@link test.novisit.Car} type in binary format. */ static final int CAR__TYPE_ID = 4; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java index 55b8e442..6f31afc3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Circle.java @@ -13,10 +13,10 @@ static test.novisit.Circle create() { } /** Identifier for the {@link test.novisit.Circle} type in JSON format. */ - static final String CIRCLE__TYPE = "Circle"; + String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ - static final String RADIUS__PROP = "r"; + String RADIUS__PROP = "r"; /** Identifier for the {@link test.novisit.Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java index f07b617a..9b44d29b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Group.java @@ -13,10 +13,10 @@ static test.novisit.Group create() { } /** Identifier for the {@link test.novisit.Group} type in JSON format. */ - static final String GROUP__TYPE = "Group"; + String GROUP__TYPE = "Group"; /** @see #getShapes() */ - static final String SHAPES__PROP = "shapes"; + String SHAPES__PROP = "shapes"; /** Identifier for the {@link test.novisit.Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java index 776e6473..e1c50849 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Rectangle.java @@ -13,13 +13,13 @@ static test.novisit.Rectangle create() { } /** Identifier for the {@link test.novisit.Rectangle} type in JSON format. */ - static final String RECTANGLE__TYPE = "Rectangle"; + String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ - static final String WIDTH__PROP = "w"; + String WIDTH__PROP = "w"; /** @see #getHeight() */ - static final String HEIGHT__PROP = "h"; + String HEIGHT__PROP = "h"; /** Identifier for the {@link test.novisit.Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java index 6430b030..1f48c30e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/Shape.java @@ -24,10 +24,10 @@ public enum TypeKind { } /** @see #getXCoordinate() */ - static final String X_COORDINATE__PROP = "x"; + String X_COORDINATE__PROP = "x"; /** @see #getYCoordinate() */ - static final String Y_COORDINATE__PROP = "y"; + String Y_COORDINATE__PROP = "y"; /** Identifier for the property {@link #getXCoordinate()} in binary format. */ static final int X_COORDINATE__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType.java index 5195f020..396b90ee 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/SimpleType.java @@ -13,13 +13,13 @@ static test.novisit.SimpleType create() { } /** Identifier for the {@link test.novisit.SimpleType} type in JSON format. */ - static final String SIMPLE_TYPE__TYPE = "SimpleType"; + String SIMPLE_TYPE__TYPE = "SimpleType"; /** @see #getStr() */ - static final String STR__PROP = "str"; + String STR__PROP = "str"; /** @see #getX() */ - static final String X__PROP = "x"; + String X__PROP = "x"; /** Identifier for the property {@link #getStr()} in binary format. */ static final int STR__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java index 90e80573..95828b0f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Car.java @@ -13,16 +13,16 @@ static test.novisitexceptions.Car create() { } /** Identifier for the {@link test.novisitexceptions.Car} type in JSON format. */ - static final String CAR__TYPE = "Car"; + String CAR__TYPE = "Car"; /** @see #getWheel1() */ - static final String WHEEL_1__PROP = "wheel1"; + String WHEEL_1__PROP = "wheel1"; /** @see #getWheel2() */ - static final String WHEEL_2__PROP = "wheel2"; + String WHEEL_2__PROP = "wheel2"; /** @see #getBody() */ - static final String BODY__PROP = "body"; + String BODY__PROP = "body"; /** Identifier for the {@link test.novisitexceptions.Car} type in binary format. */ static final int CAR__TYPE_ID = 4; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java index 9f45efb6..1707323f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Circle.java @@ -13,10 +13,10 @@ static test.novisitexceptions.Circle create() { } /** Identifier for the {@link test.novisitexceptions.Circle} type in JSON format. */ - static final String CIRCLE__TYPE = "Circle"; + String CIRCLE__TYPE = "Circle"; /** @see #getRadius() */ - static final String RADIUS__PROP = "r"; + String RADIUS__PROP = "r"; /** Identifier for the {@link test.novisitexceptions.Circle} type in binary format. */ static final int CIRCLE__TYPE_ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java index 2517d469..ef30f7b6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Group.java @@ -13,10 +13,10 @@ static test.novisitexceptions.Group create() { } /** Identifier for the {@link test.novisitexceptions.Group} type in JSON format. */ - static final String GROUP__TYPE = "Group"; + String GROUP__TYPE = "Group"; /** @see #getShapes() */ - static final String SHAPES__PROP = "shapes"; + String SHAPES__PROP = "shapes"; /** Identifier for the {@link test.novisitexceptions.Group} type in binary format. */ static final int GROUP__TYPE_ID = 3; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java index 93e80a91..27b42308 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Rectangle.java @@ -13,13 +13,13 @@ static test.novisitexceptions.Rectangle create() { } /** Identifier for the {@link test.novisitexceptions.Rectangle} type in JSON format. */ - static final String RECTANGLE__TYPE = "Rectangle"; + String RECTANGLE__TYPE = "Rectangle"; /** @see #getWidth() */ - static final String WIDTH__PROP = "w"; + String WIDTH__PROP = "w"; /** @see #getHeight() */ - static final String HEIGHT__PROP = "h"; + String HEIGHT__PROP = "h"; /** Identifier for the {@link test.novisitexceptions.Rectangle} type in binary format. */ static final int RECTANGLE__TYPE_ID = 2; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java index e84a53c9..da551ed2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/Shape.java @@ -35,10 +35,10 @@ public interface Visitor extends test.novisitexceptions.AtomicShape.Visitor } /** @see #getXCoordinate() */ - static final String X_COORDINATE__PROP = "x"; + String X_COORDINATE__PROP = "x"; /** @see #getYCoordinate() */ - static final String Y_COORDINATE__PROP = "y"; + String Y_COORDINATE__PROP = "y"; /** Identifier for the property {@link #getXCoordinate()} in binary format. */ static final int X_COORDINATE__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType.java index a7e67118..d0f6a5a5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/SimpleType.java @@ -13,13 +13,13 @@ static test.novisitexceptions.SimpleType create() { } /** Identifier for the {@link test.novisitexceptions.SimpleType} type in JSON format. */ - static final String SIMPLE_TYPE__TYPE = "SimpleType"; + String SIMPLE_TYPE__TYPE = "SimpleType"; /** @see #getStr() */ - static final String STR__PROP = "str"; + String STR__PROP = "str"; /** @see #getX() */ - static final String X__PROP = "x"; + String X__PROP = "x"; /** Identifier for the property {@link #getStr()} in binary format. */ static final int STR__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java index 987136fe..8b2b3b8b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/NullableValues.java @@ -10,31 +10,31 @@ static test.nullable.data.NullableValues create() { } /** Identifier for the {@link test.nullable.data.NullableValues} type in JSON format. */ - static final String NULLABLE_VALUES__TYPE = "NullableValues"; + String NULLABLE_VALUES__TYPE = "NullableValues"; /** @see #getInt() */ - static final String INT__PROP = "int"; + String INT__PROP = "int"; /** @see #getLong() */ - static final String LONG__PROP = "long"; + String LONG__PROP = "long"; /** @see #getBoolean() */ - static final String BOOLEAN__PROP = "boolean"; + String BOOLEAN__PROP = "boolean"; /** @see #getString() */ - static final String STRING__PROP = "string"; + String STRING__PROP = "string"; /** @see #getIntList() */ - static final String INT_LIST__PROP = "intList"; + String INT_LIST__PROP = "intList"; /** @see #getStringList() */ - static final String STRING_LIST__PROP = "stringList"; + String STRING_LIST__PROP = "stringList"; /** @see #getStringIntMap() */ - static final String STRING_INT_MAP__PROP = "stringIntMap"; + String STRING_INT_MAP__PROP = "stringIntMap"; /** @see #getOptionalDecision() */ - static final String OPTIONAL_DECISION__PROP = "optionalDecision"; + String OPTIONAL_DECISION__PROP = "optionalDecision"; /** Identifier for the property {@link #getInt()} in binary format. */ static final int INT__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java b/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java index 015ed7dd..f12149bd 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/SampleMessage.java @@ -10,7 +10,7 @@ static test.oneoffield.data.SampleMessage create() { } /** Identifier for the {@link test.oneoffield.data.SampleMessage} type in JSON format. */ - static final String SAMPLE_MESSAGE__TYPE = "SampleMessage"; + String SAMPLE_MESSAGE__TYPE = "SampleMessage"; @Override public test.oneoffield.data.SampleMessage registerListener(de.haumacher.msgbuf.observer.Listener l); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java index f66b85a6..bda2067c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage1.java @@ -77,7 +77,7 @@ static test.options.data.MyMessage1 create() { } /** Identifier for the {@link test.options.data.MyMessage1} type in JSON format. */ - static final String MY_MESSAGE_1__TYPE = "MyMessage1"; + String MY_MESSAGE_1__TYPE = "MyMessage1"; @Override public test.options.data.MyMessage1 registerListener(de.haumacher.msgbuf.observer.Listener l); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java index d44b1bda..f2ffcc9e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/MyMessage2.java @@ -73,7 +73,7 @@ static test.options.data.MyMessage2 create() { } /** Identifier for the {@link test.options.data.MyMessage2} type in JSON format. */ - static final String MY_MESSAGE_2__TYPE = "MyMessage2"; + String MY_MESSAGE_2__TYPE = "MyMessage2"; @Override public test.options.data.MyMessage2 registerListener(de.haumacher.msgbuf.observer.Listener l); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java index 0271b5e6..bfe02231 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/A.java @@ -10,34 +10,34 @@ static test.references.data.A create() { } /** Identifier for the {@link test.references.data.A} type in JSON format. */ - static final String A__TYPE = "A"; + String A__TYPE = "A"; /** @see #getName() */ - static final String NAME__PROP = "name"; + String NAME__PROP = "name"; /** @see #getContents() */ - static final String CONTENTS__PROP = "contents"; + String CONTENTS__PROP = "contents"; /** @see #getChildren() */ - static final String CHILDREN__PROP = "children"; + String CHILDREN__PROP = "children"; /** @see #getBs() */ - static final String BS__PROP = "bs"; + String BS__PROP = "bs"; /** @see #getB() */ - static final String B__PROP = "b"; + String B__PROP = "b"; /** @see #getOther() */ - static final String OTHER__PROP = "other"; + String OTHER__PROP = "other"; /** @see #getOthers() */ - static final String OTHERS__PROP = "others"; + String OTHERS__PROP = "others"; /** @see #getInOther() */ - static final String IN_OTHER__PROP = "inOther"; + String IN_OTHER__PROP = "inOther"; /** @see #getInOthers() */ - static final String IN_OTHERS__PROP = "inOthers"; + String IN_OTHERS__PROP = "inOthers"; /** Identifier for the property {@link #getName()} in binary format. */ static final int NAME__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java index 6dbd6eaf..5a63d904 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/B.java @@ -10,16 +10,16 @@ static test.references.data.B create() { } /** Identifier for the {@link test.references.data.B} type in JSON format. */ - static final String B__TYPE = "B"; + String B__TYPE = "B"; /** @see #getName() */ - static final String NAME__PROP = "name"; + String NAME__PROP = "name"; /** @see #getInBs() */ - static final String IN_BS__PROP = "inBs"; + String IN_BS__PROP = "inBs"; /** @see #getInB() */ - static final String IN_B__PROP = "inB"; + String IN_B__PROP = "inB"; /** Identifier for the property {@link #getName()} in binary format. */ static final int NAME__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java index 3bfa35c2..4c70a6b9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/SearchRequest.java @@ -10,16 +10,16 @@ static test.types.data.SearchRequest create() { } /** Identifier for the {@link test.types.data.SearchRequest} type in JSON format. */ - static final String SEARCH_REQUEST__TYPE = "SearchRequest"; + String SEARCH_REQUEST__TYPE = "SearchRequest"; /** @see #getQuery() */ - static final String QUERY__PROP = "query"; + String QUERY__PROP = "query"; /** @see #getPageNumber() */ - static final String PAGE_NUMBER__PROP = "page_number"; + String PAGE_NUMBER__PROP = "page_number"; /** @see #getResultPerPage() */ - static final String RESULT_PER_PAGE__PROP = "result_per_page"; + String RESULT_PER_PAGE__PROP = "result_per_page"; /** Identifier for the property {@link #getQuery()} in binary format. */ static final int QUERY__ID = 1; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java index 3eb49c32..0570e0b8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/AnnotatedMessage.java @@ -10,10 +10,10 @@ static test.underscorename.AnnotatedMessage create() { } /** Identifier for the {@link test.underscorename.AnnotatedMessage} type in JSON format. */ - static final String ANNOTATED_MESSAGE__TYPE = "m1"; + String ANNOTATED_MESSAGE__TYPE = "m1"; /** @see #getAnnotatedField() */ - static final String ANNOTATED_FIELD__PROP = "f1"; + String ANNOTATED_FIELD__PROP = "f1"; /** Identifier for the {@link test.underscorename.AnnotatedMessage} type in binary format. */ static final int ANNOTATED_MESSAGE__TYPE_ID = 2; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java index 70b97f05..864c378b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/SomeName.java @@ -10,10 +10,10 @@ static test.underscorename.SomeName create() { } /** Identifier for the {@link test.underscorename.SomeName} type in JSON format. */ - static final String SOME_NAME__TYPE = "some_name"; + String SOME_NAME__TYPE = "some_name"; /** @see #getMyField() */ - static final String MY_FIELD__PROP = "my_field"; + String MY_FIELD__PROP = "my_field"; /** Identifier for the {@link test.underscorename.SomeName} type in binary format. */ static final int SOME_NAME__TYPE_ID = 1; From b7c5612adbe87482c5269eb2f45f5b9417938811 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 4 Jan 2023 18:38:02 +0100 Subject: [PATCH 032/207] [maven-release-plugin] prepare release msgbuf-api-1.1.2 --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 11214beb..04e3e177 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.2-SNAPSHOT + 1.1.2 msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.2-SNAPSHOT + 1.1.2 diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 269cce31..47bdc168 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.2-SNAPSHOT + 1.1.2 msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 00584c22..171b739b 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.2-SNAPSHOT + 1.1.2 msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.2-SNAPSHOT + 1.1.2 diff --git a/pom.xml b/pom.xml index 2df26845..a9292913 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.2-SNAPSHOT + 1.1.2 pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - HEAD + msgbuf-api-1.1.2 From 28d9e77445fbbaa58c1a363deac8916427e70074 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 4 Jan 2023 18:38:30 +0100 Subject: [PATCH 033/207] [maven-release-plugin] prepare for next development iteration --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 04e3e177..050fae43 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.2 + 1.1.3-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.2 + 1.1.3-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 47bdc168..c9a7202e 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.2 + 1.1.3-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 171b739b..c32fd7be 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.2 + 1.1.3-SNAPSHOT msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.2 + 1.1.3-SNAPSHOT diff --git a/pom.xml b/pom.xml index a9292913..c148e494 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.2 + 1.1.3-SNAPSHOT pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - msgbuf-api-1.1.2 + HEAD From 705c8acdde32d6b9f0e54dc42db426bc90d182d0 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 4 Jan 2023 18:46:15 +0100 Subject: [PATCH 034/207] Updated version number on website, updated release howto. --- README.md | 4 ++-- de.haumacher.msgbuf/README.MD | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c094b3e6..b0795432 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ In contrast to `protobuf`, `msgbuf` supports: de.haumacher.msgbuf msgbuf-api - 1.1.1 + 1.1.2 ``` @@ -32,7 +32,7 @@ To the `build/plugins` section add: de.haumacher.msgbuf msgbuf-generator-maven-plugin - 1.1.1 + 1.1.2 diff --git a/de.haumacher.msgbuf/README.MD b/de.haumacher.msgbuf/README.MD index bec9783a..f117aad8 100644 --- a/de.haumacher.msgbuf/README.MD +++ b/de.haumacher.msgbuf/README.MD @@ -5,5 +5,6 @@ mvn release:clean release:prepare mvn release:perform cd target/checkout/de.haumacher.msgbuf mvn nexus-staging:release +mvn release:clean ``` From aa42b4d5e1ecf38f1587d56c24483b9bb9458ce6 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 3 Feb 2023 18:33:16 +0100 Subject: [PATCH 035/207] Fixed names of enumeration literals in Dart. --- .../msgbuf/generator/dart/DartCoding.java | 2 +- .../haumacher/msgbuf/generator/util/CodeUtil.java | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/dart/DartCoding.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/dart/DartCoding.java index 28e54017..dd9de697 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/dart/DartCoding.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/dart/DartCoding.java @@ -22,7 +22,7 @@ public class DartCoding { * Name of an enum literal. */ public static String literalName(Constant constant) { - return firstLowerCase(camelCase(constant.getName())); + return firstLowerCase(camelCase(underscored(constant.getName()))); } /** diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/util/CodeUtil.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/util/CodeUtil.java index 9c53975b..44d634c5 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/util/CodeUtil.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/util/CodeUtil.java @@ -18,7 +18,6 @@ public class CodeUtil { "(?<=\\p{javaDigit})(?=\\p{javaLetter})" + "|" + "_+"); - /** * Converts the given '_' separated string to CamelCase. */ @@ -30,6 +29,20 @@ public static String camelCase(String name) { return result.toString(); } + /** + * Converts a camel-case name to a name where parts are separated by '_'. + */ + public static String underscored(String name) { + StringBuilder result = new StringBuilder(); + for (String part : name.split("(?<=\\p{javaLowerCase})(?=\\p{javaUpperCase})")) { + if (result.length() > 0) { + result.append('_'); + } + result.append(part.toLowerCase()); + } + return result.toString(); + } + /** * Makes the first character upper-case in the given string. */ From 1743bd3991ba54ad45e506ff889ef14301238a42 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 3 Feb 2023 18:34:42 +0100 Subject: [PATCH 036/207] Fixed null-safety problem in Dart read operations. --- .../msgbuf/generator/dart/ReadOperationBuilder.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/dart/ReadOperationBuilder.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/dart/ReadOperationBuilder.java index b4d8ed1f..01ea4e73 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/dart/ReadOperationBuilder.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/dart/ReadOperationBuilder.java @@ -123,7 +123,12 @@ public Void visit(MessageDef self, Function statementBuilder) { } else { line("if (!json.tryNull()) {"); { - line(statementBuilder.apply(value)); + line("var value = " + value + ";"); + line("if (value != null) {"); + { + line(statementBuilder.apply("value")); + } + line("}"); } line("}"); } From e3257868e08416ea72e086b69c6ed168001b7520 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 3 Feb 2023 18:35:11 +0100 Subject: [PATCH 037/207] Added missing initailizations of super filed in Dart code. --- .../msgbuf/generator/dart/DartClassGenerator.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/dart/DartClassGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/dart/DartClassGenerator.java index 0979cdc9..a798b407 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/dart/DartClassGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/dart/DartClassGenerator.java @@ -5,6 +5,8 @@ import static de.haumacher.msgbuf.generator.dart.DartCoding.*; +import java.util.ArrayList; +import java.util.List; import java.util.stream.Collectors; import de.haumacher.msgbuf.generator.ast.Field; @@ -55,11 +57,21 @@ protected void generate() { nl(); } + List inheritedFields = new ArrayList<>(); + MessageDef superDef = _def.getExtendedDef(); + while (superDef != null) { + inheritedFields.addAll(superDef.getFields()); + superDef = superDef.getExtendedDef(); + } + line("/// Creates a " + typeName + "."); - if (_def.getFields().isEmpty()) { + if (_def.getFields().isEmpty() && inheritedFields.isEmpty()) { line(typeName + "();"); } else { line(typeName + "({"); + for (Field field : inheritedFields) { + line("super." + fieldName(field) + ", "); + } for (Field field : _def.getFields()) { line("this." + fieldName(field) + initializer(field) + ", "); } From 3e34e01e0a558b88312769e69f116a7baa65e334 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 3 Feb 2023 18:36:43 +0100 Subject: [PATCH 038/207] Cleanup: More convenience methods in Field AST type. --- .../msgbuf/generator/FieldOperations.java | 48 ++++++++++++++++++- .../msgbuf/generator/MessageGenerator.java | 10 +--- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java index 75d5de0e..80d8c793 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java @@ -5,6 +5,7 @@ import de.haumacher.msgbuf.generator.ast.Field; import de.haumacher.msgbuf.generator.ast.Option; +import de.haumacher.msgbuf.generator.ast.StringOption; /** * Mix-in interface for {@link Field} providing operations. @@ -21,7 +22,52 @@ public interface FieldOperations { /** Whether this field cannot be set by the application */ default boolean isDerived() { - return getOptions().get("Reverse") != null || getOptions().get("Container") != null; + return isReverse() || isContainer(); + } + + /** + * Whether this is a derived reference pointing to the owner of the object this referenec belongs to. + */ + default boolean isContainer() { + return getOptions().get("Container") != null; + } + + + /** + * Whether this is a reverse reference. + */ + default boolean isReverse() { + return getReverseAnnotation() != null; } + /** + * Whether this field is the reverse to the reference with the given name. + */ + default boolean isReverseOf(String name) { + return name.equals(getReverse()); + } + + /** + * The name of the inverse reference of this one. + * + * @return The name of the reverse reference to this one, or null if no such + * reference exists. + */ + default String getReverse() { + StringOption reverseOption = (StringOption) getReverseAnnotation(); + if (reverseOption == null) { + return null; + } + return reverseOption.getValue(); + } + + + /** + * The annotation marking this reference as "reverse". + */ + default Option getReverseAnnotation() { + return getOptions().get("Reverse"); + } + + } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 70e57ef8..9ac1e58a 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -1997,15 +1997,7 @@ private static Field getReverseField(MessageDef def, String name) { } static Field getLocalReverseField(MessageDef def, String name) { - return def.getFields().stream().filter(f -> hasReverseName(f, name)).findFirst().orElse(null); - } - - private static boolean hasReverseName(Field f, String name) { - StringOption reverseOption = (StringOption) f.getOptions().get("Reverse"); - if (reverseOption == null) { - return false; - } - return reverseOption.getValue().equals(name); + return def.getFields().stream().filter(f -> f.isReverseOf(name)).findFirst().orElse(null); } } From c8b28e07047b5b3b9795b2eb4d3f86f8e94ce0ae Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 3 Feb 2023 18:37:06 +0100 Subject: [PATCH 039/207] Cleanup: Removed unneccessary cast. --- .../msgbuf/generator/maven/TestGenerateMessageClasses.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msgbuf-generator-maven-plugin/src/test/java/de/haumacher/msgbuf/generator/maven/TestGenerateMessageClasses.java b/msgbuf-generator-maven-plugin/src/test/java/de/haumacher/msgbuf/generator/maven/TestGenerateMessageClasses.java index 79235b86..31812fda 100644 --- a/msgbuf-generator-maven-plugin/src/test/java/de/haumacher/msgbuf/generator/maven/TestGenerateMessageClasses.java +++ b/msgbuf-generator-maven-plugin/src/test/java/de/haumacher/msgbuf/generator/maven/TestGenerateMessageClasses.java @@ -31,7 +31,7 @@ public void testSomething() throws Exception { assertNotNull(generate); generate.execute(); - File outputDirectory = (File) generate.getOutputDirectory(); + File outputDirectory = generate.getOutputDirectory(); assertNotNull(outputDirectory); assertTrue(outputDirectory.exists()); From 9a97c5e99b87b98c98ffd547251906b268d2231f Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 3 Feb 2023 20:21:49 +0100 Subject: [PATCH 040/207] Generate code for @Container annotations in the case of single refs. --- .../msgbuf/generator/FieldOperations.java | 34 +- .../generator/MessageDefOperations.java | 32 ++ .../msgbuf/generator/MessageGenerator.java | 69 +++- .../haumacher/msgbuf/generator/ast/Field.java | 4 + .../msgbuf/generator/ast/MessageDef.java | 7 +- .../java/test/container/TestContainer.java | 62 +++ .../test/container/model/MyContainer.java | 91 +++++ .../java/test/container/model/MyContent.java | 65 ++++ .../java/test/container/model/container.proto | 17 + .../model/impl/MyContainer_Impl.java | 361 ++++++++++++++++++ .../container/model/impl/MyContent_Impl.java | 278 ++++++++++++++ .../test/references/data/impl/A_Impl.java | 26 +- .../test/references/data/impl/B_Impl.java | 6 + 13 files changed, 1031 insertions(+), 21 deletions(-) create mode 100644 de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageDefOperations.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContainer.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContent.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/container/model/container.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java index 80d8c793..9cc9580a 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java @@ -3,9 +3,13 @@ */ package de.haumacher.msgbuf.generator; +import de.haumacher.msgbuf.generator.ast.CustomType; +import de.haumacher.msgbuf.generator.ast.Definition; import de.haumacher.msgbuf.generator.ast.Field; +import de.haumacher.msgbuf.generator.ast.MessageDef; import de.haumacher.msgbuf.generator.ast.Option; import de.haumacher.msgbuf.generator.ast.StringOption; +import de.haumacher.msgbuf.generator.ast.Type; /** * Mix-in interface for {@link Field} providing operations. @@ -14,11 +18,10 @@ */ public interface FieldOperations { - /** - * Annotations to this definition. + /** + * The implementation. */ - java.util.Map getOptions(); - + Field self(); /** Whether this field cannot be set by the application */ default boolean isDerived() { @@ -29,7 +32,7 @@ default boolean isDerived() { * Whether this is a derived reference pointing to the owner of the object this referenec belongs to. */ default boolean isContainer() { - return getOptions().get("Container") != null; + return self().getOptions().get("Container") != null; } @@ -66,8 +69,27 @@ default String getReverse() { * The annotation marking this reference as "reverse". */ default Option getReverseAnnotation() { - return getOptions().get("Reverse"); + return self().getOptions().get("Reverse"); + } + + /** + * The {@link Field} in this field's type that is marked as {@link #isContainer() container}, or + * null if no such field exists. + */ + default Field container() { + if (!isDerived()) { + Type contentType = self().getType(); + if (contentType instanceof CustomType) { + Definition contentDef = ((CustomType) contentType).getDefinition(); + if (contentDef instanceof MessageDef) { + // Field is a composition reference. + return ((MessageDef) contentDef).container(); + } + } + } + return null; } + } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageDefOperations.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageDefOperations.java new file mode 100644 index 00000000..5096214a --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageDefOperations.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 Bernhard Haumacher et al. All Rights Reserved. + */ +package de.haumacher.msgbuf.generator; + +import de.haumacher.msgbuf.generator.ast.Field; +import de.haumacher.msgbuf.generator.ast.MessageDef; + +/** + * Mix-in interface for {@link MessageDef}. + * + * @author Bernhard Haumacher + */ +public interface MessageDefOperations { + + MessageDef self(); + + default Field container() { + Field local = self().getFields().stream().filter(Field::isContainer).findAny().orElse(null); + if (local != null) { + return local; + } + + MessageDef generalization = self().getExtendedDef(); + if (generalization == null) { + return null; + } + + return generalization.container(); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 9ac1e58a..a93985d1 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -606,8 +606,11 @@ private void accessorSetter(Field field, boolean override) { if (!override && _noInterfaces) { setterDoc(field); } else { + // Only in interface for non-derived fields, therefore no override necessary for derived fields. line("@Override"); } + } else { + docComment("Internal setter for updating derived field."); } line(setterModifier(field) + myType() + " " + setterName(field) + "(" + mkTypeReadOnly(field) + " " + "value" + ")" + " {"); { @@ -645,24 +648,64 @@ private void accessorSetterImpl(Field field) { Field reverseEnd = reverseEnd(field); boolean hasReverseEnd = reverseEnd != null; + Field container = field.container(); + + if (container != null || hasReverseEnd) { + line(mkTypeWrappedImpl(type) + " before = (" + mkTypeWrappedImpl(type) + ") " + fieldMemberName(field) +";"); + line(mkTypeWrappedImpl(type) + " after = (" + mkTypeWrappedImpl(type) + ") value;"); + } + + if (container != null) { + // Check early to not leave back inconsistent state upon error. + line("if (after != null) {"); + { + line(mkType(container) + " oldContainer = after." + getterName(container) + "();"); + line("if (oldContainer != null && oldContainer != this) {"); + { + line("throw new IllegalStateException(\"Object may not be part of two different containers.\");"); + } + line("}"); + } + line("}"); + } + if (_listener) { line("_listener.beforeSet(this, " + constant(field) + ", value);"); } - if (hasReverseEnd) { - line("if (" + fieldMemberName(field) + " != null) {"); + if (container != null || hasReverseEnd) { + line("if (before != null) {"); { - line("((" + mkTypeWrappedImpl(type) + ") " + fieldMemberName(field) + ")." + removerName(reverseEnd) + "(this);"); + if (container != null) { + line("before." + internalSetterName(container) + "(null);"); + } + + if (hasReverseEnd) { + line("before." + removerName(reverseEnd) + "(this);"); + } } line("}"); } + if (field.isContainer()) { + line("if (value != null && " + fieldMemberName(field) + " != null) {"); + { + line("throw new IllegalStateException(\"Object may not be part of two different containers.\");"); + } + line("}"); + } line(fieldMemberName(field) + " = " + "value" + ";"); - if (hasReverseEnd) { - line("if (value != null) {"); + if (container != null || hasReverseEnd) { + line("if (after != null) {"); { - line("((" + mkTypeWrappedImpl(type) + ") value)." + adderName(reverseEnd) + "(this);"); + if (hasReverseEnd) { + line("after." + adderName(reverseEnd) + "(this);"); + } + + if (container != null) { + line("after." + internalSetterName(container) + "(this);"); + } } line("}"); } @@ -671,6 +714,20 @@ private void accessorSetterImpl(Field field) { line("}"); } + private void setContainer(Field field) { + Field container = field.container(); + if (container != null) { + line("if (value == null) {"); + { + line(fieldMemberName(field) + "." + internalSetterName(container) + "(null);"); + } + line("} else {"); + { + line("value." + internalSetterName(container) + "(this);"); + } + } + } + private Field reverseEnd(Field field) { Type type = field.getType(); if (type instanceof CustomType) { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java index 1a57a7e6..2c1aee7d 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java @@ -221,4 +221,8 @@ public R visit(Part.Visitor v, A arg) { return v.visit(this, arg); } + @Override + public Field self() { + return this; + } } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java index 10ab7d37..8c659d36 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java @@ -3,7 +3,7 @@ /** * {@link Definition} of a data class. */ -public class MessageDef extends Definition { +public class MessageDef extends Definition implements de.haumacher.msgbuf.generator.MessageDefOperations { /** * Creates a {@link MessageDef} instance. @@ -468,4 +468,9 @@ public R visit(Definition.Visitor v, A arg) { return v.visit(this, arg); } + @Override + public MessageDef self() { + return this; + } + } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java new file mode 100644 index 00000000..bf02b4e6 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023 Bernhard Haumacher et al. All Rights Reserved. + */ +package test.container; + +import junit.framework.TestCase; +import test.container.model.MyContainer; +import test.container.model.MyContent; + +/** + * Test case for @Container annotations. + * + * @author Bernhard Haumacher + */ +@SuppressWarnings("javadoc") +public class TestContainer extends TestCase { + + public void testUpdateSingle() { + MyContainer container = MyContainer.create().setName("container"); + MyContainer otherContainer = MyContainer.create().setName("other"); + + MyContent c1 = MyContent.create().setName("content 1"); + + container.setContent1(c1); + assertEquals(container, c1.getContainer()); + + MyContent c2 = MyContent.create().setName("content 2"); + container.setContent1(c2); + assertNull(c1.getContainer()); + assertEquals(container, c2.getContainer()); + + container.setContent2(c1); + assertEquals(container, c1.getContainer()); + assertEquals(container, c2.getContainer()); + + try { + otherContainer.setContent1(c1); + fail("Must not make object part of two different containers."); + } catch (IllegalStateException ex) { + assertEquals("Object may not be part of two different containers.", ex.getMessage()); + } + + // Check that nothing has changed. + assertNull(otherContainer.getContent1()); + assertEquals(container, c1.getContainer()); + assertEquals(container, c2.getContainer()); + } + + public void testUpdateIdentical() { + MyContent c = MyContent.create().setName("c"); + MyContainer container = MyContainer.create().setContent1(c); + + assertEquals(container, c.getContainer()); + assertEquals(c, container.getContent1()); + + container.setContent1(c); + + assertEquals(container, c.getContainer()); + assertEquals(c, container.getContent1()); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContainer.java new file mode 100644 index 00000000..8bed8e93 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContainer.java @@ -0,0 +1,91 @@ +package test.container.model; + +public interface MyContainer extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.container.model.MyContainer} instance. + */ + static test.container.model.MyContainer create() { + return new test.container.model.impl.MyContainer_Impl(); + } + + /** Identifier for the {@link test.container.model.MyContainer} type in JSON format. */ + String MY_CONTAINER__TYPE = "MyContainer"; + + /** @see #getName() */ + String NAME__PROP = "name"; + + /** @see #getContent1() */ + String CONTENT_1__PROP = "content1"; + + /** @see #getContent2() */ + String CONTENT_2__PROP = "content2"; + + /** Identifier for the property {@link #getName()} in binary format. */ + static final int NAME__ID = 1; + + /** Identifier for the property {@link #getContent1()} in binary format. */ + static final int CONTENT_1__ID = 2; + + /** Identifier for the property {@link #getContent2()} in binary format. */ + static final int CONTENT_2__ID = 3; + + String getName(); + + /** + * @see #getName() + */ + test.container.model.MyContainer setName(String value); + + test.container.model.MyContent getContent1(); + + /** + * @see #getContent1() + */ + test.container.model.MyContainer setContent1(test.container.model.MyContent value); + + /** + * Checks, whether {@link #getContent1()} has a value. + */ + boolean hasContent1(); + + test.container.model.MyContent getContent2(); + + /** + * @see #getContent2() + */ + test.container.model.MyContainer setContent2(test.container.model.MyContent value); + + /** + * Checks, whether {@link #getContent2()} has a value. + */ + boolean hasContent2(); + + @Override + public test.container.model.MyContainer registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.container.model.MyContainer unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.container.model.MyContainer readMyContainer(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.container.model.impl.MyContainer_Impl result = new test.container.model.impl.MyContainer_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.container.model.MyContainer readMyContainer(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.container.model.MyContainer result = test.container.model.impl.MyContainer_Impl.readMyContainer_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link MyContainer} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static MyContainer readMyContainer(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.container.model.impl.MyContainer_Impl.readMyContainer_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContent.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContent.java new file mode 100644 index 00000000..f7e46170 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContent.java @@ -0,0 +1,65 @@ +package test.container.model; + +public interface MyContent extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.container.model.MyContent} instance. + */ + static test.container.model.MyContent create() { + return new test.container.model.impl.MyContent_Impl(); + } + + /** Identifier for the {@link test.container.model.MyContent} type in JSON format. */ + String MY_CONTENT__TYPE = "MyContent"; + + /** @see #getContainer() */ + String CONTAINER__PROP = "container"; + + /** @see #getName() */ + String NAME__PROP = "name"; + + /** Identifier for the property {@link #getName()} in binary format. */ + static final int NAME__ID = 2; + + test.container.model.MyContainer getContainer(); + + /** + * Checks, whether {@link #getContainer()} has a value. + */ + boolean hasContainer(); + + String getName(); + + /** + * @see #getName() + */ + test.container.model.MyContent setName(String value); + + @Override + public test.container.model.MyContent registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.container.model.MyContent unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.container.model.MyContent readMyContent(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.container.model.impl.MyContent_Impl result = new test.container.model.impl.MyContent_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.container.model.MyContent readMyContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.container.model.MyContent result = test.container.model.impl.MyContent_Impl.readMyContent_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link MyContent} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static MyContent readMyContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.container.model.impl.MyContent_Impl.readMyContent_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/container.proto b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/container.proto new file mode 100644 index 00000000..98c856c0 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/container.proto @@ -0,0 +1,17 @@ +package test.container.model; + +message MyContainer { + string name; + + MyContent content1; + MyContent content2; +} + +message MyContent { + + @Container + MyContainer container; + + string name; + +} \ No newline at end of file diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java new file mode 100644 index 00000000..6ad02861 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java @@ -0,0 +1,361 @@ +package test.container.model.impl; + +public class MyContainer_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.container.model.MyContainer { + + private String _name = ""; + + private test.container.model.MyContent _content1 = null; + + private test.container.model.MyContent _content2 = null; + + /** + * Creates a {@link MyContainer_Impl} instance. + * + * @see test.container.model.MyContainer#create() + */ + public MyContainer_Impl() { + super(); + } + + @Override + public final String getName() { + return _name; + } + + @Override + public test.container.model.MyContainer setName(String value) { + internalSetName(value); + return this; + } + + /** Internal setter for {@link #getName()} without chain call utility. */ + protected final void internalSetName(String value) { + _listener.beforeSet(this, NAME__PROP, value); + _name = value; + } + + @Override + public final test.container.model.MyContent getContent1() { + return _content1; + } + + @Override + public test.container.model.MyContainer setContent1(test.container.model.MyContent value) { + internalSetContent1(value); + return this; + } + + /** Internal setter for {@link #getContent1()} without chain call utility. */ + protected final void internalSetContent1(test.container.model.MyContent value) { + test.container.model.impl.MyContent_Impl before = (test.container.model.impl.MyContent_Impl) _content1; + test.container.model.impl.MyContent_Impl after = (test.container.model.impl.MyContent_Impl) value; + if (after != null) { + test.container.model.MyContainer oldContainer = after.getContainer(); + if (oldContainer != null && oldContainer != this) { + throw new IllegalStateException("Object may not be part of two different containers."); + } + } + _listener.beforeSet(this, CONTENT_1__PROP, value); + if (before != null) { + before.internalSetContainer(null); + } + _content1 = value; + if (after != null) { + after.internalSetContainer(this); + } + } + + @Override + public final boolean hasContent1() { + return _content1 != null; + } + + @Override + public final test.container.model.MyContent getContent2() { + return _content2; + } + + @Override + public test.container.model.MyContainer setContent2(test.container.model.MyContent value) { + internalSetContent2(value); + return this; + } + + /** Internal setter for {@link #getContent2()} without chain call utility. */ + protected final void internalSetContent2(test.container.model.MyContent value) { + test.container.model.impl.MyContent_Impl before = (test.container.model.impl.MyContent_Impl) _content2; + test.container.model.impl.MyContent_Impl after = (test.container.model.impl.MyContent_Impl) value; + if (after != null) { + test.container.model.MyContainer oldContainer = after.getContainer(); + if (oldContainer != null && oldContainer != this) { + throw new IllegalStateException("Object may not be part of two different containers."); + } + } + _listener.beforeSet(this, CONTENT_2__PROP, value); + if (before != null) { + before.internalSetContainer(null); + } + _content2 = value; + if (after != null) { + after.internalSetContainer(this); + } + } + + @Override + public final boolean hasContent2() { + return _content2 != null; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.container.model.MyContainer registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.container.model.MyContainer unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return MY_CONTAINER__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + NAME__PROP, + CONTENT_1__PROP, + CONTENT_2__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NAME__PROP: return getName(); + case CONTENT_1__PROP: return getContent1(); + case CONTENT_2__PROP: return getContent2(); + default: return test.container.model.MyContainer.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NAME__PROP: internalSetName((String) value); break; + case CONTENT_1__PROP: internalSetContent1((test.container.model.MyContent) value); break; + case CONTENT_2__PROP: internalSetContent2((test.container.model.MyContent) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NAME__PROP); + out.value(getName()); + if (hasContent1()) { + out.name(CONTENT_1__PROP); + getContent1().writeTo(out); + } + if (hasContent2()) { + out.name(CONTENT_2__PROP); + getContent2().writeTo(out); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case CONTENT_1__PROP: setContent1(test.container.model.MyContent.readMyContent(in)); break; + case CONTENT_2__PROP: setContent2(test.container.model.MyContent.readMyContent(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(NAME__ID); + out.value(getName()); + if (hasContent1()) { + out.name(CONTENT_1__ID); + getContent1().writeTo(out); + } + if (hasContent2()) { + out.name(CONTENT_2__ID); + getContent2().writeTo(out); + } + } + + /** Helper for creating an object of type {@link test.container.model.MyContainer} from a polymorphic composition. */ + public static test.container.model.MyContainer readMyContainer_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.container.model.impl.MyContainer_Impl result = new MyContainer_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case NAME__ID: setName(in.nextString()); break; + case CONTENT_1__ID: setContent1(test.container.model.MyContent.readMyContent(in)); break; + case CONTENT_2__ID: setContent2(test.container.model.MyContent.readMyContent(in)); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.container.model.MyContainer} type. */ + public static final String MY_CONTAINER__XML_ELEMENT = "my-container"; + + /** XML attribute or element name of a {@link #getName} property. */ + private static final String NAME__XML_ATTR = "name"; + + /** XML attribute or element name of a {@link #getContent1} property. */ + private static final String CONTENT_1__XML_ATTR = "content-1"; + + /** XML attribute or element name of a {@link #getContent2} property. */ + private static final String CONTENT_2__XML_ATTR = "content-2"; + + @Override + public String getXmlTagName() { + return MY_CONTAINER__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasContent1()) { + out.writeStartElement(CONTENT_1__XML_ATTR); + getContent1().writeContent(out); + out.writeEndElement(); + } + if (hasContent2()) { + out.writeStartElement(CONTENT_2__XML_ATTR); + getContent2().writeContent(out); + out.writeEndElement(); + } + } + + /** Creates a new {@link test.container.model.MyContainer} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static MyContainer_Impl readMyContainer_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + MyContainer_Impl result = new MyContainer_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NAME__XML_ATTR: { + setName(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NAME__XML_ATTR: { + setName(in.getElementText()); + break; + } + case CONTENT_1__XML_ATTR: { + setContent1(test.container.model.impl.MyContent_Impl.readMyContent_XmlContent(in)); + break; + } + case CONTENT_2__XML_ATTR: { + setContent2(test.container.model.impl.MyContent_Impl.readMyContent_XmlContent(in)); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java new file mode 100644 index 00000000..327a6720 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java @@ -0,0 +1,278 @@ +package test.container.model.impl; + +public class MyContent_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.container.model.MyContent { + + private test.container.model.MyContainer _container = null; + + private String _name = ""; + + /** + * Creates a {@link MyContent_Impl} instance. + * + * @see test.container.model.MyContent#create() + */ + public MyContent_Impl() { + super(); + } + + @Override + public final test.container.model.MyContainer getContainer() { + return _container; + } + + /** + * Internal setter for updating derived field. + */ + test.container.model.MyContent setContainer(test.container.model.MyContainer value) { + internalSetContainer(value); + return this; + } + + /** Internal setter for {@link #getContainer()} without chain call utility. */ + protected final void internalSetContainer(test.container.model.MyContainer value) { + _listener.beforeSet(this, CONTAINER__PROP, value); + if (value != null && _container != null) { + throw new IllegalStateException("Object may not be part of two different containers."); + } + _container = value; + } + + @Override + public final boolean hasContainer() { + return _container != null; + } + + @Override + public final String getName() { + return _name; + } + + @Override + public test.container.model.MyContent setName(String value) { + internalSetName(value); + return this; + } + + /** Internal setter for {@link #getName()} without chain call utility. */ + protected final void internalSetName(String value) { + _listener.beforeSet(this, NAME__PROP, value); + _name = value; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.container.model.MyContent registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.container.model.MyContent unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return MY_CONTENT__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + CONTAINER__PROP, + NAME__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case CONTAINER__PROP: return getContainer(); + case NAME__PROP: return getName(); + default: return test.container.model.MyContent.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NAME__PROP: internalSetName((String) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NAME__PROP); + out.value(getName()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(NAME__ID); + out.value(getName()); + } + + /** Helper for creating an object of type {@link test.container.model.MyContent} from a polymorphic composition. */ + public static test.container.model.MyContent readMyContent_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.container.model.impl.MyContent_Impl result = new MyContent_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case NAME__ID: setName(in.nextString()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.container.model.MyContent} type. */ + public static final String MY_CONTENT__XML_ELEMENT = "my-content"; + + /** XML attribute or element name of a {@link #getContainer} property. */ + private static final String CONTAINER__XML_ATTR = "container"; + + /** XML attribute or element name of a {@link #getName} property. */ + private static final String NAME__XML_ATTR = "name"; + + @Override + public String getXmlTagName() { + return MY_CONTENT__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasContainer()) { + out.writeStartElement(CONTAINER__XML_ATTR); + getContainer().writeContent(out); + out.writeEndElement(); + } + } + + /** Creates a new {@link test.container.model.MyContent} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static MyContent_Impl readMyContent_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + MyContent_Impl result = new MyContent_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NAME__XML_ATTR: { + setName(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case CONTAINER__XML_ATTR: { + setContainer(test.container.model.impl.MyContainer_Impl.readMyContainer_XmlContent(in)); + break; + } + case NAME__XML_ATTR: { + setName(in.getElementText()); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java index 3b711273..323ade69 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java @@ -203,13 +203,15 @@ public test.references.data.A setB(test.references.data.B value) { /** Internal setter for {@link #getB()} without chain call utility. */ protected final void internalSetB(test.references.data.B value) { + test.references.data.impl.B_Impl before = (test.references.data.impl.B_Impl) _b; + test.references.data.impl.B_Impl after = (test.references.data.impl.B_Impl) value; _listener.beforeSet(this, B__PROP, value); - if (_b != null) { - ((test.references.data.impl.B_Impl) _b).removeInB(this); + if (before != null) { + before.removeInB(this); } _b = value; - if (value != null) { - ((test.references.data.impl.B_Impl) value).addInB(this); + if (after != null) { + after.addInB(this); } } @@ -231,13 +233,15 @@ public test.references.data.A setOther(test.references.data.A value) { /** Internal setter for {@link #getOther()} without chain call utility. */ protected final void internalSetOther(test.references.data.A value) { + test.references.data.impl.A_Impl before = (test.references.data.impl.A_Impl) _other; + test.references.data.impl.A_Impl after = (test.references.data.impl.A_Impl) value; _listener.beforeSet(this, OTHER__PROP, value); - if (_other != null) { - ((test.references.data.impl.A_Impl) _other).removeInOther(this); + if (before != null) { + before.removeInOther(this); } _other = value; - if (value != null) { - ((test.references.data.impl.A_Impl) value).addInOther(this); + if (after != null) { + after.addInOther(this); } } @@ -285,6 +289,9 @@ public final java.util.List getInOther() { return _inOther; } + /** + * Internal setter for updating derived field. + */ test.references.data.A setInOther(java.util.List value) { internalSetInOther(value); return this; @@ -316,6 +323,9 @@ public final java.util.List getInOthers() { return _inOthers; } + /** + * Internal setter for updating derived field. + */ test.references.data.A setInOthers(java.util.List value) { internalSetInOthers(value); return this; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java index b31e5a1e..3af83984 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java @@ -59,6 +59,9 @@ public final java.util.List getInBs() { return _inBs; } + /** + * Internal setter for updating derived field. + */ test.references.data.B setInBs(java.util.List value) { internalSetInBs(value); return this; @@ -90,6 +93,9 @@ public final java.util.List getInB() { return _inB; } + /** + * Internal setter for updating derived field. + */ test.references.data.B setInB(java.util.List value) { internalSetInB(value); return this; From 725f5577cbe7911ba866e60a9b663052821bb980 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 3 Feb 2023 20:49:15 +0100 Subject: [PATCH 041/207] Implemented container handling for reference lists. --- .../msgbuf/generator/MessageGenerator.java | 69 ++++--- .../java/test/container/TestContainer.java | 55 +++++ .../test/container/model/MyContainer.java | 46 +++++ .../java/test/container/model/container.proto | 3 + .../model/impl/MyContainer_Impl.java | 193 +++++++++++++++++- .../test/references/data/impl/A_Impl.java | 12 +- 6 files changed, 349 insertions(+), 29 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index a93985d1..581f3a20 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -470,18 +470,42 @@ private void generateFieldMembers() { if (field.isRepeated()) { Field reverseEnd = reverseEnd(field); boolean hasReverseEnd = reverseEnd != null; - if (_listener || hasReverseEnd) { - String qFieldTypeName = mkTypeWrapped(field.getType()); + + Field container = field.container(); + boolean hasContainer = container != null; + + if (_listener || hasReverseEnd || container != null) { + Type type = field.getType(); + String qFieldTypeName = mkTypeWrapped(type); line("private" + mkTransient(field) + mkFinal(field) + " " + mkType(field) + " " + fieldMemberName(field) + " = " + "new de.haumacher.msgbuf.util.ReferenceList<" + qFieldTypeName + ">() {"); { line("@Override"); line("protected void beforeAdd(int index, " + qFieldTypeName + " element) {"); { + if (hasContainer || hasReverseEnd) { + line(mkTypeWrappedImpl(type) + " added = (" + mkTypeWrappedImpl(type) + ") element;"); + } + + if (hasContainer) { + // Check early to not leave back inconsistent state upon error. + line(mkType(container) + " oldContainer = added." + getterName(container) + "();"); + line("if (oldContainer != null && oldContainer != this) {"); + { + line("throw new IllegalStateException(\"Object may not be part of two different containers.\");"); + } + line("}"); + } + if (_listener) { line("_listener.beforeAdd(" + implName(_def) + ".this, " + constant(field) + ", index, element);"); } + + if (hasContainer) { + line("added." + internalSetterName(container) + "(" + implName(_def) + ".this);"); + } + if (hasReverseEnd) { - line("((" + mkTypeWrappedImpl(field.getType()) + ") element)." + adderName(reverseEnd) + "(" + implName(_def) + ".this);"); + line("added." + adderName(reverseEnd) + "(" + implName(_def) + ".this);"); } } line("}"); @@ -490,9 +514,18 @@ private void generateFieldMembers() { line("@Override"); line("protected void afterRemove(int index, " + qFieldTypeName + " element) {"); { + if (hasContainer || hasReverseEnd) { + line(mkTypeWrappedImpl(type) + " removed = (" + mkTypeWrappedImpl(type) + ") element;"); + } + if (hasReverseEnd) { - line("((" + mkTypeWrappedImpl(field.getType()) + ") element)." + removerName(reverseEnd) + "(" + implName(_def) + ".this);"); + line("removed." + removerName(reverseEnd) + "(" + implName(_def) + ".this);"); + } + + if (hasContainer) { + line("removed." + internalSetterName(container) + "(null);"); } + if (_listener) { line("_listener.afterRemove(" + implName(_def) + ".this, " + constant(field) + ", index, element);"); } @@ -649,13 +682,14 @@ private void accessorSetterImpl(Field field) { boolean hasReverseEnd = reverseEnd != null; Field container = field.container(); + boolean hasContainer = container != null; - if (container != null || hasReverseEnd) { + if (hasContainer || hasReverseEnd) { line(mkTypeWrappedImpl(type) + " before = (" + mkTypeWrappedImpl(type) + ") " + fieldMemberName(field) +";"); line(mkTypeWrappedImpl(type) + " after = (" + mkTypeWrappedImpl(type) + ") value;"); } - if (container != null) { + if (hasContainer) { // Check early to not leave back inconsistent state upon error. line("if (after != null) {"); { @@ -673,10 +707,10 @@ private void accessorSetterImpl(Field field) { line("_listener.beforeSet(this, " + constant(field) + ", value);"); } - if (container != null || hasReverseEnd) { + if (hasContainer || hasReverseEnd) { line("if (before != null) {"); { - if (container != null) { + if (hasContainer) { line("before." + internalSetterName(container) + "(null);"); } @@ -694,16 +728,17 @@ private void accessorSetterImpl(Field field) { } line("}"); } + line(fieldMemberName(field) + " = " + "value" + ";"); - if (container != null || hasReverseEnd) { + if (hasContainer || hasReverseEnd) { line("if (after != null) {"); { if (hasReverseEnd) { line("after." + adderName(reverseEnd) + "(this);"); } - if (container != null) { + if (hasContainer) { line("after." + internalSetterName(container) + "(this);"); } } @@ -714,20 +749,6 @@ private void accessorSetterImpl(Field field) { line("}"); } - private void setContainer(Field field) { - Field container = field.container(); - if (container != null) { - line("if (value == null) {"); - { - line(fieldMemberName(field) + "." + internalSetterName(container) + "(null);"); - } - line("} else {"); - { - line("value." + internalSetterName(container) + "(this);"); - } - } - } - private Field reverseEnd(Field field) { Type type = field.getType(); if (type instanceof CustomType) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java index bf02b4e6..6cdd099e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java @@ -3,6 +3,8 @@ */ package test.container; +import java.util.Arrays; + import junit.framework.TestCase; import test.container.model.MyContainer; import test.container.model.MyContent; @@ -46,6 +48,59 @@ public void testUpdateSingle() { assertEquals(container, c2.getContainer()); } + public void testUpdateMulti() { + MyContainer container = MyContainer.create().setName("container"); + MyContainer otherContainer = MyContainer.create().setName("other"); + + MyContent c1 = MyContent.create().setName("content 1"); + + container.addContentList(c1); + assertEquals(container, c1.getContainer()); + + MyContent c2 = MyContent.create().setName("content 2"); + container.addContentList(c2); + assertEquals(container, c1.getContainer()); + assertEquals(container, c2.getContainer()); + + container.setContentList(Arrays.asList(c1)); + assertEquals(container, c1.getContainer()); + assertNull(c2.getContainer()); + + container.removeContentList(c1); + assertNull(c1.getContainer()); + + container.setContentList(Arrays.asList(c1, c2)); + assertEquals(container, c1.getContainer()); + assertEquals(container, c2.getContainer()); + + container.getContentList().clear(); + assertNull(c1.getContainer()); + assertNull(c2.getContainer()); + + container.addContentList(c1); + try { + container.addContentList(c1); + fail("Must not make object part of two different containers."); + } catch (IllegalStateException ex) { + assertEquals("Object may not be part of two different containers.", ex.getMessage()); + } + + // Check that nothing has changed. + assertEquals(container, c1.getContainer()); + assertEquals(Arrays.asList(c1), container.getContentList()); + + try { + otherContainer.addContentList(c1); + fail("Must not make object part of two different containers."); + } catch (IllegalStateException ex) { + assertEquals("Object may not be part of two different containers.", ex.getMessage()); + } + + assertEquals(container, c1.getContainer()); + assertEquals(Arrays.asList(c1), container.getContentList()); + assertEquals(0, otherContainer.getContentList().size()); + } + public void testUpdateIdentical() { MyContent c = MyContent.create().setName("c"); MyContainer container = MyContainer.create().setContent1(c); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContainer.java index 8bed8e93..d08efca4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContainer.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContainer.java @@ -21,6 +21,12 @@ static test.container.model.MyContainer create() { /** @see #getContent2() */ String CONTENT_2__PROP = "content2"; + /** @see #getContentList() */ + String CONTENT_LIST__PROP = "contentList"; + + /** @see #getContentMap() */ + String CONTENT_MAP__PROP = "contentMap"; + /** Identifier for the property {@link #getName()} in binary format. */ static final int NAME__ID = 1; @@ -30,6 +36,12 @@ static test.container.model.MyContainer create() { /** Identifier for the property {@link #getContent2()} in binary format. */ static final int CONTENT_2__ID = 3; + /** Identifier for the property {@link #getContentList()} in binary format. */ + static final int CONTENT_LIST__ID = 4; + + /** Identifier for the property {@link #getContentMap()} in binary format. */ + static final int CONTENT_MAP__ID = 5; + String getName(); /** @@ -61,6 +73,40 @@ static test.container.model.MyContainer create() { */ boolean hasContent2(); + java.util.List getContentList(); + + /** + * @see #getContentList() + */ + test.container.model.MyContainer setContentList(java.util.List value); + + /** + * Adds a value to the {@link #getContentList()} list. + */ + test.container.model.MyContainer addContentList(test.container.model.MyContent value); + + /** + * Removes a value from the {@link #getContentList()} list. + */ + void removeContentList(test.container.model.MyContent value); + + java.util.Map getContentMap(); + + /** + * @see #getContentMap() + */ + test.container.model.MyContainer setContentMap(java.util.Map value); + + /** + * Adds a key value pair to the {@link #getContentMap()} map. + */ + test.container.model.MyContainer putContentMap(String key, test.container.model.MyContent value); + + /** + * Removes a key from the {@link #getContentMap()} map. + */ + void removeContentMap(String key); + @Override public test.container.model.MyContainer registerListener(de.haumacher.msgbuf.observer.Listener l); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/container.proto b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/container.proto index 98c856c0..bace4cee 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/container.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/container.proto @@ -5,6 +5,9 @@ message MyContainer { MyContent content1; MyContent content2; + + repeated MyContent contentList; + map contentMap; } message MyContent { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java index 6ad02861..3b5be407 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java @@ -8,6 +8,28 @@ public class MyContainer_Impl extends de.haumacher.msgbuf.data.AbstractDataObjec private test.container.model.MyContent _content2 = null; + private final java.util.List _contentList = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.container.model.MyContent element) { + test.container.model.impl.MyContent_Impl added = (test.container.model.impl.MyContent_Impl) element; + test.container.model.MyContainer oldContainer = added.getContainer(); + if (oldContainer != null && oldContainer != this) { + throw new IllegalStateException("Object may not be part of two different containers."); + } + _listener.beforeAdd(MyContainer_Impl.this, CONTENT_LIST__PROP, index, element); + added.internalSetContainer(MyContainer_Impl.this); + } + + @Override + protected void afterRemove(int index, test.container.model.MyContent element) { + test.container.model.impl.MyContent_Impl removed = (test.container.model.impl.MyContent_Impl) element; + removed.internalSetContainer(null); + _listener.afterRemove(MyContainer_Impl.this, CONTENT_LIST__PROP, index, element); + } + }; + + private final java.util.Map _contentMap = new java.util.HashMap<>(); + /** * Creates a {@link MyContainer_Impl} instance. * @@ -106,6 +128,77 @@ public final boolean hasContent2() { return _content2 != null; } + @Override + public final java.util.List getContentList() { + return _contentList; + } + + @Override + public test.container.model.MyContainer setContentList(java.util.List value) { + internalSetContentList(value); + return this; + } + + /** Internal setter for {@link #getContentList()} without chain call utility. */ + protected final void internalSetContentList(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'contentList' cannot be null."); + _contentList.clear(); + _contentList.addAll(value); + } + + @Override + public test.container.model.MyContainer addContentList(test.container.model.MyContent value) { + internalAddContentList(value); + return this; + } + + /** Implementation of {@link #addContentList(test.container.model.MyContent)} without chain call utility. */ + protected final void internalAddContentList(test.container.model.MyContent value) { + _contentList.add(value); + } + + @Override + public final void removeContentList(test.container.model.MyContent value) { + _contentList.remove(value); + } + + @Override + public final java.util.Map getContentMap() { + return _contentMap; + } + + @Override + public test.container.model.MyContainer setContentMap(java.util.Map value) { + internalSetContentMap(value); + return this; + } + + /** Internal setter for {@link #getContentMap()} without chain call utility. */ + protected final void internalSetContentMap(java.util.Map value) { + if (value == null) throw new IllegalArgumentException("Property 'contentMap' cannot be null."); + _contentMap.clear(); + _contentMap.putAll(value); + } + + @Override + public test.container.model.MyContainer putContentMap(String key, test.container.model.MyContent value) { + internalPutContentMap(key, value); + return this; + } + + /** Implementation of {@link #putContentMap(String, test.container.model.MyContent)} without chain call utility. */ + protected final void internalPutContentMap(String key, test.container.model.MyContent value) { + if (_contentMap.containsKey(key)) { + throw new IllegalArgumentException("Property 'contentMap' already contains a value for key '" + key + "'."); + } + _contentMap.put(key, value); + } + + @Override + public final void removeContentMap(String key) { + _contentMap.remove(key); + } + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override @@ -137,7 +230,9 @@ public String jsonType() { java.util.Arrays.asList( NAME__PROP, CONTENT_1__PROP, - CONTENT_2__PROP)); + CONTENT_2__PROP, + CONTENT_LIST__PROP, + CONTENT_MAP__PROP)); @Override public java.util.List properties() { @@ -150,6 +245,8 @@ public Object get(String field) { case NAME__PROP: return getName(); case CONTENT_1__PROP: return getContent1(); case CONTENT_2__PROP: return getContent2(); + case CONTENT_LIST__PROP: return getContentList(); + case CONTENT_MAP__PROP: return getContentMap(); default: return test.container.model.MyContainer.super.get(field); } } @@ -160,6 +257,8 @@ public void set(String field, Object value) { case NAME__PROP: internalSetName((String) value); break; case CONTENT_1__PROP: internalSetContent1((test.container.model.MyContent) value); break; case CONTENT_2__PROP: internalSetContent2((test.container.model.MyContent) value); break; + case CONTENT_LIST__PROP: internalSetContentList(de.haumacher.msgbuf.util.Conversions.asList(test.container.model.MyContent.class, value)); break; + case CONTENT_MAP__PROP: internalSetContentMap((java.util.Map) value); break; } } @@ -181,6 +280,19 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. out.name(CONTENT_2__PROP); getContent2().writeTo(out); } + out.name(CONTENT_LIST__PROP); + out.beginArray(); + for (test.container.model.MyContent x : getContentList()) { + x.writeTo(out); + } + out.endArray(); + out.name(CONTENT_MAP__PROP); + out.beginObject(); + for (java.util.Map.Entry entry : getContentMap().entrySet()) { + out.name(entry.getKey()); + entry.getValue().writeTo(out); + } + out.endObject(); } @Override @@ -189,6 +301,22 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; case CONTENT_1__PROP: setContent1(test.container.model.MyContent.readMyContent(in)); break; case CONTENT_2__PROP: setContent2(test.container.model.MyContent.readMyContent(in)); break; + case CONTENT_LIST__PROP: { + in.beginArray(); + while (in.hasNext()) { + addContentList(test.container.model.MyContent.readMyContent(in)); + } + in.endArray(); + } + break; + case CONTENT_MAP__PROP: { + in.beginObject(); + while (in.hasNext()) { + putContentMap(in.nextName(), test.container.model.MyContent.readMyContent(in)); + } + in.endObject(); + break; + } default: super.readField(in, field); } } @@ -218,6 +346,16 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.name(CONTENT_2__ID); getContent2().writeTo(out); } + out.name(CONTENT_LIST__ID); + { + java.util.List values = getContentList(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.container.model.MyContent x : values) { + x.writeTo(out); + } + out.endArray(); + } + out.name(CONTENT_MAP__ID); } /** Helper for creating an object of type {@link test.container.model.MyContainer} from a polymorphic composition. */ @@ -241,6 +379,33 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th case NAME__ID: setName(in.nextString()); break; case CONTENT_1__ID: setContent1(test.container.model.MyContent.readMyContent(in)); break; case CONTENT_2__ID: setContent2(test.container.model.MyContent.readMyContent(in)); break; + case CONTENT_LIST__ID: { + in.beginArray(); + while (in.hasNext()) { + addContentList(test.container.model.MyContent.readMyContent(in)); + } + in.endArray(); + } + break; + case CONTENT_MAP__ID: { + in.beginArray(); + while (in.hasNext()) { + in.beginObject(); + String key = ""; + test.container.model.MyContent value = null; + while (in.hasNext()) { + switch (in.nextName()) { + case 1: key = in.nextString(); break; + case 2: value = test.container.model.MyContent.readMyContent(in); break; + default: in.skipValue(); break; + } + } + putContentMap(key, value); + in.endObject(); + } + in.endArray(); + break; + } default: in.skipValue(); } } @@ -257,6 +422,12 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getContent2} property. */ private static final String CONTENT_2__XML_ATTR = "content-2"; + /** XML attribute or element name of a {@link #getContentList} property. */ + private static final String CONTENT_LIST__XML_ATTR = "content-list"; + + /** XML attribute or element name of a {@link #getContentMap} property. */ + private static final String CONTENT_MAP__XML_ATTR = "content-map"; + @Override public String getXmlTagName() { return MY_CONTAINER__XML_ELEMENT; @@ -285,6 +456,11 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. getContent2().writeContent(out); out.writeEndElement(); } + out.writeStartElement(CONTENT_LIST__XML_ATTR); + for (test.container.model.MyContent element : getContentList()) { + element.writeTo(out); + } + out.writeEndElement(); } /** Creates a new {@link test.container.model.MyContainer} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ @@ -342,6 +518,10 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l setContent2(test.container.model.impl.MyContent_Impl.readMyContent_XmlContent(in)); break; } + case CONTENT_LIST__XML_ATTR: { + internalReadContentListListXml(in); + break; + } default: { internalSkipUntilMatchingEndElement(in); } @@ -358,4 +538,15 @@ protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream } } + private void internalReadContentListListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addContentList(test.container.model.impl.MyContent_Impl.readMyContent_XmlContent(in)); + } + } + } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java index 323ade69..01323b2a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java @@ -21,13 +21,15 @@ protected void afterRemove(int index, test.references.data.A element) { private final java.util.List _bs = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.references.data.B element) { + test.references.data.impl.B_Impl added = (test.references.data.impl.B_Impl) element; _listener.beforeAdd(A_Impl.this, BS__PROP, index, element); - ((test.references.data.impl.B_Impl) element).addInBs(A_Impl.this); + added.addInBs(A_Impl.this); } @Override protected void afterRemove(int index, test.references.data.B element) { - ((test.references.data.impl.B_Impl) element).removeInBs(A_Impl.this); + test.references.data.impl.B_Impl removed = (test.references.data.impl.B_Impl) element; + removed.removeInBs(A_Impl.this); _listener.afterRemove(A_Impl.this, BS__PROP, index, element); } }; @@ -39,13 +41,15 @@ protected void afterRemove(int index, test.references.data.B element) { private final java.util.List _others = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.references.data.A element) { + test.references.data.impl.A_Impl added = (test.references.data.impl.A_Impl) element; _listener.beforeAdd(A_Impl.this, OTHERS__PROP, index, element); - ((test.references.data.impl.A_Impl) element).addInOthers(A_Impl.this); + added.addInOthers(A_Impl.this); } @Override protected void afterRemove(int index, test.references.data.A element) { - ((test.references.data.impl.A_Impl) element).removeInOthers(A_Impl.this); + test.references.data.impl.A_Impl removed = (test.references.data.impl.A_Impl) element; + removed.removeInOthers(A_Impl.this); _listener.afterRemove(A_Impl.this, OTHERS__PROP, index, element); } }; From cebbc36935d7f8d5ec2cdef89d5a316811022785 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 3 Feb 2023 22:19:52 +0100 Subject: [PATCH 042/207] Implemented container handling for map-valued properties. --- .../msgbuf/generator/FieldOperations.java | 4 + .../msgbuf/generator/MessageGenerator.java | 27 +++++-- .../java/test/container/TestContainer.java | 64 ++++++++++++++++ .../model/impl/MyContainer_Impl.java | 22 +++++- .../java/test/graph/data/impl/Group_Impl.java | 2 +- .../test/hierarchy/data/impl/Group_Impl.java | 2 +- .../maptype/data/impl/MyMessage_Impl.java | 24 +++++- .../nested/data/impl/SearchResponse_Impl.java | 4 +- .../test/java/test/nointerfaces/Group.java | 2 +- .../java/test/nojson/impl/Group_Impl.java | 2 +- .../java/test/notypekind/impl/Group_Impl.java | 2 +- .../java/test/novisit/impl/Group_Impl.java | 2 +- .../novisitexceptions/impl/Group_Impl.java | 2 +- .../test/references/data/impl/A_Impl.java | 10 +-- .../test/references/data/impl/B_Impl.java | 4 +- .../haumacher/msgbuf/observer/Listener.java | 32 ++++++++ .../haumacher/msgbuf/util/ReferenceMap.java | 75 +++++++++++++++++++ 17 files changed, 252 insertions(+), 28 deletions(-) create mode 100644 de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceMap.java diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java index 9cc9580a..90151e5c 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java @@ -6,6 +6,7 @@ import de.haumacher.msgbuf.generator.ast.CustomType; import de.haumacher.msgbuf.generator.ast.Definition; import de.haumacher.msgbuf.generator.ast.Field; +import de.haumacher.msgbuf.generator.ast.MapType; import de.haumacher.msgbuf.generator.ast.MessageDef; import de.haumacher.msgbuf.generator.ast.Option; import de.haumacher.msgbuf.generator.ast.StringOption; @@ -79,6 +80,9 @@ default Option getReverseAnnotation() { default Field container() { if (!isDerived()) { Type contentType = self().getType(); + if (contentType instanceof MapType) { + contentType = ((MapType) contentType).getValueType(); + } if (contentType instanceof CustomType) { Definition contentDef = ((CustomType) contentType).getDefinition(); if (contentDef instanceof MessageDef) { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 581f3a20..500c8879 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -467,7 +467,9 @@ private void generateFieldMembers() { for (Field field : getFields()) { nl(); - if (field.isRepeated()) { + boolean isList = field.isRepeated(); + boolean isMap = field.getType() instanceof MapType; + if (isList || isMap) { Field reverseEnd = reverseEnd(field); boolean hasReverseEnd = reverseEnd != null; @@ -476,14 +478,23 @@ private void generateFieldMembers() { if (_listener || hasReverseEnd || container != null) { Type type = field.getType(); - String qFieldTypeName = mkTypeWrapped(type); - line("private" + mkTransient(field) + mkFinal(field) + " " + mkType(field) + " " + fieldMemberName(field) + " = " + "new de.haumacher.msgbuf.util.ReferenceList<" + qFieldTypeName + ">() {"); + Type contentType = isList ? type : ((MapType) type).getValueType(); + String contentTypeWrapped = mkTypeWrapped(contentType); + String contentTypeImpl = mkTypeWrappedImpl(contentType); + String keyType = isList ? + "int" : + mkTypeWrapped(((MapType) type).getKeyType()); + + String collectionType = isList ? + "de.haumacher.msgbuf.util.ReferenceList" + "<>" : + "de.haumacher.msgbuf.util.ReferenceMap" + "<>"; + line("private" + mkTransient(field) + mkFinal(field) + " " + mkType(field) + " " + fieldMemberName(field) + " = " + "new " + collectionType + "() {"); { line("@Override"); - line("protected void beforeAdd(int index, " + qFieldTypeName + " element) {"); + line("protected void beforeAdd(" + keyType + " " + "index" + ", " + contentTypeWrapped + " element) {"); { if (hasContainer || hasReverseEnd) { - line(mkTypeWrappedImpl(type) + " added = (" + mkTypeWrappedImpl(type) + ") element;"); + line(contentTypeImpl + " added = (" + contentTypeImpl + ") element;"); } if (hasContainer) { @@ -497,7 +508,7 @@ private void generateFieldMembers() { } if (_listener) { - line("_listener.beforeAdd(" + implName(_def) + ".this, " + constant(field) + ", index, element);"); + line("_listener.beforeAdd(" + implName(_def) + ".this, " + constant(field) + ", " + "index" + ", element);"); } if (hasContainer) { @@ -512,10 +523,10 @@ private void generateFieldMembers() { nl(); line("@Override"); - line("protected void afterRemove(int index, " + qFieldTypeName + " element) {"); + line("protected void afterRemove(" + keyType + " " + "index" + ", " + contentTypeWrapped + " element) {"); { if (hasContainer || hasReverseEnd) { - line(mkTypeWrappedImpl(type) + " removed = (" + mkTypeWrappedImpl(type) + ") element;"); + line(contentTypeImpl + " removed = (" + contentTypeImpl + ") element;"); } if (hasReverseEnd) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java index 6cdd099e..e83c6c50 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java @@ -4,6 +4,7 @@ package test.container; import java.util.Arrays; +import java.util.Collections; import junit.framework.TestCase; import test.container.model.MyContainer; @@ -101,6 +102,69 @@ public void testUpdateMulti() { assertEquals(0, otherContainer.getContentList().size()); } + public void testUpdateMap() { + MyContainer container = MyContainer.create().setName("container"); + MyContainer otherContainer = MyContainer.create().setName("other"); + + MyContent c1 = MyContent.create().setName("content 1"); + + container.putContentMap("c1", c1); + assertEquals(container, c1.getContainer()); + + MyContent c2 = MyContent.create().setName("content 2"); + container.putContentMap("c2", c2); + assertEquals(container, c1.getContainer()); + assertEquals(container, c2.getContainer()); + + container.setContentMap(Collections.singletonMap("c1", c1)); + assertEquals(container, c1.getContainer()); + assertNull(c2.getContainer()); + + container.removeContentMap("c1"); + assertNull(c1.getContainer()); + + container.getContentMap().putAll(Collections.singletonMap("c1", c1)); + container.getContentMap().putAll(Collections.singletonMap("c2", c2)); + assertEquals(container, c1.getContainer()); + assertEquals(container, c2.getContainer()); + + container.getContentMap().clear(); + assertNull(c1.getContainer()); + assertNull(c2.getContainer()); + + container.getContentMap().put("c1", c2); + assertEquals(container, c2.getContainer()); + + container.getContentMap().put("c1", c2); + assertEquals(container, c2.getContainer()); + + container.getContentMap().put("c1", c1); + assertEquals(container, c1.getContainer()); + assertNull(c2.getContainer()); + + try { + container.getContentMap().put("c2", c1); + fail("Must not make object part of two different containers."); + } catch (IllegalStateException ex) { + assertEquals("Object may not be part of two different containers.", ex.getMessage()); + } + + // Check that nothing has changed. + assertEquals(container, c1.getContainer()); + assertEquals(Collections.singletonMap("c1", c1), container.getContentMap()); + + try { + otherContainer.putContentMap("c1", c1); + fail("Must not make object part of two different containers."); + } catch (IllegalStateException ex) { + assertEquals("Object may not be part of two different containers.", ex.getMessage()); + } + + assertEquals(container, c1.getContainer()); + assertEquals(Collections.singletonMap("c1", c1), container.getContentMap()); + assertEquals(0, otherContainer.getContentMap().size()); + } + public void testUpdateIdentical() { MyContent c = MyContent.create().setName("c"); MyContainer container = MyContainer.create().setContent1(c); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java index 3b5be407..b36c3caf 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java @@ -8,7 +8,7 @@ public class MyContainer_Impl extends de.haumacher.msgbuf.data.AbstractDataObjec private test.container.model.MyContent _content2 = null; - private final java.util.List _contentList = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _contentList = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.container.model.MyContent element) { test.container.model.impl.MyContent_Impl added = (test.container.model.impl.MyContent_Impl) element; @@ -28,7 +28,25 @@ protected void afterRemove(int index, test.container.model.MyContent element) { } }; - private final java.util.Map _contentMap = new java.util.HashMap<>(); + private final java.util.Map _contentMap = new de.haumacher.msgbuf.util.ReferenceMap<>() { + @Override + protected void beforeAdd(String index, test.container.model.MyContent element) { + test.container.model.impl.MyContent_Impl added = (test.container.model.impl.MyContent_Impl) element; + test.container.model.MyContainer oldContainer = added.getContainer(); + if (oldContainer != null && oldContainer != this) { + throw new IllegalStateException("Object may not be part of two different containers."); + } + _listener.beforeAdd(MyContainer_Impl.this, CONTENT_MAP__PROP, index, element); + added.internalSetContainer(MyContainer_Impl.this); + } + + @Override + protected void afterRemove(String index, test.container.model.MyContent element) { + test.container.model.impl.MyContent_Impl removed = (test.container.model.impl.MyContent_Impl) element; + removed.internalSetContainer(null); + _listener.afterRemove(MyContainer_Impl.this, CONTENT_MAP__PROP, index, element); + } + }; /** * Creates a {@link MyContainer_Impl} instance. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java index 4af09d5a..0636b265 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java @@ -5,7 +5,7 @@ */ public class Group_Impl extends test.graph.data.impl.Shape_Impl implements test.graph.data.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.graph.data.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java index 80072c80..60f81dc7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java @@ -5,7 +5,7 @@ */ public class Group_Impl extends test.hierarchy.data.impl.Shape_Impl implements test.hierarchy.data.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.hierarchy.data.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java index d8c8e0c8..e15ff3be 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java @@ -2,9 +2,29 @@ public class MyMessage_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.maptype.data.MyMessage { - private final java.util.Map _projects = new java.util.HashMap<>(); + private final java.util.Map _projects = new de.haumacher.msgbuf.util.ReferenceMap<>() { + @Override + protected void beforeAdd(String index, test.maptype.data.Project element) { + _listener.beforeAdd(MyMessage_Impl.this, PROJECTS__PROP, index, element); + } + + @Override + protected void afterRemove(String index, test.maptype.data.Project element) { + _listener.afterRemove(MyMessage_Impl.this, PROJECTS__PROP, index, element); + } + }; - private final java.util.Map _rating = new java.util.HashMap<>(); + private final java.util.Map _rating = new de.haumacher.msgbuf.util.ReferenceMap<>() { + @Override + protected void beforeAdd(Integer index, String element) { + _listener.beforeAdd(MyMessage_Impl.this, RATING__PROP, index, element); + } + + @Override + protected void afterRemove(Integer index, String element) { + _listener.afterRemove(MyMessage_Impl.this, RATING__PROP, index, element); + } + }; /** * Creates a {@link MyMessage_Impl} instance. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java index faa24c26..a5f23037 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java @@ -7,7 +7,7 @@ public static class Result_Impl extends de.haumacher.msgbuf.data.AbstractDataObj private String _title = ""; - private final java.util.List _snippets = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _snippets = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, String element) { _listener.beforeAdd(Result_Impl.this, SNIPPETS__PROP, index, element); @@ -367,7 +367,7 @@ protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream } - private final java.util.List _results = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _results = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.nested.data.SearchResponse.Result element) { _listener.beforeAdd(SearchResponse_Impl.this, RESULTS__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java index 84c22f3c..68645e41 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java @@ -24,7 +24,7 @@ public static test.nointerfaces.Group create() { /** Identifier for the property {@link #getShapes()} in binary format. */ static final int SHAPES__ID = 3; - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.nointerfaces.Shape element) { _listener.beforeAdd(Group.this, SHAPES__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java index af30cfea..06cab9c5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java @@ -5,7 +5,7 @@ */ public class Group_Impl extends test.nojson.impl.Shape_Impl implements test.nojson.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.nojson.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java index fa484c6c..859ed464 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java @@ -5,7 +5,7 @@ */ public class Group_Impl extends test.notypekind.impl.Shape_Impl implements test.notypekind.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.notypekind.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java index 93c64952..7cea26ac 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java @@ -5,7 +5,7 @@ */ public class Group_Impl extends test.novisit.impl.Shape_Impl implements test.novisit.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.novisit.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java index 57bc4aa3..0a4a613a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java @@ -5,7 +5,7 @@ */ public class Group_Impl extends test.novisitexceptions.impl.Shape_Impl implements test.novisitexceptions.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.novisitexceptions.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java index 01323b2a..357a4134 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java @@ -6,7 +6,7 @@ public class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implemen private test.references.data.A _contents = null; - private final java.util.List _children = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _children = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(A_Impl.this, CHILDREN__PROP, index, element); @@ -18,7 +18,7 @@ protected void afterRemove(int index, test.references.data.A element) { } }; - private final java.util.List _bs = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _bs = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.references.data.B element) { test.references.data.impl.B_Impl added = (test.references.data.impl.B_Impl) element; @@ -38,7 +38,7 @@ protected void afterRemove(int index, test.references.data.B element) { private test.references.data.A _other = null; - private final java.util.List _others = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _others = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.references.data.A element) { test.references.data.impl.A_Impl added = (test.references.data.impl.A_Impl) element; @@ -54,7 +54,7 @@ protected void afterRemove(int index, test.references.data.A element) { } }; - private final java.util.List _inOther = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _inOther = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(A_Impl.this, IN_OTHER__PROP, index, element); @@ -66,7 +66,7 @@ protected void afterRemove(int index, test.references.data.A element) { } }; - private final java.util.List _inOthers = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _inOthers = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(A_Impl.this, IN_OTHERS__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java index 3af83984..67e02013 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java @@ -4,7 +4,7 @@ public class B_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implemen private String _name = ""; - private final java.util.List _inBs = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _inBs = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(B_Impl.this, IN_BS__PROP, index, element); @@ -16,7 +16,7 @@ protected void afterRemove(int index, test.references.data.A element) { } }; - private final java.util.List _inB = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _inB = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(B_Impl.this, IN_B__PROP, index, element); diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/observer/Listener.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/observer/Listener.java index 8dc112af..fe995ce3 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/observer/Listener.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/observer/Listener.java @@ -48,6 +48,22 @@ default void beforeAdd(Observable obj, String property, int index, Object elemen // Ignore. } + /** + * Informs this {@link Listener} that an element will be added to the map property with the given name. + * + * @param obj + * The {@link Observable} object. + * @param property + * The name of the property to be modified. + * @param index + * The index where the new element will be added if the property is ordered, -1 otherwise. + * @param element + * The new element that is being added to the given property. + */ + default void beforeAdd(Observable obj, String property, Object index, Object element) { + // Ignore. + } + /** * Informs this {@link Listener} that an element was removed from a repeated property with the given name. * @@ -64,6 +80,22 @@ default void afterRemove(Observable obj, String property, int index, Object elem // Ignore. } + /** + * Informs this {@link Listener} that an element was removed from a map property with the given name. + * + * @param obj + * The {@link Observable} object. + * @param property + * The name of the property to be modified. + * @param index + * The index where the element was removed if the property is ordered, -1 otherwise. + * @param element + * The element that was removed from the given property. + */ + default void afterRemove(Observable obj, String property, Object index, Object element) { + // Ignore. + } + /** * {@link Listener} that multiplexes events to a list of potentially multiple target {@link Listener}s. */ diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceMap.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceMap.java new file mode 100644 index 00000000..15221739 --- /dev/null +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceMap.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021 Bernhard Haumacher et al. All Rights Reserved. + */ +package de.haumacher.msgbuf.util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * {@link Map} implementing a map-valued property of a data object that has a reverse end. + * + *

+ * The reverse end must be handled in concrete subclasses by overriding {@link #beforeAdd(Object, Object)} and + * {@link #afterRemove(Object, Object)}. + *

+ */ +public abstract class ReferenceMap extends HashMap { + + @Override + public V put(K key, V value) { + remove(key); + + beforeAdd(key, value); + return super.put(key, value); + } + + @Override + public void putAll(Map collection) { + beforeAddAll(collection); + super.putAll(collection); + } + + private void beforeAddAll(Map collection) { + for (Entry value : collection.entrySet()) { + beforeAdd(value.getKey(), value.getValue()); + } + } + + protected abstract void beforeAdd(K key, V value); + + @Override + public V remove(Object key) { + final V removed = super.remove(key); + if (removed != null) { + @SuppressWarnings("unchecked") + K removedKey = (K) key; + afterRemove(removedKey, removed); + } + return removed; + } + + @Override + public boolean remove(Object key, Object value) { + final boolean success = super.remove(key, value); + if (success) { + @SuppressWarnings("unchecked") + K removedKey = (K) key; + @SuppressWarnings("unchecked") + V removed = (V) value; + afterRemove(removedKey, removed); + } + return success; + } + + @Override + public void clear() { + for (K key : new ArrayList<>(keySet())) { + remove(key); + } + } + + protected abstract void afterRemove(K key, V value); + +} From 72cd2478177dc36049fc0f781a4d59a08934d63c Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 19 May 2023 10:52:45 +0200 Subject: [PATCH 043/207] Do not duplicate user comment at implementation class. The comment may reference other types that would have to be qualified, otherwise. The implementation classes are not visible, therefore need no user documentation. --- .../de/haumacher/msgbuf/generator/MessageGenerator.java | 6 +++++- .../java/test/comments/data/impl/SearchRequest_Impl.java | 3 +-- .../java/test/container/model/impl/MyContainer_Impl.java | 3 +++ .../test/java/test/container/model/impl/MyContent_Impl.java | 3 +++ .../java/test/enumeration/data/impl/SearchRequest_Impl.java | 3 +++ .../test/java/test/graph/data/impl/AtomicShape_Impl.java | 2 +- .../src/test/java/test/graph/data/impl/Car_Impl.java | 2 +- .../src/test/java/test/graph/data/impl/Circle_Impl.java | 2 +- .../src/test/java/test/graph/data/impl/Group_Impl.java | 2 +- .../src/test/java/test/graph/data/impl/Rectangle_Impl.java | 2 +- .../src/test/java/test/graph/data/impl/Shape_Impl.java | 2 +- .../src/test/java/test/graph/data/impl/SimpleType_Impl.java | 2 +- .../java/test/hierarchy/data/impl/AtomicShape_Impl.java | 2 +- .../src/test/java/test/hierarchy/data/impl/Car_Impl.java | 2 +- .../src/test/java/test/hierarchy/data/impl/Circle_Impl.java | 2 +- .../src/test/java/test/hierarchy/data/impl/Group_Impl.java | 2 +- .../test/java/test/hierarchy/data/impl/Optional_Impl.java | 2 +- .../test/java/test/hierarchy/data/impl/Rectangle_Impl.java | 2 +- .../src/test/java/test/hierarchy/data/impl/Shape_Impl.java | 2 +- .../test/java/test/hierarchy/data/impl/SimpleType_Impl.java | 2 +- .../src/test/java/test/innertypeclash/impl/A_Impl.java | 6 ++++++ .../src/test/java/test/innertypeclash/impl/B_Impl.java | 6 ++++++ .../src/test/java/test/lowercasemessage/impl/A_Impl.java | 6 ++++++ .../test/java/test/maptype/data/impl/MyMessage_Impl.java | 3 +++ .../src/test/java/test/maptype/data/impl/Project_Impl.java | 3 +++ .../java/test/nested/data/impl/SearchResponse_Impl.java | 6 ++++++ .../src/test/java/test/nojson/impl/AtomicShape_Impl.java | 2 +- .../src/test/java/test/nojson/impl/Car_Impl.java | 2 +- .../src/test/java/test/nojson/impl/Circle_Impl.java | 2 +- .../src/test/java/test/nojson/impl/Group_Impl.java | 2 +- .../src/test/java/test/nojson/impl/Rectangle_Impl.java | 2 +- .../src/test/java/test/nojson/impl/Shape_Impl.java | 2 +- .../src/test/java/test/nojson/impl/SimpleType_Impl.java | 2 +- .../test/java/test/nolistener/impl/AtomicShape_Impl.java | 2 +- .../src/test/java/test/nolistener/impl/Car_Impl.java | 2 +- .../src/test/java/test/nolistener/impl/Circle_Impl.java | 2 +- .../src/test/java/test/nolistener/impl/Group_Impl.java | 2 +- .../src/test/java/test/nolistener/impl/Rectangle_Impl.java | 2 +- .../src/test/java/test/nolistener/impl/Shape_Impl.java | 2 +- .../src/test/java/test/nolistener/impl/SimpleType_Impl.java | 2 +- .../src/test/java/test/nothing/impl/AtomicShape_Impl.java | 2 +- .../src/test/java/test/nothing/impl/Car_Impl.java | 2 +- .../src/test/java/test/nothing/impl/Circle_Impl.java | 2 +- .../src/test/java/test/nothing/impl/Group_Impl.java | 2 +- .../src/test/java/test/nothing/impl/Rectangle_Impl.java | 2 +- .../src/test/java/test/nothing/impl/Shape_Impl.java | 2 +- .../src/test/java/test/nothing/impl/SimpleType_Impl.java | 2 +- .../test/java/test/notypekind/impl/AtomicShape_Impl.java | 2 +- .../src/test/java/test/notypekind/impl/Car_Impl.java | 2 +- .../src/test/java/test/notypekind/impl/Circle_Impl.java | 2 +- .../src/test/java/test/notypekind/impl/Group_Impl.java | 2 +- .../src/test/java/test/notypekind/impl/Rectangle_Impl.java | 2 +- .../src/test/java/test/notypekind/impl/Shape_Impl.java | 2 +- .../src/test/java/test/notypekind/impl/SimpleType_Impl.java | 2 +- .../src/test/java/test/novisit/impl/AtomicShape_Impl.java | 2 +- .../src/test/java/test/novisit/impl/Car_Impl.java | 2 +- .../src/test/java/test/novisit/impl/Circle_Impl.java | 2 +- .../src/test/java/test/novisit/impl/Group_Impl.java | 2 +- .../src/test/java/test/novisit/impl/Rectangle_Impl.java | 2 +- .../src/test/java/test/novisit/impl/Shape_Impl.java | 2 +- .../src/test/java/test/novisit/impl/SimpleType_Impl.java | 2 +- .../java/test/novisitexceptions/impl/AtomicShape_Impl.java | 2 +- .../src/test/java/test/novisitexceptions/impl/Car_Impl.java | 2 +- .../test/java/test/novisitexceptions/impl/Circle_Impl.java | 2 +- .../test/java/test/novisitexceptions/impl/Group_Impl.java | 2 +- .../java/test/novisitexceptions/impl/Rectangle_Impl.java | 2 +- .../test/java/test/novisitexceptions/impl/Shape_Impl.java | 2 +- .../java/test/novisitexceptions/impl/SimpleType_Impl.java | 2 +- .../java/test/nullable/data/impl/NullableValues_Impl.java | 3 +++ .../java/test/oneoffield/data/impl/SampleMessage_Impl.java | 3 +++ .../test/java/test/onlyxml/data/impl/AtomicShape_Impl.java | 2 +- .../src/test/java/test/onlyxml/data/impl/Car_Impl.java | 2 +- .../src/test/java/test/onlyxml/data/impl/Circle_Impl.java | 2 +- .../src/test/java/test/onlyxml/data/impl/Group_Impl.java | 2 +- .../src/test/java/test/onlyxml/data/impl/Optional_Impl.java | 2 +- .../test/java/test/onlyxml/data/impl/Rectangle_Impl.java | 2 +- .../src/test/java/test/onlyxml/data/impl/Shape_Impl.java | 2 +- .../test/java/test/onlyxml/data/impl/SimpleType_Impl.java | 2 +- .../test/java/test/options/data/impl/MyMessage1_Impl.java | 3 +++ .../test/java/test/options/data/impl/MyMessage2_Impl.java | 3 +++ .../src/test/java/test/references/data/impl/A_Impl.java | 3 +++ .../src/test/java/test/references/data/impl/B_Impl.java | 3 +++ .../test/java/test/types/data/impl/SearchRequest_Impl.java | 3 +++ .../test/underscorename/impl/AnnotatedMessage_Impl.java | 3 +++ .../test/java/test/underscorename/impl/BaseMsg_Impl.java | 3 +++ .../test/java/test/underscorename/impl/SomeName_Impl.java | 3 +++ 86 files changed, 140 insertions(+), 68 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 500c8879..dd6666be 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -130,7 +130,11 @@ protected void generate() { } else { modifier = _interface ? "" : "static"; } - docComment(_def.getComment()); + if (_interface || _noInterfaces) { + docComment(_def.getComment()); + } else { + docComment("Implementation of {@link " + qTypeName(_def) + "}."); + } line("public", modifier, mkAbstract(), (_interface ? "interface" : "class"), (_interface || _noInterfaces ? typeName(_def) : implName(_def)), getExtends(), getImplements(), "{"); generateClassContents(); nl(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java index f838e71a..8ff30fde 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java @@ -1,8 +1,7 @@ package test.comments.data.impl; /** - * SearchRequest represents a search query, with {@link #getPageNumber() pagination options} to - * indicate which results to include in the response. + * Implementation of {@link test.comments.data.SearchRequest}. */ public class SearchRequest_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.comments.data.SearchRequest { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java index b36c3caf..b871e89e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java @@ -1,5 +1,8 @@ package test.container.model.impl; +/** + * Implementation of {@link test.container.model.MyContainer}. + */ public class MyContainer_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.container.model.MyContainer { private String _name = ""; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java index 327a6720..7c55a4ca 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java @@ -1,5 +1,8 @@ package test.container.model.impl; +/** + * Implementation of {@link test.container.model.MyContent}. + */ public class MyContent_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.container.model.MyContent { private test.container.model.MyContainer _container = null; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java index d1a395b9..01cb4fdf 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java @@ -1,5 +1,8 @@ package test.enumeration.data.impl; +/** + * Implementation of {@link test.enumeration.data.SearchRequest}. + */ public class SearchRequest_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.enumeration.data.SearchRequest { private String _query = ""; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/AtomicShape_Impl.java index 125a496e..c872ce80 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/AtomicShape_Impl.java @@ -1,7 +1,7 @@ package test.graph.data.impl; /** - * A {@link Shape} that has no sub-shapes. + * Implementation of {@link test.graph.data.AtomicShape}. */ public abstract class AtomicShape_Impl extends test.graph.data.impl.Shape_Impl implements test.graph.data.AtomicShape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java index 321ebac3..258da6e5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java @@ -1,7 +1,7 @@ package test.graph.data.impl; /** - * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. + * Implementation of {@link test.graph.data.Car}. */ public class Car_Impl extends test.graph.data.impl.Shape_Impl implements test.graph.data.Car { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java index 01b9d1af..6918ec51 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java @@ -1,7 +1,7 @@ package test.graph.data.impl; /** - * A circle {@link Shape}. + * Implementation of {@link test.graph.data.Circle}. */ public class Circle_Impl extends test.graph.data.impl.AtomicShape_Impl implements test.graph.data.Circle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java index 0636b265..632f0bce 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java @@ -1,7 +1,7 @@ package test.graph.data.impl; /** - * A group of shapes. + * Implementation of {@link test.graph.data.Group}. */ public class Group_Impl extends test.graph.data.impl.Shape_Impl implements test.graph.data.Group { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java index 90438389..1d99f42c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java @@ -1,7 +1,7 @@ package test.graph.data.impl; /** - * A rectangle. + * Implementation of {@link test.graph.data.Rectangle}. */ public class Rectangle_Impl extends test.graph.data.impl.AtomicShape_Impl implements test.graph.data.Rectangle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java index ccbf5426..96bef0f1 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java @@ -1,7 +1,7 @@ package test.graph.data.impl; /** - * An abstract base class for all shapes + * Implementation of {@link test.graph.data.Shape}. */ public abstract class Shape_Impl extends de.haumacher.msgbuf.graph.AbstractSharedGraphNode implements test.graph.data.Shape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java index d4a5ad2a..951a448b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java @@ -1,7 +1,7 @@ package test.graph.data.impl; /** - * A concrete type without abstract super type. + * Implementation of {@link test.graph.data.SimpleType}. */ public class SimpleType_Impl extends de.haumacher.msgbuf.graph.AbstractSharedGraphNode implements test.graph.data.SimpleType { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/AtomicShape_Impl.java index a25138f9..83e14bf8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/AtomicShape_Impl.java @@ -1,7 +1,7 @@ package test.hierarchy.data.impl; /** - * A {@link Shape} that has no sub-shapes. + * Implementation of {@link test.hierarchy.data.AtomicShape}. */ public abstract class AtomicShape_Impl extends test.hierarchy.data.impl.Shape_Impl implements test.hierarchy.data.AtomicShape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java index 4c7ee58e..060dd5ea 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java @@ -1,7 +1,7 @@ package test.hierarchy.data.impl; /** - * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. + * Implementation of {@link test.hierarchy.data.Car}. */ public class Car_Impl extends test.hierarchy.data.impl.Shape_Impl implements test.hierarchy.data.Car { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java index a9ad8679..e41d7173 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java @@ -1,7 +1,7 @@ package test.hierarchy.data.impl; /** - * A circle {@link Shape}. + * Implementation of {@link test.hierarchy.data.Circle}. */ public class Circle_Impl extends test.hierarchy.data.impl.AtomicShape_Impl implements test.hierarchy.data.Circle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java index 60f81dc7..2c465b89 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java @@ -1,7 +1,7 @@ package test.hierarchy.data.impl; /** - * A group of shapes. + * Implementation of {@link test.hierarchy.data.Group}. */ public class Group_Impl extends test.hierarchy.data.impl.Shape_Impl implements test.hierarchy.data.Group { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java index 10b1ed9c..7e76fd18 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java @@ -1,7 +1,7 @@ package test.hierarchy.data.impl; /** - * A shape that can be dynamically hidden. + * Implementation of {@link test.hierarchy.data.Optional}. */ public class Optional_Impl extends test.hierarchy.data.impl.Shape_Impl implements test.hierarchy.data.Optional { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java index d7ed4e34..b303d09f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java @@ -1,7 +1,7 @@ package test.hierarchy.data.impl; /** - * A rectangle. + * Implementation of {@link test.hierarchy.data.Rectangle}. */ public class Rectangle_Impl extends test.hierarchy.data.impl.AtomicShape_Impl implements test.hierarchy.data.Rectangle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java index 4ac5b1d6..3cb1de6f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java @@ -1,7 +1,7 @@ package test.hierarchy.data.impl; /** - * An abstract base class for all shapes + * Implementation of {@link test.hierarchy.data.Shape}. */ public abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.hierarchy.data.Shape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java index f38cfdbe..e59706a0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java @@ -1,7 +1,7 @@ package test.hierarchy.data.impl; /** - * A concrete type without abstract super type. + * Implementation of {@link test.hierarchy.data.SimpleType}. */ public class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.hierarchy.data.SimpleType { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java index 667e995d..c9c5977d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java @@ -1,6 +1,12 @@ package test.innertypeclash.impl; +/** + * Implementation of {@link test.innertypeclash.A}. + */ public class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.innertypeclash.A { + /** + * Implementation of {@link test.innertypeclash.A.C}. + */ public static class C_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.innertypeclash.A.C { /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java index f41ffe1f..f5f1d80b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java @@ -1,6 +1,12 @@ package test.innertypeclash.impl; +/** + * Implementation of {@link test.innertypeclash.B}. + */ public class B_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.innertypeclash.B { + /** + * Implementation of {@link test.innertypeclash.B.C}. + */ public static class C_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.innertypeclash.B.C { /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java index b8003d3e..5b3c981e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java @@ -1,6 +1,12 @@ package test.lowercasemessage.impl; +/** + * Implementation of {@link test.lowercasemessage.A}. + */ public class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.lowercasemessage.A { + /** + * Implementation of {@link test.lowercasemessage.A.B}. + */ public static class B_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.lowercasemessage.A.B { private test.lowercasemessage.A _a1 = null; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java index e15ff3be..51ae6ca8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java @@ -1,5 +1,8 @@ package test.maptype.data.impl; +/** + * Implementation of {@link test.maptype.data.MyMessage}. + */ public class MyMessage_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.maptype.data.MyMessage { private final java.util.Map _projects = new de.haumacher.msgbuf.util.ReferenceMap<>() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java index 8c1b8af3..c8030451 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java @@ -1,5 +1,8 @@ package test.maptype.data.impl; +/** + * Implementation of {@link test.maptype.data.Project}. + */ public class Project_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.maptype.data.Project { private String _name = ""; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java index a5f23037..3294bf2b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java @@ -1,6 +1,12 @@ package test.nested.data.impl; +/** + * Implementation of {@link test.nested.data.SearchResponse}. + */ public class SearchResponse_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.data.SearchResponse { + /** + * Implementation of {@link test.nested.data.SearchResponse.Result}. + */ public static class Result_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.data.SearchResponse.Result { private String _url = ""; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/AtomicShape_Impl.java index 1bd3a3fb..a8aa98de 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/AtomicShape_Impl.java @@ -1,7 +1,7 @@ package test.nojson.impl; /** - * A {@link Shape} that has no sub-shapes. + * Implementation of {@link test.nojson.AtomicShape}. */ public abstract class AtomicShape_Impl extends test.nojson.impl.Shape_Impl implements test.nojson.AtomicShape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java index de6950a1..bb0cdb5a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java @@ -1,7 +1,7 @@ package test.nojson.impl; /** - * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. + * Implementation of {@link test.nojson.Car}. */ public class Car_Impl extends test.nojson.impl.Shape_Impl implements test.nojson.Car { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java index aaf5bd73..c25d63e1 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java @@ -1,7 +1,7 @@ package test.nojson.impl; /** - * A circle {@link Shape}. + * Implementation of {@link test.nojson.Circle}. */ public class Circle_Impl extends test.nojson.impl.AtomicShape_Impl implements test.nojson.Circle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java index 06cab9c5..9d2c6445 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java @@ -1,7 +1,7 @@ package test.nojson.impl; /** - * A group of shapes. + * Implementation of {@link test.nojson.Group}. */ public class Group_Impl extends test.nojson.impl.Shape_Impl implements test.nojson.Group { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java index 4f605b43..6e36f515 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java @@ -1,7 +1,7 @@ package test.nojson.impl; /** - * A rectangle. + * Implementation of {@link test.nojson.Rectangle}. */ public class Rectangle_Impl extends test.nojson.impl.AtomicShape_Impl implements test.nojson.Rectangle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java index 4eaf380b..772ab4b8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java @@ -1,7 +1,7 @@ package test.nojson.impl; /** - * An abstract base class for all shapes + * Implementation of {@link test.nojson.Shape}. */ public abstract class Shape_Impl implements test.nojson.Shape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java index e8b41b7b..b2a8596c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java @@ -1,7 +1,7 @@ package test.nojson.impl; /** - * A concrete type without abstract super type. + * Implementation of {@link test.nojson.SimpleType}. */ public class SimpleType_Impl implements test.nojson.SimpleType { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/AtomicShape_Impl.java index 2089fbd1..0e7b117d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/AtomicShape_Impl.java @@ -1,7 +1,7 @@ package test.nolistener.impl; /** - * A {@link Shape} that has no sub-shapes. + * Implementation of {@link test.nolistener.AtomicShape}. */ public abstract class AtomicShape_Impl extends test.nolistener.impl.Shape_Impl implements test.nolistener.AtomicShape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Car_Impl.java index 56761d79..82bf9712 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Car_Impl.java @@ -1,7 +1,7 @@ package test.nolistener.impl; /** - * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. + * Implementation of {@link test.nolistener.Car}. */ public class Car_Impl extends test.nolistener.impl.Shape_Impl implements test.nolistener.Car { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Circle_Impl.java index 95c4b4a7..4edad803 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Circle_Impl.java @@ -1,7 +1,7 @@ package test.nolistener.impl; /** - * A circle {@link Shape}. + * Implementation of {@link test.nolistener.Circle}. */ public class Circle_Impl extends test.nolistener.impl.AtomicShape_Impl implements test.nolistener.Circle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java index 43e9866c..99744cb2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java @@ -1,7 +1,7 @@ package test.nolistener.impl; /** - * A group of shapes. + * Implementation of {@link test.nolistener.Group}. */ public class Group_Impl extends test.nolistener.impl.Shape_Impl implements test.nolistener.Group { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Rectangle_Impl.java index d5279800..e4218684 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Rectangle_Impl.java @@ -1,7 +1,7 @@ package test.nolistener.impl; /** - * A rectangle. + * Implementation of {@link test.nolistener.Rectangle}. */ public class Rectangle_Impl extends test.nolistener.impl.AtomicShape_Impl implements test.nolistener.Rectangle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java index 4a7039fd..393b2bd7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java @@ -1,7 +1,7 @@ package test.nolistener.impl; /** - * An abstract base class for all shapes + * Implementation of {@link test.nolistener.Shape}. */ public abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nolistener.Shape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/SimpleType_Impl.java index 68ad9798..2d0c67ae 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/SimpleType_Impl.java @@ -1,7 +1,7 @@ package test.nolistener.impl; /** - * A concrete type without abstract super type. + * Implementation of {@link test.nolistener.SimpleType}. */ public class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nolistener.SimpleType { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/AtomicShape_Impl.java index 2dd06774..ed3348d9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/AtomicShape_Impl.java @@ -1,7 +1,7 @@ package test.nothing.impl; /** - * A {@link Shape} that has no sub-shapes. + * Implementation of {@link test.nothing.AtomicShape}. */ public abstract class AtomicShape_Impl extends test.nothing.impl.Shape_Impl implements test.nothing.AtomicShape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Car_Impl.java index 162971c8..d6f2400b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Car_Impl.java @@ -1,7 +1,7 @@ package test.nothing.impl; /** - * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. + * Implementation of {@link test.nothing.Car}. */ public class Car_Impl extends test.nothing.impl.Shape_Impl implements test.nothing.Car { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Circle_Impl.java index 845ef525..1c8de66e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Circle_Impl.java @@ -1,7 +1,7 @@ package test.nothing.impl; /** - * A circle {@link Shape}. + * Implementation of {@link test.nothing.Circle}. */ public class Circle_Impl extends test.nothing.impl.AtomicShape_Impl implements test.nothing.Circle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Group_Impl.java index eda6e999..da74d2e4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Group_Impl.java @@ -1,7 +1,7 @@ package test.nothing.impl; /** - * A group of shapes. + * Implementation of {@link test.nothing.Group}. */ public class Group_Impl extends test.nothing.impl.Shape_Impl implements test.nothing.Group { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Rectangle_Impl.java index 8f28fe09..1335f209 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Rectangle_Impl.java @@ -1,7 +1,7 @@ package test.nothing.impl; /** - * A rectangle. + * Implementation of {@link test.nothing.Rectangle}. */ public class Rectangle_Impl extends test.nothing.impl.AtomicShape_Impl implements test.nothing.Rectangle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Shape_Impl.java index 310114ad..c0db4719 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/Shape_Impl.java @@ -1,7 +1,7 @@ package test.nothing.impl; /** - * An abstract base class for all shapes + * Implementation of {@link test.nothing.Shape}. */ public abstract class Shape_Impl implements test.nothing.Shape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/SimpleType_Impl.java index 78d52e30..c0099982 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nothing/impl/SimpleType_Impl.java @@ -1,7 +1,7 @@ package test.nothing.impl; /** - * A concrete type without abstract super type. + * Implementation of {@link test.nothing.SimpleType}. */ public class SimpleType_Impl implements test.nothing.SimpleType { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/AtomicShape_Impl.java index ee6295f3..4e57c7e2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/AtomicShape_Impl.java @@ -1,7 +1,7 @@ package test.notypekind.impl; /** - * A {@link Shape} that has no sub-shapes. + * Implementation of {@link test.notypekind.AtomicShape}. */ public abstract class AtomicShape_Impl extends test.notypekind.impl.Shape_Impl implements test.notypekind.AtomicShape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java index fc864274..5c724d94 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java @@ -1,7 +1,7 @@ package test.notypekind.impl; /** - * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. + * Implementation of {@link test.notypekind.Car}. */ public class Car_Impl extends test.notypekind.impl.Shape_Impl implements test.notypekind.Car { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java index 7d8d9910..d94b638e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java @@ -1,7 +1,7 @@ package test.notypekind.impl; /** - * A circle {@link Shape}. + * Implementation of {@link test.notypekind.Circle}. */ public class Circle_Impl extends test.notypekind.impl.AtomicShape_Impl implements test.notypekind.Circle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java index 859ed464..eee0c52e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java @@ -1,7 +1,7 @@ package test.notypekind.impl; /** - * A group of shapes. + * Implementation of {@link test.notypekind.Group}. */ public class Group_Impl extends test.notypekind.impl.Shape_Impl implements test.notypekind.Group { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java index 0da2c61a..b91e1f53 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java @@ -1,7 +1,7 @@ package test.notypekind.impl; /** - * A rectangle. + * Implementation of {@link test.notypekind.Rectangle}. */ public class Rectangle_Impl extends test.notypekind.impl.AtomicShape_Impl implements test.notypekind.Rectangle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java index 5af75e5f..6d7017eb 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java @@ -1,7 +1,7 @@ package test.notypekind.impl; /** - * An abstract base class for all shapes + * Implementation of {@link test.notypekind.Shape}. */ public abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.notypekind.Shape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java index e084acfd..0b17e2d3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java @@ -1,7 +1,7 @@ package test.notypekind.impl; /** - * A concrete type without abstract super type. + * Implementation of {@link test.notypekind.SimpleType}. */ public class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.notypekind.SimpleType { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/AtomicShape_Impl.java index be562b5b..6cee6b36 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/AtomicShape_Impl.java @@ -1,7 +1,7 @@ package test.novisit.impl; /** - * A {@link Shape} that has no sub-shapes. + * Implementation of {@link test.novisit.AtomicShape}. */ public abstract class AtomicShape_Impl extends test.novisit.impl.Shape_Impl implements test.novisit.AtomicShape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java index a0455037..a75dde94 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java @@ -1,7 +1,7 @@ package test.novisit.impl; /** - * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. + * Implementation of {@link test.novisit.Car}. */ public class Car_Impl extends test.novisit.impl.Shape_Impl implements test.novisit.Car { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java index 7281b1ff..561e4718 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java @@ -1,7 +1,7 @@ package test.novisit.impl; /** - * A circle {@link Shape}. + * Implementation of {@link test.novisit.Circle}. */ public class Circle_Impl extends test.novisit.impl.AtomicShape_Impl implements test.novisit.Circle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java index 7cea26ac..6bc63e66 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java @@ -1,7 +1,7 @@ package test.novisit.impl; /** - * A group of shapes. + * Implementation of {@link test.novisit.Group}. */ public class Group_Impl extends test.novisit.impl.Shape_Impl implements test.novisit.Group { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java index 99925b4e..740ddbcc 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java @@ -1,7 +1,7 @@ package test.novisit.impl; /** - * A rectangle. + * Implementation of {@link test.novisit.Rectangle}. */ public class Rectangle_Impl extends test.novisit.impl.AtomicShape_Impl implements test.novisit.Rectangle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java index 2cc8e03c..b7d71b30 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java @@ -1,7 +1,7 @@ package test.novisit.impl; /** - * An abstract base class for all shapes + * Implementation of {@link test.novisit.Shape}. */ public abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.novisit.Shape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java index 59c56292..9c9c2e3f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java @@ -1,7 +1,7 @@ package test.novisit.impl; /** - * A concrete type without abstract super type. + * Implementation of {@link test.novisit.SimpleType}. */ public class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.novisit.SimpleType { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/AtomicShape_Impl.java index b219afd6..ef3e2e02 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/AtomicShape_Impl.java @@ -1,7 +1,7 @@ package test.novisitexceptions.impl; /** - * A {@link Shape} that has no sub-shapes. + * Implementation of {@link test.novisitexceptions.AtomicShape}. */ public abstract class AtomicShape_Impl extends test.novisitexceptions.impl.Shape_Impl implements test.novisitexceptions.AtomicShape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java index 95e16555..add66c47 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java @@ -1,7 +1,7 @@ package test.novisitexceptions.impl; /** - * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. + * Implementation of {@link test.novisitexceptions.Car}. */ public class Car_Impl extends test.novisitexceptions.impl.Shape_Impl implements test.novisitexceptions.Car { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java index 40a5ec86..a2dd570d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java @@ -1,7 +1,7 @@ package test.novisitexceptions.impl; /** - * A circle {@link Shape}. + * Implementation of {@link test.novisitexceptions.Circle}. */ public class Circle_Impl extends test.novisitexceptions.impl.AtomicShape_Impl implements test.novisitexceptions.Circle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java index 0a4a613a..729e8e5f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java @@ -1,7 +1,7 @@ package test.novisitexceptions.impl; /** - * A group of shapes. + * Implementation of {@link test.novisitexceptions.Group}. */ public class Group_Impl extends test.novisitexceptions.impl.Shape_Impl implements test.novisitexceptions.Group { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java index 3d0ad51d..f6563794 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java @@ -1,7 +1,7 @@ package test.novisitexceptions.impl; /** - * A rectangle. + * Implementation of {@link test.novisitexceptions.Rectangle}. */ public class Rectangle_Impl extends test.novisitexceptions.impl.AtomicShape_Impl implements test.novisitexceptions.Rectangle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java index 4e5c9f9f..4207b3ba 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java @@ -1,7 +1,7 @@ package test.novisitexceptions.impl; /** - * An abstract base class for all shapes + * Implementation of {@link test.novisitexceptions.Shape}. */ public abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.novisitexceptions.Shape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java index c28a09ba..a564adb2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java @@ -1,7 +1,7 @@ package test.novisitexceptions.impl; /** - * A concrete type without abstract super type. + * Implementation of {@link test.novisitexceptions.SimpleType}. */ public class SimpleType_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.novisitexceptions.SimpleType { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java index 17a6c0f5..40895fdf 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java @@ -1,5 +1,8 @@ package test.nullable.data.impl; +/** + * Implementation of {@link test.nullable.data.NullableValues}. + */ public class NullableValues_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nullable.data.NullableValues { private Integer _int = null; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/impl/SampleMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/impl/SampleMessage_Impl.java index 08e95ae8..a82a8c61 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/impl/SampleMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/oneoffield/data/impl/SampleMessage_Impl.java @@ -1,5 +1,8 @@ package test.oneoffield.data.impl; +/** + * Implementation of {@link test.oneoffield.data.SampleMessage}. + */ public class SampleMessage_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.oneoffield.data.SampleMessage { /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/AtomicShape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/AtomicShape_Impl.java index 3ad43460..f3e6f0f9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/AtomicShape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/AtomicShape_Impl.java @@ -1,7 +1,7 @@ package test.onlyxml.data.impl; /** - * A {@link Shape} that has no sub-shapes. + * Implementation of {@link test.onlyxml.data.AtomicShape}. */ public abstract class AtomicShape_Impl extends test.onlyxml.data.impl.Shape_Impl implements test.onlyxml.data.AtomicShape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Car_Impl.java index 4ef67b4d..6ccef537 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Car_Impl.java @@ -1,7 +1,7 @@ package test.onlyxml.data.impl; /** - * A special {@link Shape} that contains concrete monomorphic references to type in a polymorphic hierarchy. + * Implementation of {@link test.onlyxml.data.Car}. */ public class Car_Impl extends test.onlyxml.data.impl.Shape_Impl implements test.onlyxml.data.Car { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Circle_Impl.java index 2a61633d..8d33720a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Circle_Impl.java @@ -1,7 +1,7 @@ package test.onlyxml.data.impl; /** - * A circle {@link Shape}. + * Implementation of {@link test.onlyxml.data.Circle}. */ public class Circle_Impl extends test.onlyxml.data.impl.AtomicShape_Impl implements test.onlyxml.data.Circle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Group_Impl.java index 50a88fc4..c8500a8a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Group_Impl.java @@ -1,7 +1,7 @@ package test.onlyxml.data.impl; /** - * A group of shapes. + * Implementation of {@link test.onlyxml.data.Group}. */ public class Group_Impl extends test.onlyxml.data.impl.Shape_Impl implements test.onlyxml.data.Group { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Optional_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Optional_Impl.java index b99e5fb0..900548f1 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Optional_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Optional_Impl.java @@ -1,7 +1,7 @@ package test.onlyxml.data.impl; /** - * A shape that can be dynamically hidden. + * Implementation of {@link test.onlyxml.data.Optional}. */ public class Optional_Impl extends test.onlyxml.data.impl.Shape_Impl implements test.onlyxml.data.Optional { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Rectangle_Impl.java index 2a5c647c..2be64d9a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Rectangle_Impl.java @@ -1,7 +1,7 @@ package test.onlyxml.data.impl; /** - * A rectangle. + * Implementation of {@link test.onlyxml.data.Rectangle}. */ public class Rectangle_Impl extends test.onlyxml.data.impl.AtomicShape_Impl implements test.onlyxml.data.Rectangle { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Shape_Impl.java index 0308197f..91f8a977 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/Shape_Impl.java @@ -1,7 +1,7 @@ package test.onlyxml.data.impl; /** - * An abstract base class for all shapes + * Implementation of {@link test.onlyxml.data.Shape}. */ public abstract class Shape_Impl implements test.onlyxml.data.Shape { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/SimpleType_Impl.java index 68c042b1..31307968 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/onlyxml/data/impl/SimpleType_Impl.java @@ -1,7 +1,7 @@ package test.onlyxml.data.impl; /** - * A concrete type without abstract super type. + * Implementation of {@link test.onlyxml.data.SimpleType}. */ public class SimpleType_Impl implements test.onlyxml.data.SimpleType { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/impl/MyMessage1_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/impl/MyMessage1_Impl.java index 289d7f21..3ec25282 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/impl/MyMessage1_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/impl/MyMessage1_Impl.java @@ -1,5 +1,8 @@ package test.options.data.impl; +/** + * Implementation of {@link test.options.data.MyMessage1}. + */ public class MyMessage1_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.options.data.MyMessage1 { /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/impl/MyMessage2_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/impl/MyMessage2_Impl.java index 91220e12..3f3b1b16 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/options/data/impl/MyMessage2_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/options/data/impl/MyMessage2_Impl.java @@ -1,5 +1,8 @@ package test.options.data.impl; +/** + * Implementation of {@link test.options.data.MyMessage2}. + */ public class MyMessage2_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.options.data.MyMessage2 { /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java index 357a4134..8ca52b01 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java @@ -1,5 +1,8 @@ package test.references.data.impl; +/** + * Implementation of {@link test.references.data.A}. + */ public class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.references.data.A { private String _name = ""; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java index 67e02013..23105251 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java @@ -1,5 +1,8 @@ package test.references.data.impl; +/** + * Implementation of {@link test.references.data.B}. + */ public class B_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.references.data.B { private String _name = ""; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java index 5c0a80b7..fb01178a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java @@ -1,5 +1,8 @@ package test.types.data.impl; +/** + * Implementation of {@link test.types.data.SearchRequest}. + */ public class SearchRequest_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.types.data.SearchRequest { private String _query = ""; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java index 1beb94c0..9fe37b1a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java @@ -1,5 +1,8 @@ package test.underscorename.impl; +/** + * Implementation of {@link test.underscorename.AnnotatedMessage}. + */ public class AnnotatedMessage_Impl extends test.underscorename.impl.BaseMsg_Impl implements test.underscorename.AnnotatedMessage { private String _annotatedField = ""; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/BaseMsg_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/BaseMsg_Impl.java index 5c780b68..69de5b81 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/BaseMsg_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/BaseMsg_Impl.java @@ -1,5 +1,8 @@ package test.underscorename.impl; +/** + * Implementation of {@link test.underscorename.BaseMsg}. + */ public abstract class BaseMsg_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.underscorename.BaseMsg { /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java index 1a849651..55091833 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java @@ -1,5 +1,8 @@ package test.underscorename.impl; +/** + * Implementation of {@link test.underscorename.SomeName}. + */ public class SomeName_Impl extends test.underscorename.impl.BaseMsg_Impl implements test.underscorename.SomeName { private String _myField = ""; From 0a2a2083be8664628ea6e17ae7ffee1e41762279 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 19 May 2023 10:56:50 +0200 Subject: [PATCH 044/207] No duplicate type kind lookup declaration in abstract implementations. --- .../java/de/haumacher/msgbuf/generator/MessageGenerator.java | 2 +- .../src/test/java/test/graph/data/impl/Shape_Impl.java | 3 --- .../src/test/java/test/hierarchy/data/impl/Shape_Impl.java | 3 --- .../src/test/java/test/nojson/impl/Shape_Impl.java | 3 --- .../src/test/java/test/nolistener/impl/Shape_Impl.java | 3 --- .../src/test/java/test/novisit/impl/Shape_Impl.java | 3 --- .../src/test/java/test/novisitexceptions/impl/Shape_Impl.java | 3 --- .../src/test/java/test/underscorename/impl/BaseMsg_Impl.java | 3 --- 8 files changed, 1 insertion(+), 22 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index dd6666be..dbf19fc5 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -569,7 +569,7 @@ private void generateKindLookup() { } } else { if (_def.isAbstract()) { - if (isBaseClass()) { + if (_noInterfaces && isBaseClass()) { nl(); kindLookupComment(); line("public abstract " + TYPE_KIND_NAME + " kind();"); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java index 96bef0f1..e935d6bc 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java @@ -16,9 +16,6 @@ public Shape_Impl() { super(); } - /** The type code of this instance. */ - public abstract TypeKind kind(); - @Override public final int getXCoordinate() { return _xCoordinate; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java index 3cb1de6f..9537b535 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java @@ -18,9 +18,6 @@ public Shape_Impl() { super(); } - /** The type code of this instance. */ - public abstract TypeKind kind(); - @Override public final int getXCoordinate() { return _xCoordinate; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java index 772ab4b8..4e92eef9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java @@ -16,9 +16,6 @@ public Shape_Impl() { super(); } - /** The type code of this instance. */ - public abstract TypeKind kind(); - @Override public final int getXCoordinate() { return _xCoordinate; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java index 393b2bd7..96fba590 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java @@ -16,9 +16,6 @@ public Shape_Impl() { super(); } - /** The type code of this instance. */ - public abstract TypeKind kind(); - @Override public final int getXCoordinate() { return _xCoordinate; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java index b7d71b30..fcc69830 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java @@ -16,9 +16,6 @@ public Shape_Impl() { super(); } - /** The type code of this instance. */ - public abstract TypeKind kind(); - @Override public final int getXCoordinate() { return _xCoordinate; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java index 4207b3ba..d87d179e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java @@ -16,9 +16,6 @@ public Shape_Impl() { super(); } - /** The type code of this instance. */ - public abstract TypeKind kind(); - @Override public final int getXCoordinate() { return _xCoordinate; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/BaseMsg_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/BaseMsg_Impl.java index 69de5b81..f95b1f7e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/BaseMsg_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/BaseMsg_Impl.java @@ -12,9 +12,6 @@ public BaseMsg_Impl() { super(); } - /** The type code of this instance. */ - public abstract TypeKind kind(); - protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override From e80193debacd00a8fbc67b79bab27a3634aeb248 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 6 Dec 2023 09:16:40 +0100 Subject: [PATCH 045/207] Added access to ref option. --- .../de/haumacher/msgbuf/generator/FieldOperations.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java index 90151e5c..9dcc2962 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldOperations.java @@ -36,6 +36,12 @@ default boolean isContainer() { return self().getOptions().get("Container") != null; } + /** + * Whether this is a cross reference (not a composition which is the default). + */ + default boolean isRef() { + return self().getOptions().get("Ref") != null; + } /** * Whether this is a reverse reference. @@ -78,7 +84,7 @@ default Option getReverseAnnotation() { * null if no such field exists. */ default Field container() { - if (!isDerived()) { + if (!isDerived() && !isRef()) { Type contentType = self().getType(); if (contentType instanceof MapType) { contentType = ((MapType) contentType).getValueType(); From 6739249c8e114e82aa89de998f8cb3e5607e64fd Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 6 Dec 2023 09:20:42 +0100 Subject: [PATCH 046/207] [maven-release-plugin] prepare release msgbuf-api-1.1.3 --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 050fae43..8727e3e2 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.3-SNAPSHOT + 1.1.3 msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.3-SNAPSHOT + 1.1.3 diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index c9a7202e..dede8602 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.3-SNAPSHOT + 1.1.3 msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index c32fd7be..cac57dc3 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.3-SNAPSHOT + 1.1.3 msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.3-SNAPSHOT + 1.1.3 diff --git a/pom.xml b/pom.xml index c148e494..06061188 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.3-SNAPSHOT + 1.1.3 pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - HEAD + msgbuf-api-1.1.3 From c15cdddf2abe89e71db09987b5d63381d941d67d Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 6 Dec 2023 09:20:45 +0100 Subject: [PATCH 047/207] [maven-release-plugin] prepare for next development iteration --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 8727e3e2..c7f81ca2 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.3 + 1.1.4-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.3 + 1.1.4-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index dede8602..ace87833 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.3 + 1.1.4-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index cac57dc3..599c3eb6 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.3 + 1.1.4-SNAPSHOT msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.3 + 1.1.4-SNAPSHOT diff --git a/pom.xml b/pom.xml index 06061188..ec5d3ddf 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.3 + 1.1.4-SNAPSHOT pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - msgbuf-api-1.1.3 + HEAD From 5f890c2276f59bc1e2df635c422ff641108a6063 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 6 Dec 2023 09:27:28 +0100 Subject: [PATCH 048/207] Updated version number to 1.1.3 in README. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b0795432..f7382fb5 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ In contrast to `protobuf`, `msgbuf` supports: de.haumacher.msgbuf msgbuf-api - 1.1.2 + 1.1.3 ``` @@ -32,7 +32,7 @@ To the `build/plugins` section add: de.haumacher.msgbuf msgbuf-generator-maven-plugin - 1.1.2 + 1.1.3 From f2369d0b20892d8779d49467facf830f67cabc53 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 21 Jan 2024 10:36:57 +0100 Subject: [PATCH 049/207] Fixed typo in error message. --- .../msgbuf/generator/maven/GenerateMessageClasses.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java b/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java index 7ab16c10..6ee6d139 100644 --- a/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java +++ b/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java @@ -67,7 +67,7 @@ public void execute() throws MojoExecutionException { String[] args = argList.toArray(new String[0]); Generator.main(args); } catch (Throwable ex) { - throw new MojoExecutionException("Failed to invoke the generatore: " + ex.getMessage(), ex); + throw new MojoExecutionException("Failed to invoke the generator: " + ex.getMessage(), ex); } } From 86ff8228aa5a98d251c34b9f77405e5c2369139a Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 21 Jan 2024 10:37:32 +0100 Subject: [PATCH 050/207] Fixed NPE when generating message class with reference to external type. --- .../java/de/haumacher/msgbuf/generator/TypeGenerator.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/TypeGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/TypeGenerator.java index 4f1004e5..f80387b9 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/TypeGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/TypeGenerator.java @@ -8,6 +8,7 @@ import java.util.function.Function; import de.haumacher.msgbuf.generator.ast.CustomType; +import de.haumacher.msgbuf.generator.ast.Definition; import de.haumacher.msgbuf.generator.ast.Field; import de.haumacher.msgbuf.generator.ast.MapType; import de.haumacher.msgbuf.generator.ast.PrimitiveType; @@ -75,7 +76,11 @@ public String visit(MapType type, Boolean wrapped) { @Override public String visit(CustomType type, Boolean wrapped) { - return qName(_packageSuffix, type.getDefinition(), _typeNameConvention); + Definition definition = type.getDefinition(); + if (definition == null) { + return qName(type.getName()); + } + return qName(_packageSuffix, definition, _typeNameConvention); } @Override From 79bdb61613da605bc0cb7a38f7db0bae8deaae61 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 21 Jan 2024 10:49:16 +0100 Subject: [PATCH 051/207] Updated resources plugin. Necessary to be compatible with Eclipse 4.30. --- pom.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pom.xml b/pom.xml index ec5d3ddf..f2501096 100644 --- a/pom.xml +++ b/pom.xml @@ -153,5 +153,14 @@ To update dependencies to latest releases use: mvn versions:use-latest-releases --> + + + + org.apache.maven.plugins + maven-resources-plugin + 3.3.0 + + + \ No newline at end of file From e9b529f1846b645efea2dd9669bf8e01a699b10d Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 21 Jan 2024 10:49:52 +0100 Subject: [PATCH 052/207] Updated Eclipse settings. --- de.haumacher.msgbuf.eclipse/.classpath | 6 +++++- .../.settings/org.eclipse.jdt.core.prefs | 3 ++- de.haumacher.msgbuf.generator/.classpath | 2 +- de.haumacher.msgbuf/.classpath | 1 - 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/de.haumacher.msgbuf.eclipse/.classpath b/de.haumacher.msgbuf.eclipse/.classpath index fec2eab5..1c9b40d9 100644 --- a/de.haumacher.msgbuf.eclipse/.classpath +++ b/de.haumacher.msgbuf.eclipse/.classpath @@ -1,6 +1,10 @@ - + + + + + diff --git a/de.haumacher.msgbuf.eclipse/.settings/org.eclipse.jdt.core.prefs b/de.haumacher.msgbuf.eclipse/.settings/org.eclipse.jdt.core.prefs index f2525a8b..cd8d089a 100644 --- a/de.haumacher.msgbuf.eclipse/.settings/org.eclipse.jdt.core.prefs +++ b/de.haumacher.msgbuf.eclipse/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=11 @@ -10,5 +11,5 @@ org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning -org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=11 diff --git a/de.haumacher.msgbuf.generator/.classpath b/de.haumacher.msgbuf.generator/.classpath index 22b120f8..97c61224 100644 --- a/de.haumacher.msgbuf.generator/.classpath +++ b/de.haumacher.msgbuf.generator/.classpath @@ -1,6 +1,6 @@ - + diff --git a/de.haumacher.msgbuf/.classpath b/de.haumacher.msgbuf/.classpath index 88d9f461..e2008929 100644 --- a/de.haumacher.msgbuf/.classpath +++ b/de.haumacher.msgbuf/.classpath @@ -3,7 +3,6 @@ - From 7a827ed51939802c408df9e2fce90d576f7eb60f Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 21 Jan 2024 10:51:10 +0100 Subject: [PATCH 053/207] [maven-release-plugin] prepare release msgbuf-api-1.1.4 --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index c7f81ca2..761a4b01 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.4-SNAPSHOT + 1.1.4 msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.4-SNAPSHOT + 1.1.4 diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index ace87833..88966633 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.4-SNAPSHOT + 1.1.4 msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 599c3eb6..9dd9edf9 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.4-SNAPSHOT + 1.1.4 msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.4-SNAPSHOT + 1.1.4 diff --git a/pom.xml b/pom.xml index f2501096..c7690042 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.4-SNAPSHOT + 1.1.4 pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - HEAD + msgbuf-api-1.1.4 From 690f939c16df1cb3db41a196ed9b30c6ecf9a7f8 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 21 Jan 2024 10:51:12 +0100 Subject: [PATCH 054/207] [maven-release-plugin] prepare for next development iteration --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 761a4b01..de72fdcb 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.4 + 1.1.5-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.4 + 1.1.5-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 88966633..7d9da016 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.4 + 1.1.5-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 9dd9edf9..79ff10ab 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.4 + 1.1.5-SNAPSHOT msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.4 + 1.1.5-SNAPSHOT diff --git a/pom.xml b/pom.xml index c7690042..f23e5a48 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.4 + 1.1.5-SNAPSHOT pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - msgbuf-api-1.1.4 + HEAD From fba81a89c5c0d8dcacb7fe0f9d686e5e76fcd4ac Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 21 Jan 2024 10:58:18 +0100 Subject: [PATCH 055/207] Updated version in project README. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f7382fb5..8a408033 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ In contrast to `protobuf`, `msgbuf` supports: de.haumacher.msgbuf msgbuf-api - 1.1.3 + 1.1.4 ``` @@ -32,7 +32,7 @@ To the `build/plugins` section add: de.haumacher.msgbuf msgbuf-generator-maven-plugin - 1.1.3 + 1.1.4 From bcbfa3bfb9dbeab1806cae31cbab95caaac552d2 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 14 Apr 2024 17:38:36 +0200 Subject: [PATCH 056/207] Updated public key ID. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f23e5a48..eb3bdb46 100644 --- a/pom.xml +++ b/pom.xml @@ -98,7 +98,7 @@ maven-gpg-plugin 1.5 - 3FDEA7509C2E6ACFBAAE4E4C062F98BC833AC2BF + 401FE46033F5589B53443B0CBD126C2FB1395E37 From e45f5f100801372ed8a396a05b095b5f29514bdb Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 14 Apr 2024 18:11:59 +0200 Subject: [PATCH 057/207] Updated self-generated compiler AST. --- .../msgbuf/generator/ast/Constant.java | 24 +- .../msgbuf/generator/ast/CustomType.java | 52 ++--- .../msgbuf/generator/ast/Definition.java | 76 +++---- .../msgbuf/generator/ast/DefinitionBase.java | 32 +-- .../msgbuf/generator/ast/DefinitionFile.java | 76 +++---- .../msgbuf/generator/ast/EnumDef.java | 62 +++--- .../haumacher/msgbuf/generator/ast/Field.java | 85 ++++---- .../haumacher/msgbuf/generator/ast/Flag.java | 28 +-- .../msgbuf/generator/ast/MapType.java | 56 ++--- .../msgbuf/generator/ast/MessageDef.java | 206 +++++++++--------- .../msgbuf/generator/ast/NumberOption.java | 28 +-- .../msgbuf/generator/ast/Option.java | 30 +-- .../msgbuf/generator/ast/OptionContainer.java | 16 +- .../haumacher/msgbuf/generator/ast/Part.java | 74 +++---- .../msgbuf/generator/ast/PrimitiveType.java | 34 +-- .../haumacher/msgbuf/generator/ast/QName.java | 36 +-- .../msgbuf/generator/ast/StringOption.java | 28 +-- .../haumacher/msgbuf/generator/ast/Type.java | 30 +-- .../msgbuf/generator/ast/WithOptions.java | 72 +++--- .../msgbuf/generator/ast/proto.proto | 2 + 20 files changed, 530 insertions(+), 517 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Constant.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Constant.java index b304d4ac..bf50dabe 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Constant.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Constant.java @@ -8,19 +8,19 @@ public class Constant extends Part { /** - * Creates a {@link Constant} instance. + * Creates a {@link de.haumacher.msgbuf.generator.ast.Constant} instance. */ - public static Constant create() { + public static de.haumacher.msgbuf.generator.ast.Constant create() { return new de.haumacher.msgbuf.generator.ast.Constant(); } - /** Identifier for the {@link Constant} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.generator.ast.Constant} type in JSON format. */ public static final String CONSTANT__TYPE = "Constant"; /** * Creates a {@link Constant} instance. * - * @see Constant#create() + * @see de.haumacher.msgbuf.generator.ast.Constant#create() */ protected Constant() { super(); @@ -32,37 +32,37 @@ public TypeKind kind() { } @Override - public Constant setName(String value) { + public de.haumacher.msgbuf.generator.ast.Constant setName(String value) { internalSetName(value); return this; } @Override - public Constant setIndex(int value) { + public de.haumacher.msgbuf.generator.ast.Constant setIndex(int value) { internalSetIndex(value); return this; } @Override - public Constant setOwner(Definition value) { + public de.haumacher.msgbuf.generator.ast.Constant setOwner(de.haumacher.msgbuf.generator.ast.Definition value) { internalSetOwner(value); return this; } @Override - public Constant setComment(String value) { + public de.haumacher.msgbuf.generator.ast.Constant setComment(String value) { internalSetComment(value); return this; } @Override - public Constant setOptions(java.util.Map value) { + public de.haumacher.msgbuf.generator.ast.Constant setOptions(java.util.Map value) { internalSetOptions(value); return this; } @Override - public Constant putOption(String key, Option value) { + public de.haumacher.msgbuf.generator.ast.Constant putOption(String key, de.haumacher.msgbuf.generator.ast.Option value) { internalPutOption(key, value); return this; } @@ -73,14 +73,14 @@ public String jsonType() { } /** Reads a new instance from the given reader. */ - public static Constant readConstant(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.generator.ast.Constant readConstant(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { de.haumacher.msgbuf.generator.ast.Constant result = new de.haumacher.msgbuf.generator.ast.Constant(); result.readContent(in); return result; } @Override - public R visit(Part.Visitor v, A arg) { + public R visit(de.haumacher.msgbuf.generator.ast.Part.Visitor v, A arg) { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/CustomType.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/CustomType.java index 7e07ede9..f7755425 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/CustomType.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/CustomType.java @@ -8,29 +8,29 @@ public class CustomType extends Type { /** - * Creates a {@link CustomType} instance. + * Creates a {@link de.haumacher.msgbuf.generator.ast.CustomType} instance. */ - public static CustomType create() { + public static de.haumacher.msgbuf.generator.ast.CustomType create() { return new de.haumacher.msgbuf.generator.ast.CustomType(); } - /** Identifier for the {@link CustomType} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.generator.ast.CustomType} type in JSON format. */ public static final String CUSTOM_TYPE__TYPE = "CustomType"; /** @see #getName() */ - public static final String NAME = "name"; + public static final String NAME__PROP = "name"; /** @see #getDefinition() */ - public static final String DEFINITION = "definition"; + public static final String DEFINITION__PROP = "definition"; - private QName _name = null; + private de.haumacher.msgbuf.generator.ast.QName _name = null; - private transient Definition _definition = null; + private transient de.haumacher.msgbuf.generator.ast.Definition _definition = null; /** * Creates a {@link CustomType} instance. * - * @see CustomType#create() + * @see de.haumacher.msgbuf.generator.ast.CustomType#create() */ protected CustomType() { super(); @@ -44,21 +44,21 @@ public TypeKind kind() { /** * The name of the reference type. */ - public final QName getName() { + public final de.haumacher.msgbuf.generator.ast.QName getName() { return _name; } /** * @see #getName() */ - public CustomType setName(QName value) { + public de.haumacher.msgbuf.generator.ast.CustomType setName(de.haumacher.msgbuf.generator.ast.QName value) { internalSetName(value); return this; } /** Internal setter for {@link #getName()} without chain call utility. */ - protected final void internalSetName(QName value) { - _listener.beforeSet(this, NAME, value); + protected final void internalSetName(de.haumacher.msgbuf.generator.ast.QName value) { + _listener.beforeSet(this, NAME__PROP, value); _name = value; } @@ -72,21 +72,21 @@ public final boolean hasName() { /** * Resolved reference of the {@link Definition} defining the {@link #getName() referenced type}. */ - public final Definition getDefinition() { + public final de.haumacher.msgbuf.generator.ast.Definition getDefinition() { return _definition; } /** * @see #getDefinition() */ - public CustomType setDefinition(Definition value) { + public de.haumacher.msgbuf.generator.ast.CustomType setDefinition(de.haumacher.msgbuf.generator.ast.Definition value) { internalSetDefinition(value); return this; } /** Internal setter for {@link #getDefinition()} without chain call utility. */ - protected final void internalSetDefinition(Definition value) { - _listener.beforeSet(this, DEFINITION, value); + protected final void internalSetDefinition(de.haumacher.msgbuf.generator.ast.Definition value) { + _listener.beforeSet(this, DEFINITION__PROP, value); _definition = value; } @@ -104,8 +104,8 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - NAME, - DEFINITION)); + NAME__PROP, + DEFINITION__PROP)); @Override public java.util.List properties() { @@ -115,8 +115,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case NAME: return getName(); - case DEFINITION: return getDefinition(); + case NAME__PROP: return getName(); + case DEFINITION__PROP: return getDefinition(); default: return super.get(field); } } @@ -124,14 +124,14 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case NAME: internalSetName((QName) value); break; - case DEFINITION: internalSetDefinition((Definition) value); break; + case NAME__PROP: internalSetName((de.haumacher.msgbuf.generator.ast.QName) value); break; + case DEFINITION__PROP: internalSetDefinition((de.haumacher.msgbuf.generator.ast.Definition) value); break; default: super.set(field, value); break; } } /** Reads a new instance from the given reader. */ - public static CustomType readCustomType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.generator.ast.CustomType readCustomType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { de.haumacher.msgbuf.generator.ast.CustomType result = new de.haumacher.msgbuf.generator.ast.CustomType(); result.readContent(in); return result; @@ -141,7 +141,7 @@ public static CustomType readCustomType(de.haumacher.msgbuf.json.JsonReader in) protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); if (hasName()) { - out.name(NAME); + out.name(NAME__PROP); getName().writeTo(out); } } @@ -149,13 +149,13 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case NAME: setName(de.haumacher.msgbuf.generator.ast.QName.readQName(in)); break; + case NAME__PROP: setName(de.haumacher.msgbuf.generator.ast.QName.readQName(in)); break; default: super.readField(in, field); } } @Override - public R visit(Type.Visitor v, A arg) { + public R visit(de.haumacher.msgbuf.generator.ast.Type.Visitor v, A arg) { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Definition.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Definition.java index cd3cca32..3583d210 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Definition.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Definition.java @@ -5,31 +5,31 @@ */ public abstract class Definition extends DefinitionBase { - /** Visitor interface for the {@link Definition} hierarchy.*/ + /** Visitor interface for the {@link de.haumacher.msgbuf.generator.ast.Definition} hierarchy.*/ public interface Visitor { - /** Visit case for {@link EnumDef}.*/ - R visit(EnumDef self, A arg); + /** Visit case for {@link de.haumacher.msgbuf.generator.ast.EnumDef}.*/ + R visit(de.haumacher.msgbuf.generator.ast.EnumDef self, A arg); - /** Visit case for {@link MessageDef}.*/ - R visit(MessageDef self, A arg); + /** Visit case for {@link de.haumacher.msgbuf.generator.ast.MessageDef}.*/ + R visit(de.haumacher.msgbuf.generator.ast.MessageDef self, A arg); } /** @see #getName() */ - public static final String NAME = "name"; + public static final String NAME__PROP = "name"; /** @see #getFile() */ - public static final String FILE = "file"; + public static final String FILE__PROP = "file"; /** @see #getOuter() */ - public static final String OUTER = "outer"; + public static final String OUTER__PROP = "outer"; private String _name = ""; - private transient DefinitionFile _file = null; + private transient de.haumacher.msgbuf.generator.ast.DefinitionFile _file = null; - private transient MessageDef _outer = null; + private transient de.haumacher.msgbuf.generator.ast.MessageDef _outer = null; /** * Creates a {@link Definition} instance. @@ -48,35 +48,35 @@ public final String getName() { /** * @see #getName() */ - public Definition setName(String value) { + public de.haumacher.msgbuf.generator.ast.Definition setName(String value) { internalSetName(value); return this; } /** Internal setter for {@link #getName()} without chain call utility. */ protected final void internalSetName(String value) { - _listener.beforeSet(this, NAME, value); + _listener.beforeSet(this, NAME__PROP, value); _name = value; } /** * Reference back to the {@link DefinitionFile} that contains this definition. */ - public final DefinitionFile getFile() { + public final de.haumacher.msgbuf.generator.ast.DefinitionFile getFile() { return _file; } /** * @see #getFile() */ - public Definition setFile(DefinitionFile value) { + public de.haumacher.msgbuf.generator.ast.Definition setFile(de.haumacher.msgbuf.generator.ast.DefinitionFile value) { internalSetFile(value); return this; } /** Internal setter for {@link #getFile()} without chain call utility. */ - protected final void internalSetFile(DefinitionFile value) { - _listener.beforeSet(this, FILE, value); + protected final void internalSetFile(de.haumacher.msgbuf.generator.ast.DefinitionFile value) { + _listener.beforeSet(this, FILE__PROP, value); _file = value; } @@ -94,21 +94,21 @@ public final boolean hasFile() { * The value is null for top-level defintions, see {@link #getFile()}. *

*/ - public final MessageDef getOuter() { + public final de.haumacher.msgbuf.generator.ast.MessageDef getOuter() { return _outer; } /** * @see #getOuter() */ - public Definition setOuter(MessageDef value) { + public de.haumacher.msgbuf.generator.ast.Definition setOuter(de.haumacher.msgbuf.generator.ast.MessageDef value) { internalSetOuter(value); return this; } /** Internal setter for {@link #getOuter()} without chain call utility. */ - protected final void internalSetOuter(MessageDef value) { - _listener.beforeSet(this, OUTER, value); + protected final void internalSetOuter(de.haumacher.msgbuf.generator.ast.MessageDef value) { + _listener.beforeSet(this, OUTER__PROP, value); _outer = value; } @@ -120,28 +120,28 @@ public final boolean hasOuter() { } @Override - public Definition setComment(String value) { + public de.haumacher.msgbuf.generator.ast.Definition setComment(String value) { internalSetComment(value); return this; } @Override - public Definition setOptions(java.util.Map value) { + public de.haumacher.msgbuf.generator.ast.Definition setOptions(java.util.Map value) { internalSetOptions(value); return this; } @Override - public Definition putOption(String key, Option value) { + public de.haumacher.msgbuf.generator.ast.Definition putOption(String key, de.haumacher.msgbuf.generator.ast.Option value) { internalPutOption(key, value); return this; } private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - NAME, - FILE, - OUTER)); + NAME__PROP, + FILE__PROP, + OUTER__PROP)); @Override public java.util.List properties() { @@ -151,9 +151,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case NAME: return getName(); - case FILE: return getFile(); - case OUTER: return getOuter(); + case NAME__PROP: return getName(); + case FILE__PROP: return getFile(); + case OUTER__PROP: return getOuter(); default: return super.get(field); } } @@ -161,16 +161,16 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case NAME: internalSetName((String) value); break; - case FILE: internalSetFile((DefinitionFile) value); break; - case OUTER: internalSetOuter((MessageDef) value); break; + case NAME__PROP: internalSetName((String) value); break; + case FILE__PROP: internalSetFile((de.haumacher.msgbuf.generator.ast.DefinitionFile) value); break; + case OUTER__PROP: internalSetOuter((de.haumacher.msgbuf.generator.ast.MessageDef) value); break; default: super.set(field, value); break; } } /** Reads a new instance from the given reader. */ - public static Definition readDefinition(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - Definition result; + public static de.haumacher.msgbuf.generator.ast.Definition readDefinition(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.generator.ast.Definition result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -185,14 +185,14 @@ public static Definition readDefinition(de.haumacher.msgbuf.json.JsonReader in) @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(NAME); + out.name(NAME__PROP); out.value(getName()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case NAME: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; default: super.readField(in, field); } } @@ -201,8 +201,8 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t public abstract R visit(Visitor v, A arg); @Override - public final R visit(DefinitionBase.Visitor v, A arg) { - return visit((Definition.Visitor) v, arg); + public final R visit(de.haumacher.msgbuf.generator.ast.DefinitionBase.Visitor v, A arg) { + return visit((de.haumacher.msgbuf.generator.ast.Definition.Visitor) v, arg); } } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionBase.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionBase.java index dccfdd8b..768a4070 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionBase.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionBase.java @@ -5,15 +5,15 @@ */ public abstract class DefinitionBase extends WithOptions { - /** Visitor interface for the {@link DefinitionBase} hierarchy.*/ - public interface Visitor extends Part.Visitor, Definition.Visitor { + /** Visitor interface for the {@link de.haumacher.msgbuf.generator.ast.DefinitionBase} hierarchy.*/ + public interface Visitor extends de.haumacher.msgbuf.generator.ast.Part.Visitor, de.haumacher.msgbuf.generator.ast.Definition.Visitor { // Pure sum interface. } /** @see #getComment() */ - public static final String COMMENT = "comment"; + public static final String COMMENT__PROP = "comment"; private String _comment = ""; @@ -34,32 +34,32 @@ public final String getComment() { /** * @see #getComment() */ - public DefinitionBase setComment(String value) { + public de.haumacher.msgbuf.generator.ast.DefinitionBase setComment(String value) { internalSetComment(value); return this; } /** Internal setter for {@link #getComment()} without chain call utility. */ protected final void internalSetComment(String value) { - _listener.beforeSet(this, COMMENT, value); + _listener.beforeSet(this, COMMENT__PROP, value); _comment = value; } @Override - public DefinitionBase setOptions(java.util.Map value) { + public de.haumacher.msgbuf.generator.ast.DefinitionBase setOptions(java.util.Map value) { internalSetOptions(value); return this; } @Override - public DefinitionBase putOption(String key, Option value) { + public de.haumacher.msgbuf.generator.ast.DefinitionBase putOption(String key, de.haumacher.msgbuf.generator.ast.Option value) { internalPutOption(key, value); return this; } private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - COMMENT)); + COMMENT__PROP)); @Override public java.util.List properties() { @@ -69,7 +69,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case COMMENT: return getComment(); + case COMMENT__PROP: return getComment(); default: return super.get(field); } } @@ -77,14 +77,14 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case COMMENT: internalSetComment((String) value); break; + case COMMENT__PROP: internalSetComment((String) value); break; default: super.set(field, value); break; } } /** Reads a new instance from the given reader. */ - public static DefinitionBase readDefinitionBase(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - DefinitionBase result; + public static de.haumacher.msgbuf.generator.ast.DefinitionBase readDefinitionBase(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.generator.ast.DefinitionBase result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -101,14 +101,14 @@ public static DefinitionBase readDefinitionBase(de.haumacher.msgbuf.json.JsonRea @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(COMMENT); + out.name(COMMENT__PROP); out.value(getComment()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case COMMENT: setComment(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case COMMENT__PROP: setComment(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; default: super.readField(in, field); } } @@ -117,8 +117,8 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t public abstract R visit(Visitor v, A arg); @Override - public final R visit(WithOptions.Visitor v, A arg) { - return visit((DefinitionBase.Visitor) v, arg); + public final R visit(de.haumacher.msgbuf.generator.ast.WithOptions.Visitor v, A arg) { + return visit((de.haumacher.msgbuf.generator.ast.DefinitionBase.Visitor) v, arg); } } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java index 7c665f9f..52d74c99 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java @@ -8,39 +8,39 @@ public class DefinitionFile extends WithOptions { /** - * Creates a {@link DefinitionFile} instance. + * Creates a {@link de.haumacher.msgbuf.generator.ast.DefinitionFile} instance. */ - public static DefinitionFile create() { + public static de.haumacher.msgbuf.generator.ast.DefinitionFile create() { return new de.haumacher.msgbuf.generator.ast.DefinitionFile(); } - /** Identifier for the {@link DefinitionFile} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.generator.ast.DefinitionFile} type in JSON format. */ public static final String DEFINITION_FILE__TYPE = "DefinitionFile"; /** @see #getPackage() */ - public static final String PACKAGE = "package"; + public static final String PACKAGE__PROP = "package"; /** @see #getDefinitions() */ - public static final String DEFINITIONS = "definitions"; + public static final String DEFINITIONS__PROP = "definitions"; - private QName _package = null; + private de.haumacher.msgbuf.generator.ast.QName _package = null; - private final java.util.List _definitions = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _definitions = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override - protected void beforeAdd(int index, Definition element) { - _listener.beforeAdd(DefinitionFile.this, DEFINITIONS, index, element); + protected void beforeAdd(int index, de.haumacher.msgbuf.generator.ast.Definition element) { + _listener.beforeAdd(DefinitionFile.this, DEFINITIONS__PROP, index, element); } @Override - protected void afterRemove(int index, Definition element) { - _listener.afterRemove(DefinitionFile.this, DEFINITIONS, index, element); + protected void afterRemove(int index, de.haumacher.msgbuf.generator.ast.Definition element) { + _listener.afterRemove(DefinitionFile.this, DEFINITIONS__PROP, index, element); } }; /** * Creates a {@link DefinitionFile} instance. * - * @see DefinitionFile#create() + * @see de.haumacher.msgbuf.generator.ast.DefinitionFile#create() */ protected DefinitionFile() { super(); @@ -54,21 +54,21 @@ public TypeKind kind() { /** * The package name for all types in this file. */ - public final QName getPackage() { + public final de.haumacher.msgbuf.generator.ast.QName getPackage() { return _package; } /** * @see #getPackage() */ - public DefinitionFile setPackage(QName value) { + public de.haumacher.msgbuf.generator.ast.DefinitionFile setPackage(de.haumacher.msgbuf.generator.ast.QName value) { internalSetPackage(value); return this; } /** Internal setter for {@link #getPackage()} without chain call utility. */ - protected final void internalSetPackage(QName value) { - _listener.beforeSet(this, PACKAGE, value); + protected final void internalSetPackage(de.haumacher.msgbuf.generator.ast.QName value) { + _listener.beforeSet(this, PACKAGE__PROP, value); _package = value; } @@ -82,20 +82,20 @@ public final boolean hasPackage() { /** * All definitions in this file. */ - public final java.util.List getDefinitions() { + public final java.util.List getDefinitions() { return _definitions; } /** * @see #getDefinitions() */ - public DefinitionFile setDefinitions(java.util.List value) { + public de.haumacher.msgbuf.generator.ast.DefinitionFile setDefinitions(java.util.List value) { internalSetDefinitions(value); return this; } /** Internal setter for {@link #getDefinitions()} without chain call utility. */ - protected final void internalSetDefinitions(java.util.List value) { + protected final void internalSetDefinitions(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'definitions' cannot be null."); _definitions.clear(); _definitions.addAll(value); @@ -104,31 +104,31 @@ protected final void internalSetDefinitions(java.util.List /** * Adds a value to the {@link #getDefinitions()} list. */ - public DefinitionFile addDefinition(Definition value) { + public de.haumacher.msgbuf.generator.ast.DefinitionFile addDefinition(de.haumacher.msgbuf.generator.ast.Definition value) { internalAddDefinition(value); return this; } - /** Implementation of {@link #addDefinition(Definition)} without chain call utility. */ - protected final void internalAddDefinition(Definition value) { + /** Implementation of {@link #addDefinition(de.haumacher.msgbuf.generator.ast.Definition)} without chain call utility. */ + protected final void internalAddDefinition(de.haumacher.msgbuf.generator.ast.Definition value) { _definitions.add(value); } /** * Removes a value from the {@link #getDefinitions()} list. */ - public final void removeDefinition(Definition value) { + public final void removeDefinition(de.haumacher.msgbuf.generator.ast.Definition value) { _definitions.remove(value); } @Override - public DefinitionFile setOptions(java.util.Map value) { + public de.haumacher.msgbuf.generator.ast.DefinitionFile setOptions(java.util.Map value) { internalSetOptions(value); return this; } @Override - public DefinitionFile putOption(String key, Option value) { + public de.haumacher.msgbuf.generator.ast.DefinitionFile putOption(String key, de.haumacher.msgbuf.generator.ast.Option value) { internalPutOption(key, value); return this; } @@ -140,8 +140,8 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - PACKAGE, - DEFINITIONS)); + PACKAGE__PROP, + DEFINITIONS__PROP)); @Override public java.util.List properties() { @@ -151,8 +151,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case PACKAGE: return getPackage(); - case DEFINITIONS: return getDefinitions(); + case PACKAGE__PROP: return getPackage(); + case DEFINITIONS__PROP: return getDefinitions(); default: return super.get(field); } } @@ -160,14 +160,14 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case PACKAGE: internalSetPackage((QName) value); break; - case DEFINITIONS: internalSetDefinitions(de.haumacher.msgbuf.util.Conversions.asList(Definition.class, value)); break; + case PACKAGE__PROP: internalSetPackage((de.haumacher.msgbuf.generator.ast.QName) value); break; + case DEFINITIONS__PROP: internalSetDefinitions(de.haumacher.msgbuf.util.Conversions.asList(de.haumacher.msgbuf.generator.ast.Definition.class, value)); break; default: super.set(field, value); break; } } /** Reads a new instance from the given reader. */ - public static DefinitionFile readDefinitionFile(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.generator.ast.DefinitionFile readDefinitionFile(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { de.haumacher.msgbuf.generator.ast.DefinitionFile result = new de.haumacher.msgbuf.generator.ast.DefinitionFile(); result.readContent(in); return result; @@ -177,12 +177,12 @@ public static DefinitionFile readDefinitionFile(de.haumacher.msgbuf.json.JsonRea protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); if (hasPackage()) { - out.name(PACKAGE); + out.name(PACKAGE__PROP); getPackage().writeTo(out); } - out.name(DEFINITIONS); + out.name(DEFINITIONS__PROP); out.beginArray(); - for (Definition x : getDefinitions()) { + for (de.haumacher.msgbuf.generator.ast.Definition x : getDefinitions()) { x.writeTo(out); } out.endArray(); @@ -191,8 +191,8 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case PACKAGE: setPackage(de.haumacher.msgbuf.generator.ast.QName.readQName(in)); break; - case DEFINITIONS: { + case PACKAGE__PROP: setPackage(de.haumacher.msgbuf.generator.ast.QName.readQName(in)); break; + case DEFINITIONS__PROP: { in.beginArray(); while (in.hasNext()) { addDefinition(de.haumacher.msgbuf.generator.ast.Definition.readDefinition(in)); @@ -205,7 +205,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t } @Override - public R visit(WithOptions.Visitor v, A arg) { + public R visit(de.haumacher.msgbuf.generator.ast.WithOptions.Visitor v, A arg) { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/EnumDef.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/EnumDef.java index 5b8fef18..00166bfa 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/EnumDef.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/EnumDef.java @@ -6,34 +6,34 @@ public class EnumDef extends Definition { /** - * Creates a {@link EnumDef} instance. + * Creates a {@link de.haumacher.msgbuf.generator.ast.EnumDef} instance. */ - public static EnumDef create() { + public static de.haumacher.msgbuf.generator.ast.EnumDef create() { return new de.haumacher.msgbuf.generator.ast.EnumDef(); } - /** Identifier for the {@link EnumDef} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.generator.ast.EnumDef} type in JSON format. */ public static final String ENUM_DEF__TYPE = "EnumDef"; /** @see #getConstants() */ - public static final String CONSTANTS = "constants"; + public static final String CONSTANTS__PROP = "constants"; - private final java.util.List _constants = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _constants = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override - protected void beforeAdd(int index, Constant element) { - _listener.beforeAdd(EnumDef.this, CONSTANTS, index, element); + protected void beforeAdd(int index, de.haumacher.msgbuf.generator.ast.Constant element) { + _listener.beforeAdd(EnumDef.this, CONSTANTS__PROP, index, element); } @Override - protected void afterRemove(int index, Constant element) { - _listener.afterRemove(EnumDef.this, CONSTANTS, index, element); + protected void afterRemove(int index, de.haumacher.msgbuf.generator.ast.Constant element) { + _listener.afterRemove(EnumDef.this, CONSTANTS__PROP, index, element); } }; /** * Creates a {@link EnumDef} instance. * - * @see EnumDef#create() + * @see de.haumacher.msgbuf.generator.ast.EnumDef#create() */ protected EnumDef() { super(); @@ -47,20 +47,20 @@ public TypeKind kind() { /** * All enum constants of this enumeration */ - public final java.util.List getConstants() { + public final java.util.List getConstants() { return _constants; } /** * @see #getConstants() */ - public EnumDef setConstants(java.util.List value) { + public de.haumacher.msgbuf.generator.ast.EnumDef setConstants(java.util.List value) { internalSetConstants(value); return this; } /** Internal setter for {@link #getConstants()} without chain call utility. */ - protected final void internalSetConstants(java.util.List value) { + protected final void internalSetConstants(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'constants' cannot be null."); _constants.clear(); _constants.addAll(value); @@ -69,55 +69,55 @@ protected final void internalSetConstants(java.util.List val /** * Adds a value to the {@link #getConstants()} list. */ - public EnumDef addConstant(Constant value) { + public de.haumacher.msgbuf.generator.ast.EnumDef addConstant(de.haumacher.msgbuf.generator.ast.Constant value) { internalAddConstant(value); return this; } - /** Implementation of {@link #addConstant(Constant)} without chain call utility. */ - protected final void internalAddConstant(Constant value) { + /** Implementation of {@link #addConstant(de.haumacher.msgbuf.generator.ast.Constant)} without chain call utility. */ + protected final void internalAddConstant(de.haumacher.msgbuf.generator.ast.Constant value) { _constants.add(value); } /** * Removes a value from the {@link #getConstants()} list. */ - public final void removeConstant(Constant value) { + public final void removeConstant(de.haumacher.msgbuf.generator.ast.Constant value) { _constants.remove(value); } @Override - public EnumDef setName(String value) { + public de.haumacher.msgbuf.generator.ast.EnumDef setName(String value) { internalSetName(value); return this; } @Override - public EnumDef setFile(DefinitionFile value) { + public de.haumacher.msgbuf.generator.ast.EnumDef setFile(de.haumacher.msgbuf.generator.ast.DefinitionFile value) { internalSetFile(value); return this; } @Override - public EnumDef setOuter(MessageDef value) { + public de.haumacher.msgbuf.generator.ast.EnumDef setOuter(de.haumacher.msgbuf.generator.ast.MessageDef value) { internalSetOuter(value); return this; } @Override - public EnumDef setComment(String value) { + public de.haumacher.msgbuf.generator.ast.EnumDef setComment(String value) { internalSetComment(value); return this; } @Override - public EnumDef setOptions(java.util.Map value) { + public de.haumacher.msgbuf.generator.ast.EnumDef setOptions(java.util.Map value) { internalSetOptions(value); return this; } @Override - public EnumDef putOption(String key, Option value) { + public de.haumacher.msgbuf.generator.ast.EnumDef putOption(String key, de.haumacher.msgbuf.generator.ast.Option value) { internalPutOption(key, value); return this; } @@ -129,7 +129,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - CONSTANTS)); + CONSTANTS__PROP)); @Override public java.util.List properties() { @@ -139,7 +139,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case CONSTANTS: return getConstants(); + case CONSTANTS__PROP: return getConstants(); default: return super.get(field); } } @@ -147,13 +147,13 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case CONSTANTS: internalSetConstants(de.haumacher.msgbuf.util.Conversions.asList(Constant.class, value)); break; + case CONSTANTS__PROP: internalSetConstants(de.haumacher.msgbuf.util.Conversions.asList(de.haumacher.msgbuf.generator.ast.Constant.class, value)); break; default: super.set(field, value); break; } } /** Reads a new instance from the given reader. */ - public static EnumDef readEnumDef(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.generator.ast.EnumDef readEnumDef(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { de.haumacher.msgbuf.generator.ast.EnumDef result = new de.haumacher.msgbuf.generator.ast.EnumDef(); result.readContent(in); return result; @@ -162,9 +162,9 @@ public static EnumDef readEnumDef(de.haumacher.msgbuf.json.JsonReader in) throws @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(CONSTANTS); + out.name(CONSTANTS__PROP); out.beginArray(); - for (Constant x : getConstants()) { + for (de.haumacher.msgbuf.generator.ast.Constant x : getConstants()) { x.writeContent(out); } out.endArray(); @@ -173,7 +173,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case CONSTANTS: { + case CONSTANTS__PROP: { in.beginArray(); while (in.hasNext()) { addConstant(de.haumacher.msgbuf.generator.ast.Constant.readConstant(in)); @@ -186,7 +186,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t } @Override - public R visit(Definition.Visitor v, A arg) { + public R visit(de.haumacher.msgbuf.generator.ast.Definition.Visitor v, A arg) { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java index 2c1aee7d..a25cdc59 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java @@ -6,34 +6,34 @@ public class Field extends Part implements de.haumacher.msgbuf.generator.FieldOperations { /** - * Creates a {@link Field} instance. + * Creates a {@link de.haumacher.msgbuf.generator.ast.Field} instance. */ - public static Field create() { + public static de.haumacher.msgbuf.generator.ast.Field create() { return new de.haumacher.msgbuf.generator.ast.Field(); } - /** Identifier for the {@link Field} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.generator.ast.Field} type in JSON format. */ public static final String FIELD__TYPE = "Field"; /** @see #isTransient() */ - public static final String TRANSIENT = "transient"; + public static final String TRANSIENT__PROP = "transient"; /** @see #isRepeated() */ - public static final String REPEATED = "repeated"; + public static final String REPEATED__PROP = "repeated"; /** @see #getType() */ - public static final String TYPE = "type"; + public static final String TYPE__PROP = "type"; private boolean _transient = false; private boolean _repeated = false; - private Type _type = null; + private de.haumacher.msgbuf.generator.ast.Type _type = null; /** * Creates a {@link Field} instance. * - * @see Field#create() + * @see de.haumacher.msgbuf.generator.ast.Field#create() */ protected Field() { super(); @@ -54,14 +54,14 @@ public final boolean isTransient() { /** * @see #isTransient() */ - public Field setTransient(boolean value) { + public de.haumacher.msgbuf.generator.ast.Field setTransient(boolean value) { internalSetTransient(value); return this; } /** Internal setter for {@link #isTransient()} without chain call utility. */ protected final void internalSetTransient(boolean value) { - _listener.beforeSet(this, TRANSIENT, value); + _listener.beforeSet(this, TRANSIENT__PROP, value); _transient = value; } @@ -75,35 +75,35 @@ public final boolean isRepeated() { /** * @see #isRepeated() */ - public Field setRepeated(boolean value) { + public de.haumacher.msgbuf.generator.ast.Field setRepeated(boolean value) { internalSetRepeated(value); return this; } /** Internal setter for {@link #isRepeated()} without chain call utility. */ protected final void internalSetRepeated(boolean value) { - _listener.beforeSet(this, REPEATED, value); + _listener.beforeSet(this, REPEATED__PROP, value); _repeated = value; } /** * The type of values that can be stored in this field. */ - public final Type getType() { + public final de.haumacher.msgbuf.generator.ast.Type getType() { return _type; } /** * @see #getType() */ - public Field setType(Type value) { + public de.haumacher.msgbuf.generator.ast.Field setType(de.haumacher.msgbuf.generator.ast.Type value) { internalSetType(value); return this; } /** Internal setter for {@link #getType()} without chain call utility. */ - protected final void internalSetType(Type value) { - _listener.beforeSet(this, TYPE, value); + protected final void internalSetType(de.haumacher.msgbuf.generator.ast.Type value) { + _listener.beforeSet(this, TYPE__PROP, value); _type = value; } @@ -115,37 +115,37 @@ public final boolean hasType() { } @Override - public Field setName(String value) { + public de.haumacher.msgbuf.generator.ast.Field setName(String value) { internalSetName(value); return this; } @Override - public Field setIndex(int value) { + public de.haumacher.msgbuf.generator.ast.Field setIndex(int value) { internalSetIndex(value); return this; } @Override - public Field setOwner(Definition value) { + public de.haumacher.msgbuf.generator.ast.Field setOwner(de.haumacher.msgbuf.generator.ast.Definition value) { internalSetOwner(value); return this; } @Override - public Field setComment(String value) { + public de.haumacher.msgbuf.generator.ast.Field setComment(String value) { internalSetComment(value); return this; } @Override - public Field setOptions(java.util.Map value) { + public de.haumacher.msgbuf.generator.ast.Field setOptions(java.util.Map value) { internalSetOptions(value); return this; } @Override - public Field putOption(String key, Option value) { + public de.haumacher.msgbuf.generator.ast.Field putOption(String key, de.haumacher.msgbuf.generator.ast.Option value) { internalPutOption(key, value); return this; } @@ -157,9 +157,9 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - TRANSIENT, - REPEATED, - TYPE)); + TRANSIENT__PROP, + REPEATED__PROP, + TYPE__PROP)); @Override public java.util.List properties() { @@ -169,9 +169,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case TRANSIENT: return isTransient(); - case REPEATED: return isRepeated(); - case TYPE: return getType(); + case TRANSIENT__PROP: return isTransient(); + case REPEATED__PROP: return isRepeated(); + case TYPE__PROP: return getType(); default: return super.get(field); } } @@ -179,15 +179,15 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case TRANSIENT: internalSetTransient((boolean) value); break; - case REPEATED: internalSetRepeated((boolean) value); break; - case TYPE: internalSetType((Type) value); break; + case TRANSIENT__PROP: internalSetTransient((boolean) value); break; + case REPEATED__PROP: internalSetRepeated((boolean) value); break; + case TYPE__PROP: internalSetType((de.haumacher.msgbuf.generator.ast.Type) value); break; default: super.set(field, value); break; } } /** Reads a new instance from the given reader. */ - public static Field readField(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.generator.ast.Field readField(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { de.haumacher.msgbuf.generator.ast.Field result = new de.haumacher.msgbuf.generator.ast.Field(); result.readContent(in); return result; @@ -196,12 +196,12 @@ public static Field readField(de.haumacher.msgbuf.json.JsonReader in) throws jav @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(TRANSIENT); + out.name(TRANSIENT__PROP); out.value(isTransient()); - out.name(REPEATED); + out.name(REPEATED__PROP); out.value(isRepeated()); if (hasType()) { - out.name(TYPE); + out.name(TYPE__PROP); getType().writeTo(out); } } @@ -209,20 +209,21 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case TRANSIENT: setTransient(in.nextBoolean()); break; - case REPEATED: setRepeated(in.nextBoolean()); break; - case TYPE: setType(de.haumacher.msgbuf.generator.ast.Type.readType(in)); break; + case TRANSIENT__PROP: setTransient(in.nextBoolean()); break; + case REPEATED__PROP: setRepeated(in.nextBoolean()); break; + case TYPE__PROP: setType(de.haumacher.msgbuf.generator.ast.Type.readType(in)); break; default: super.readField(in, field); } } @Override - public R visit(Part.Visitor v, A arg) { - return v.visit(this, arg); + public Field self() { + return this; } @Override - public Field self() { - return this; + public R visit(de.haumacher.msgbuf.generator.ast.Part.Visitor v, A arg) { + return v.visit(this, arg); } + } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Flag.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Flag.java index c80cfbec..5968d714 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Flag.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Flag.java @@ -6,24 +6,24 @@ public class Flag extends Option { /** - * Creates a {@link Flag} instance. + * Creates a {@link de.haumacher.msgbuf.generator.ast.Flag} instance. */ - public static Flag create() { + public static de.haumacher.msgbuf.generator.ast.Flag create() { return new de.haumacher.msgbuf.generator.ast.Flag(); } - /** Identifier for the {@link Flag} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.generator.ast.Flag} type in JSON format. */ public static final String FLAG__TYPE = "Flag"; /** @see #isValue() */ - public static final String VALUE = "value"; + public static final String VALUE__PROP = "value"; private boolean _value = false; /** * Creates a {@link Flag} instance. * - * @see Flag#create() + * @see de.haumacher.msgbuf.generator.ast.Flag#create() */ protected Flag() { super(); @@ -44,14 +44,14 @@ public final boolean isValue() { /** * @see #isValue() */ - public Flag setValue(boolean value) { + public de.haumacher.msgbuf.generator.ast.Flag setValue(boolean value) { internalSetValue(value); return this; } /** Internal setter for {@link #isValue()} without chain call utility. */ protected final void internalSetValue(boolean value) { - _listener.beforeSet(this, VALUE, value); + _listener.beforeSet(this, VALUE__PROP, value); _value = value; } @@ -62,7 +62,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - VALUE)); + VALUE__PROP)); @Override public java.util.List properties() { @@ -72,7 +72,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case VALUE: return isValue(); + case VALUE__PROP: return isValue(); default: return super.get(field); } } @@ -80,13 +80,13 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case VALUE: internalSetValue((boolean) value); break; + case VALUE__PROP: internalSetValue((boolean) value); break; default: super.set(field, value); break; } } /** Reads a new instance from the given reader. */ - public static Flag readFlag(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.generator.ast.Flag readFlag(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { de.haumacher.msgbuf.generator.ast.Flag result = new de.haumacher.msgbuf.generator.ast.Flag(); result.readContent(in); return result; @@ -95,20 +95,20 @@ public static Flag readFlag(de.haumacher.msgbuf.json.JsonReader in) throws java. @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(VALUE); + out.name(VALUE__PROP); out.value(isValue()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case VALUE: setValue(in.nextBoolean()); break; + case VALUE__PROP: setValue(in.nextBoolean()); break; default: super.readField(in, field); } } @Override - public R visit(Option.Visitor v, A arg) { + public R visit(de.haumacher.msgbuf.generator.ast.Option.Visitor v, A arg) { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MapType.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MapType.java index 288e200c..54e5e7f6 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MapType.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MapType.java @@ -6,29 +6,29 @@ public class MapType extends Type { /** - * Creates a {@link MapType} instance. + * Creates a {@link de.haumacher.msgbuf.generator.ast.MapType} instance. */ - public static MapType create() { + public static de.haumacher.msgbuf.generator.ast.MapType create() { return new de.haumacher.msgbuf.generator.ast.MapType(); } - /** Identifier for the {@link MapType} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.generator.ast.MapType} type in JSON format. */ public static final String MAP_TYPE__TYPE = "MapType"; /** @see #getKeyType() */ - public static final String KEY_TYPE = "keyType"; + public static final String KEY_TYPE__PROP = "keyType"; /** @see #getValueType() */ - public static final String VALUE_TYPE = "valueType"; + public static final String VALUE_TYPE__PROP = "valueType"; - private Type _keyType = null; + private de.haumacher.msgbuf.generator.ast.Type _keyType = null; - private Type _valueType = null; + private de.haumacher.msgbuf.generator.ast.Type _valueType = null; /** * Creates a {@link MapType} instance. * - * @see MapType#create() + * @see de.haumacher.msgbuf.generator.ast.MapType#create() */ protected MapType() { super(); @@ -42,21 +42,21 @@ public TypeKind kind() { /** * The key type of this map. */ - public final Type getKeyType() { + public final de.haumacher.msgbuf.generator.ast.Type getKeyType() { return _keyType; } /** * @see #getKeyType() */ - public MapType setKeyType(Type value) { + public de.haumacher.msgbuf.generator.ast.MapType setKeyType(de.haumacher.msgbuf.generator.ast.Type value) { internalSetKeyType(value); return this; } /** Internal setter for {@link #getKeyType()} without chain call utility. */ - protected final void internalSetKeyType(Type value) { - _listener.beforeSet(this, KEY_TYPE, value); + protected final void internalSetKeyType(de.haumacher.msgbuf.generator.ast.Type value) { + _listener.beforeSet(this, KEY_TYPE__PROP, value); _keyType = value; } @@ -70,21 +70,21 @@ public final boolean hasKeyType() { /** * The value type of this map. */ - public final Type getValueType() { + public final de.haumacher.msgbuf.generator.ast.Type getValueType() { return _valueType; } /** * @see #getValueType() */ - public MapType setValueType(Type value) { + public de.haumacher.msgbuf.generator.ast.MapType setValueType(de.haumacher.msgbuf.generator.ast.Type value) { internalSetValueType(value); return this; } /** Internal setter for {@link #getValueType()} without chain call utility. */ - protected final void internalSetValueType(Type value) { - _listener.beforeSet(this, VALUE_TYPE, value); + protected final void internalSetValueType(de.haumacher.msgbuf.generator.ast.Type value) { + _listener.beforeSet(this, VALUE_TYPE__PROP, value); _valueType = value; } @@ -102,8 +102,8 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - KEY_TYPE, - VALUE_TYPE)); + KEY_TYPE__PROP, + VALUE_TYPE__PROP)); @Override public java.util.List properties() { @@ -113,8 +113,8 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case KEY_TYPE: return getKeyType(); - case VALUE_TYPE: return getValueType(); + case KEY_TYPE__PROP: return getKeyType(); + case VALUE_TYPE__PROP: return getValueType(); default: return super.get(field); } } @@ -122,14 +122,14 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case KEY_TYPE: internalSetKeyType((Type) value); break; - case VALUE_TYPE: internalSetValueType((Type) value); break; + case KEY_TYPE__PROP: internalSetKeyType((de.haumacher.msgbuf.generator.ast.Type) value); break; + case VALUE_TYPE__PROP: internalSetValueType((de.haumacher.msgbuf.generator.ast.Type) value); break; default: super.set(field, value); break; } } /** Reads a new instance from the given reader. */ - public static MapType readMapType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.generator.ast.MapType readMapType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { de.haumacher.msgbuf.generator.ast.MapType result = new de.haumacher.msgbuf.generator.ast.MapType(); result.readContent(in); return result; @@ -139,11 +139,11 @@ public static MapType readMapType(de.haumacher.msgbuf.json.JsonReader in) throws protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); if (hasKeyType()) { - out.name(KEY_TYPE); + out.name(KEY_TYPE__PROP); getKeyType().writeTo(out); } if (hasValueType()) { - out.name(VALUE_TYPE); + out.name(VALUE_TYPE__PROP); getValueType().writeTo(out); } } @@ -151,14 +151,14 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case KEY_TYPE: setKeyType(de.haumacher.msgbuf.generator.ast.Type.readType(in)); break; - case VALUE_TYPE: setValueType(de.haumacher.msgbuf.generator.ast.Type.readType(in)); break; + case KEY_TYPE__PROP: setKeyType(de.haumacher.msgbuf.generator.ast.Type.readType(in)); break; + case VALUE_TYPE__PROP: setValueType(de.haumacher.msgbuf.generator.ast.Type.readType(in)); break; default: super.readField(in, field); } } @Override - public R visit(Type.Visitor v, A arg) { + public R visit(de.haumacher.msgbuf.generator.ast.Type.Visitor v, A arg) { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java index 8c659d36..1ab789a6 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java @@ -6,84 +6,84 @@ public class MessageDef extends Definition implements de.haumacher.msgbuf.generator.MessageDefOperations { /** - * Creates a {@link MessageDef} instance. + * Creates a {@link de.haumacher.msgbuf.generator.ast.MessageDef} instance. */ - public static MessageDef create() { + public static de.haumacher.msgbuf.generator.ast.MessageDef create() { return new de.haumacher.msgbuf.generator.ast.MessageDef(); } - /** Identifier for the {@link MessageDef} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.generator.ast.MessageDef} type in JSON format. */ public static final String MESSAGE_DEF__TYPE = "MessageDef"; /** @see #isAbstract() */ - public static final String ABSTRACT = "abstract"; + public static final String ABSTRACT__PROP = "abstract"; /** @see #getExtends() */ - public static final String EXTENDS = "extends"; + public static final String EXTENDS__PROP = "extends"; /** @see #getDefinitions() */ - public static final String DEFINITIONS = "definitions"; + public static final String DEFINITIONS__PROP = "definitions"; /** @see #getFields() */ - public static final String FIELDS = "fields"; + public static final String FIELDS__PROP = "fields"; /** @see #getSpecializations() */ - public static final String SPECIALIZATIONS = "specializations"; + public static final String SPECIALIZATIONS__PROP = "specializations"; /** @see #getExtendedDef() */ - public static final String EXTENDED_DEF = "extendedDef"; + public static final String EXTENDED_DEF__PROP = "extendedDef"; /** @see #getId() */ - public static final String ID = "id"; + public static final String ID__PROP = "id"; private boolean _abstract = false; - private QName _extends = null; + private de.haumacher.msgbuf.generator.ast.QName _extends = null; - private final java.util.List _definitions = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _definitions = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override - protected void beforeAdd(int index, Definition element) { - _listener.beforeAdd(MessageDef.this, DEFINITIONS, index, element); + protected void beforeAdd(int index, de.haumacher.msgbuf.generator.ast.Definition element) { + _listener.beforeAdd(MessageDef.this, DEFINITIONS__PROP, index, element); } @Override - protected void afterRemove(int index, Definition element) { - _listener.afterRemove(MessageDef.this, DEFINITIONS, index, element); + protected void afterRemove(int index, de.haumacher.msgbuf.generator.ast.Definition element) { + _listener.afterRemove(MessageDef.this, DEFINITIONS__PROP, index, element); } }; - private final java.util.List _fields = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _fields = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override - protected void beforeAdd(int index, Field element) { - _listener.beforeAdd(MessageDef.this, FIELDS, index, element); + protected void beforeAdd(int index, de.haumacher.msgbuf.generator.ast.Field element) { + _listener.beforeAdd(MessageDef.this, FIELDS__PROP, index, element); } @Override - protected void afterRemove(int index, Field element) { - _listener.afterRemove(MessageDef.this, FIELDS, index, element); + protected void afterRemove(int index, de.haumacher.msgbuf.generator.ast.Field element) { + _listener.afterRemove(MessageDef.this, FIELDS__PROP, index, element); } }; - private transient final java.util.List _specializations = new de.haumacher.msgbuf.util.ReferenceList() { + private transient final java.util.List _specializations = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override - protected void beforeAdd(int index, MessageDef element) { - _listener.beforeAdd(MessageDef.this, SPECIALIZATIONS, index, element); + protected void beforeAdd(int index, de.haumacher.msgbuf.generator.ast.MessageDef element) { + _listener.beforeAdd(MessageDef.this, SPECIALIZATIONS__PROP, index, element); } @Override - protected void afterRemove(int index, MessageDef element) { - _listener.afterRemove(MessageDef.this, SPECIALIZATIONS, index, element); + protected void afterRemove(int index, de.haumacher.msgbuf.generator.ast.MessageDef element) { + _listener.afterRemove(MessageDef.this, SPECIALIZATIONS__PROP, index, element); } }; - private transient MessageDef _extendedDef = null; + private transient de.haumacher.msgbuf.generator.ast.MessageDef _extendedDef = null; private transient int _id = 0; /** * Creates a {@link MessageDef} instance. * - * @see MessageDef#create() + * @see de.haumacher.msgbuf.generator.ast.MessageDef#create() */ protected MessageDef() { super(); @@ -104,35 +104,35 @@ public final boolean isAbstract() { /** * @see #isAbstract() */ - public MessageDef setAbstract(boolean value) { + public de.haumacher.msgbuf.generator.ast.MessageDef setAbstract(boolean value) { internalSetAbstract(value); return this; } /** Internal setter for {@link #isAbstract()} without chain call utility. */ protected final void internalSetAbstract(boolean value) { - _listener.beforeSet(this, ABSTRACT, value); + _listener.beforeSet(this, ABSTRACT__PROP, value); _abstract = value; } /** * Optional reference to another {@link MessageDef} whoes fields are inherited. */ - public final QName getExtends() { + public final de.haumacher.msgbuf.generator.ast.QName getExtends() { return _extends; } /** * @see #getExtends() */ - public MessageDef setExtends(QName value) { + public de.haumacher.msgbuf.generator.ast.MessageDef setExtends(de.haumacher.msgbuf.generator.ast.QName value) { internalSetExtends(value); return this; } /** Internal setter for {@link #getExtends()} without chain call utility. */ - protected final void internalSetExtends(QName value) { - _listener.beforeSet(this, EXTENDS, value); + protected final void internalSetExtends(de.haumacher.msgbuf.generator.ast.QName value) { + _listener.beforeSet(this, EXTENDS__PROP, value); _extends = value; } @@ -146,20 +146,20 @@ public final boolean hasExtends() { /** * Ohter {@link Definition}s that are local to this data class. */ - public final java.util.List getDefinitions() { + public final java.util.List getDefinitions() { return _definitions; } /** * @see #getDefinitions() */ - public MessageDef setDefinitions(java.util.List value) { + public de.haumacher.msgbuf.generator.ast.MessageDef setDefinitions(java.util.List value) { internalSetDefinitions(value); return this; } /** Internal setter for {@link #getDefinitions()} without chain call utility. */ - protected final void internalSetDefinitions(java.util.List value) { + protected final void internalSetDefinitions(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'definitions' cannot be null."); _definitions.clear(); _definitions.addAll(value); @@ -168,20 +168,20 @@ protected final void internalSetDefinitions(java.util.List /** * Adds a value to the {@link #getDefinitions()} list. */ - public MessageDef addDefinition(Definition value) { + public de.haumacher.msgbuf.generator.ast.MessageDef addDefinition(de.haumacher.msgbuf.generator.ast.Definition value) { internalAddDefinition(value); return this; } - /** Implementation of {@link #addDefinition(Definition)} without chain call utility. */ - protected final void internalAddDefinition(Definition value) { + /** Implementation of {@link #addDefinition(de.haumacher.msgbuf.generator.ast.Definition)} without chain call utility. */ + protected final void internalAddDefinition(de.haumacher.msgbuf.generator.ast.Definition value) { _definitions.add(value); } /** * Removes a value from the {@link #getDefinitions()} list. */ - public final void removeDefinition(Definition value) { + public final void removeDefinition(de.haumacher.msgbuf.generator.ast.Definition value) { _definitions.remove(value); } @@ -194,20 +194,20 @@ public final void removeDefinition(Definition value) { * * @see #getExtends() */ - public final java.util.List getFields() { + public final java.util.List getFields() { return _fields; } /** * @see #getFields() */ - public MessageDef setFields(java.util.List value) { + public de.haumacher.msgbuf.generator.ast.MessageDef setFields(java.util.List value) { internalSetFields(value); return this; } /** Internal setter for {@link #getFields()} without chain call utility. */ - protected final void internalSetFields(java.util.List value) { + protected final void internalSetFields(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'fields' cannot be null."); _fields.clear(); _fields.addAll(value); @@ -216,40 +216,40 @@ protected final void internalSetFields(java.util.List value) { /** * Adds a value to the {@link #getFields()} list. */ - public MessageDef addField(Field value) { + public de.haumacher.msgbuf.generator.ast.MessageDef addField(de.haumacher.msgbuf.generator.ast.Field value) { internalAddField(value); return this; } - /** Implementation of {@link #addField(Field)} without chain call utility. */ - protected final void internalAddField(Field value) { + /** Implementation of {@link #addField(de.haumacher.msgbuf.generator.ast.Field)} without chain call utility. */ + protected final void internalAddField(de.haumacher.msgbuf.generator.ast.Field value) { _fields.add(value); } /** * Removes a value from the {@link #getFields()} list. */ - public final void removeField(Field value) { + public final void removeField(de.haumacher.msgbuf.generator.ast.Field value) { _fields.remove(value); } /** * All {@link MessageDef data classes} that inherit from this data class. */ - public final java.util.List getSpecializations() { + public final java.util.List getSpecializations() { return _specializations; } /** * @see #getSpecializations() */ - public MessageDef setSpecializations(java.util.List value) { + public de.haumacher.msgbuf.generator.ast.MessageDef setSpecializations(java.util.List value) { internalSetSpecializations(value); return this; } /** Internal setter for {@link #getSpecializations()} without chain call utility. */ - protected final void internalSetSpecializations(java.util.List value) { + protected final void internalSetSpecializations(java.util.List value) { if (value == null) throw new IllegalArgumentException("Property 'specializations' cannot be null."); _specializations.clear(); _specializations.addAll(value); @@ -258,41 +258,41 @@ protected final void internalSetSpecializations(java.util.List value) { + public de.haumacher.msgbuf.generator.ast.MessageDef setOptions(java.util.Map value) { internalSetOptions(value); return this; } @Override - public MessageDef putOption(String key, Option value) { + public de.haumacher.msgbuf.generator.ast.MessageDef putOption(String key, de.haumacher.msgbuf.generator.ast.Option value) { internalPutOption(key, value); return this; } @@ -367,13 +367,13 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - ABSTRACT, - EXTENDS, - DEFINITIONS, - FIELDS, - SPECIALIZATIONS, - EXTENDED_DEF, - ID)); + ABSTRACT__PROP, + EXTENDS__PROP, + DEFINITIONS__PROP, + FIELDS__PROP, + SPECIALIZATIONS__PROP, + EXTENDED_DEF__PROP, + ID__PROP)); @Override public java.util.List properties() { @@ -383,13 +383,13 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case ABSTRACT: return isAbstract(); - case EXTENDS: return getExtends(); - case DEFINITIONS: return getDefinitions(); - case FIELDS: return getFields(); - case SPECIALIZATIONS: return getSpecializations(); - case EXTENDED_DEF: return getExtendedDef(); - case ID: return getId(); + case ABSTRACT__PROP: return isAbstract(); + case EXTENDS__PROP: return getExtends(); + case DEFINITIONS__PROP: return getDefinitions(); + case FIELDS__PROP: return getFields(); + case SPECIALIZATIONS__PROP: return getSpecializations(); + case EXTENDED_DEF__PROP: return getExtendedDef(); + case ID__PROP: return getId(); default: return super.get(field); } } @@ -397,19 +397,19 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case ABSTRACT: internalSetAbstract((boolean) value); break; - case EXTENDS: internalSetExtends((QName) value); break; - case DEFINITIONS: internalSetDefinitions(de.haumacher.msgbuf.util.Conversions.asList(Definition.class, value)); break; - case FIELDS: internalSetFields(de.haumacher.msgbuf.util.Conversions.asList(Field.class, value)); break; - case SPECIALIZATIONS: internalSetSpecializations(de.haumacher.msgbuf.util.Conversions.asList(MessageDef.class, value)); break; - case EXTENDED_DEF: internalSetExtendedDef((MessageDef) value); break; - case ID: internalSetId((int) value); break; + case ABSTRACT__PROP: internalSetAbstract((boolean) value); break; + case EXTENDS__PROP: internalSetExtends((de.haumacher.msgbuf.generator.ast.QName) value); break; + case DEFINITIONS__PROP: internalSetDefinitions(de.haumacher.msgbuf.util.Conversions.asList(de.haumacher.msgbuf.generator.ast.Definition.class, value)); break; + case FIELDS__PROP: internalSetFields(de.haumacher.msgbuf.util.Conversions.asList(de.haumacher.msgbuf.generator.ast.Field.class, value)); break; + case SPECIALIZATIONS__PROP: internalSetSpecializations(de.haumacher.msgbuf.util.Conversions.asList(de.haumacher.msgbuf.generator.ast.MessageDef.class, value)); break; + case EXTENDED_DEF__PROP: internalSetExtendedDef((de.haumacher.msgbuf.generator.ast.MessageDef) value); break; + case ID__PROP: internalSetId((int) value); break; default: super.set(field, value); break; } } /** Reads a new instance from the given reader. */ - public static MessageDef readMessageDef(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.generator.ast.MessageDef readMessageDef(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { de.haumacher.msgbuf.generator.ast.MessageDef result = new de.haumacher.msgbuf.generator.ast.MessageDef(); result.readContent(in); return result; @@ -418,21 +418,21 @@ public static MessageDef readMessageDef(de.haumacher.msgbuf.json.JsonReader in) @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(ABSTRACT); + out.name(ABSTRACT__PROP); out.value(isAbstract()); if (hasExtends()) { - out.name(EXTENDS); + out.name(EXTENDS__PROP); getExtends().writeTo(out); } - out.name(DEFINITIONS); + out.name(DEFINITIONS__PROP); out.beginArray(); - for (Definition x : getDefinitions()) { + for (de.haumacher.msgbuf.generator.ast.Definition x : getDefinitions()) { x.writeTo(out); } out.endArray(); - out.name(FIELDS); + out.name(FIELDS__PROP); out.beginArray(); - for (Field x : getFields()) { + for (de.haumacher.msgbuf.generator.ast.Field x : getFields()) { x.writeContent(out); } out.endArray(); @@ -441,9 +441,9 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case ABSTRACT: setAbstract(in.nextBoolean()); break; - case EXTENDS: setExtends(de.haumacher.msgbuf.generator.ast.QName.readQName(in)); break; - case DEFINITIONS: { + case ABSTRACT__PROP: setAbstract(in.nextBoolean()); break; + case EXTENDS__PROP: setExtends(de.haumacher.msgbuf.generator.ast.QName.readQName(in)); break; + case DEFINITIONS__PROP: { in.beginArray(); while (in.hasNext()) { addDefinition(de.haumacher.msgbuf.generator.ast.Definition.readDefinition(in)); @@ -451,7 +451,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t in.endArray(); } break; - case FIELDS: { + case FIELDS__PROP: { in.beginArray(); while (in.hasNext()) { addField(de.haumacher.msgbuf.generator.ast.Field.readField(in)); @@ -464,13 +464,13 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t } @Override - public R visit(Definition.Visitor v, A arg) { - return v.visit(this, arg); + public MessageDef self() { + return this; } @Override - public MessageDef self() { - return this; + public R visit(de.haumacher.msgbuf.generator.ast.Definition.Visitor v, A arg) { + return v.visit(this, arg); } } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/NumberOption.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/NumberOption.java index 95db9349..33e4b1e1 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/NumberOption.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/NumberOption.java @@ -6,24 +6,24 @@ public class NumberOption extends Option { /** - * Creates a {@link NumberOption} instance. + * Creates a {@link de.haumacher.msgbuf.generator.ast.NumberOption} instance. */ - public static NumberOption create() { + public static de.haumacher.msgbuf.generator.ast.NumberOption create() { return new de.haumacher.msgbuf.generator.ast.NumberOption(); } - /** Identifier for the {@link NumberOption} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.generator.ast.NumberOption} type in JSON format. */ public static final String NUMBER_OPTION__TYPE = "NumberOption"; /** @see #getValue() */ - public static final String VALUE = "value"; + public static final String VALUE__PROP = "value"; private double _value = 0.0d; /** * Creates a {@link NumberOption} instance. * - * @see NumberOption#create() + * @see de.haumacher.msgbuf.generator.ast.NumberOption#create() */ protected NumberOption() { super(); @@ -44,14 +44,14 @@ public final double getValue() { /** * @see #getValue() */ - public NumberOption setValue(double value) { + public de.haumacher.msgbuf.generator.ast.NumberOption setValue(double value) { internalSetValue(value); return this; } /** Internal setter for {@link #getValue()} without chain call utility. */ protected final void internalSetValue(double value) { - _listener.beforeSet(this, VALUE, value); + _listener.beforeSet(this, VALUE__PROP, value); _value = value; } @@ -62,7 +62,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - VALUE)); + VALUE__PROP)); @Override public java.util.List properties() { @@ -72,7 +72,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case VALUE: return getValue(); + case VALUE__PROP: return getValue(); default: return super.get(field); } } @@ -80,13 +80,13 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case VALUE: internalSetValue((double) value); break; + case VALUE__PROP: internalSetValue((double) value); break; default: super.set(field, value); break; } } /** Reads a new instance from the given reader. */ - public static NumberOption readNumberOption(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.generator.ast.NumberOption readNumberOption(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { de.haumacher.msgbuf.generator.ast.NumberOption result = new de.haumacher.msgbuf.generator.ast.NumberOption(); result.readContent(in); return result; @@ -95,20 +95,20 @@ public static NumberOption readNumberOption(de.haumacher.msgbuf.json.JsonReader @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(VALUE); + out.name(VALUE__PROP); out.value(getValue()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case VALUE: setValue(in.nextDouble()); break; + case VALUE__PROP: setValue(in.nextDouble()); break; default: super.readField(in, field); } } @Override - public R visit(Option.Visitor v, A arg) { + public R visit(de.haumacher.msgbuf.generator.ast.Option.Visitor v, A arg) { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Option.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Option.java index 6053e5d4..d389ad2a 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Option.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Option.java @@ -9,32 +9,32 @@ */ public abstract class Option extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.observer.Observable { - /** Type codes for the {@link Option} hierarchy. */ + /** Type codes for the {@link de.haumacher.msgbuf.generator.ast.Option} hierarchy. */ public enum TypeKind { - /** Type literal for {@link StringOption}. */ + /** Type literal for {@link de.haumacher.msgbuf.generator.ast.StringOption}. */ STRING_OPTION, - /** Type literal for {@link NumberOption}. */ + /** Type literal for {@link de.haumacher.msgbuf.generator.ast.NumberOption}. */ NUMBER_OPTION, - /** Type literal for {@link Flag}. */ + /** Type literal for {@link de.haumacher.msgbuf.generator.ast.Flag}. */ FLAG, ; } - /** Visitor interface for the {@link Option} hierarchy.*/ + /** Visitor interface for the {@link de.haumacher.msgbuf.generator.ast.Option} hierarchy.*/ public interface Visitor { - /** Visit case for {@link StringOption}.*/ - R visit(StringOption self, A arg); + /** Visit case for {@link de.haumacher.msgbuf.generator.ast.StringOption}.*/ + R visit(de.haumacher.msgbuf.generator.ast.StringOption self, A arg); - /** Visit case for {@link NumberOption}.*/ - R visit(NumberOption self, A arg); + /** Visit case for {@link de.haumacher.msgbuf.generator.ast.NumberOption}.*/ + R visit(de.haumacher.msgbuf.generator.ast.NumberOption self, A arg); - /** Visit case for {@link Flag}.*/ - R visit(Flag self, A arg); + /** Visit case for {@link de.haumacher.msgbuf.generator.ast.Flag}.*/ + R visit(de.haumacher.msgbuf.generator.ast.Flag self, A arg); } @@ -51,7 +51,7 @@ protected Option() { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public Option registerListener(de.haumacher.msgbuf.observer.Listener l) { + public de.haumacher.msgbuf.generator.ast.Option registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -61,7 +61,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public Option unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public de.haumacher.msgbuf.generator.ast.Option unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -71,8 +71,8 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis } /** Reads a new instance from the given reader. */ - public static Option readOption(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - Option result; + public static de.haumacher.msgbuf.generator.ast.Option readOption(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.generator.ast.Option result; in.beginArray(); String type = in.nextString(); switch (type) { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/OptionContainer.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/OptionContainer.java index 208a00f2..8e40a308 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/OptionContainer.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/OptionContainer.java @@ -6,19 +6,19 @@ public class OptionContainer extends WithOptions { /** - * Creates a {@link OptionContainer} instance. + * Creates a {@link de.haumacher.msgbuf.generator.ast.OptionContainer} instance. */ - public static OptionContainer create() { + public static de.haumacher.msgbuf.generator.ast.OptionContainer create() { return new de.haumacher.msgbuf.generator.ast.OptionContainer(); } - /** Identifier for the {@link OptionContainer} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.generator.ast.OptionContainer} type in JSON format. */ public static final String OPTION_CONTAINER__TYPE = "OptionContainer"; /** * Creates a {@link OptionContainer} instance. * - * @see OptionContainer#create() + * @see de.haumacher.msgbuf.generator.ast.OptionContainer#create() */ protected OptionContainer() { super(); @@ -30,13 +30,13 @@ public TypeKind kind() { } @Override - public OptionContainer setOptions(java.util.Map value) { + public de.haumacher.msgbuf.generator.ast.OptionContainer setOptions(java.util.Map value) { internalSetOptions(value); return this; } @Override - public OptionContainer putOption(String key, Option value) { + public de.haumacher.msgbuf.generator.ast.OptionContainer putOption(String key, de.haumacher.msgbuf.generator.ast.Option value) { internalPutOption(key, value); return this; } @@ -47,14 +47,14 @@ public String jsonType() { } /** Reads a new instance from the given reader. */ - public static OptionContainer readOptionContainer(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.generator.ast.OptionContainer readOptionContainer(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { de.haumacher.msgbuf.generator.ast.OptionContainer result = new de.haumacher.msgbuf.generator.ast.OptionContainer(); result.readContent(in); return result; } @Override - public R visit(WithOptions.Visitor v, A arg) { + public R visit(de.haumacher.msgbuf.generator.ast.WithOptions.Visitor v, A arg) { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Part.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Part.java index f0800548..d0b34e88 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Part.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Part.java @@ -5,31 +5,31 @@ */ public abstract class Part extends DefinitionBase { - /** Visitor interface for the {@link Part} hierarchy.*/ + /** Visitor interface for the {@link de.haumacher.msgbuf.generator.ast.Part} hierarchy.*/ public interface Visitor { - /** Visit case for {@link Constant}.*/ - R visit(Constant self, A arg); + /** Visit case for {@link de.haumacher.msgbuf.generator.ast.Constant}.*/ + R visit(de.haumacher.msgbuf.generator.ast.Constant self, A arg); - /** Visit case for {@link Field}.*/ - R visit(Field self, A arg); + /** Visit case for {@link de.haumacher.msgbuf.generator.ast.Field}.*/ + R visit(de.haumacher.msgbuf.generator.ast.Field self, A arg); } /** @see #getName() */ - public static final String NAME = "name"; + public static final String NAME__PROP = "name"; /** @see #getIndex() */ - public static final String INDEX = "index"; + public static final String INDEX__PROP = "index"; /** @see #getOwner() */ - public static final String OWNER = "owner"; + public static final String OWNER__PROP = "owner"; private String _name = ""; private int _index = 0; - private transient Definition _owner = null; + private transient de.haumacher.msgbuf.generator.ast.Definition _owner = null; /** * Creates a {@link Part} instance. @@ -48,14 +48,14 @@ public final String getName() { /** * @see #getName() */ - public Part setName(String value) { + public de.haumacher.msgbuf.generator.ast.Part setName(String value) { internalSetName(value); return this; } /** Internal setter for {@link #getName()} without chain call utility. */ protected final void internalSetName(String value) { - _listener.beforeSet(this, NAME, value); + _listener.beforeSet(this, NAME__PROP, value); _name = value; } @@ -69,35 +69,35 @@ public final int getIndex() { /** * @see #getIndex() */ - public Part setIndex(int value) { + public de.haumacher.msgbuf.generator.ast.Part setIndex(int value) { internalSetIndex(value); return this; } /** Internal setter for {@link #getIndex()} without chain call utility. */ protected final void internalSetIndex(int value) { - _listener.beforeSet(this, INDEX, value); + _listener.beforeSet(this, INDEX__PROP, value); _index = value; } /** * The {@link Definition} definint this {@link Part}. */ - public final Definition getOwner() { + public final de.haumacher.msgbuf.generator.ast.Definition getOwner() { return _owner; } /** * @see #getOwner() */ - public Part setOwner(Definition value) { + public de.haumacher.msgbuf.generator.ast.Part setOwner(de.haumacher.msgbuf.generator.ast.Definition value) { internalSetOwner(value); return this; } /** Internal setter for {@link #getOwner()} without chain call utility. */ - protected final void internalSetOwner(Definition value) { - _listener.beforeSet(this, OWNER, value); + protected final void internalSetOwner(de.haumacher.msgbuf.generator.ast.Definition value) { + _listener.beforeSet(this, OWNER__PROP, value); _owner = value; } @@ -109,28 +109,28 @@ public final boolean hasOwner() { } @Override - public Part setComment(String value) { + public de.haumacher.msgbuf.generator.ast.Part setComment(String value) { internalSetComment(value); return this; } @Override - public Part setOptions(java.util.Map value) { + public de.haumacher.msgbuf.generator.ast.Part setOptions(java.util.Map value) { internalSetOptions(value); return this; } @Override - public Part putOption(String key, Option value) { + public de.haumacher.msgbuf.generator.ast.Part putOption(String key, de.haumacher.msgbuf.generator.ast.Option value) { internalPutOption(key, value); return this; } private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - NAME, - INDEX, - OWNER)); + NAME__PROP, + INDEX__PROP, + OWNER__PROP)); @Override public java.util.List properties() { @@ -140,9 +140,9 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case NAME: return getName(); - case INDEX: return getIndex(); - case OWNER: return getOwner(); + case NAME__PROP: return getName(); + case INDEX__PROP: return getIndex(); + case OWNER__PROP: return getOwner(); default: return super.get(field); } } @@ -150,16 +150,16 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case NAME: internalSetName((String) value); break; - case INDEX: internalSetIndex((int) value); break; - case OWNER: internalSetOwner((Definition) value); break; + case NAME__PROP: internalSetName((String) value); break; + case INDEX__PROP: internalSetIndex((int) value); break; + case OWNER__PROP: internalSetOwner((de.haumacher.msgbuf.generator.ast.Definition) value); break; default: super.set(field, value); break; } } /** Reads a new instance from the given reader. */ - public static Part readPart(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - Part result; + public static de.haumacher.msgbuf.generator.ast.Part readPart(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.generator.ast.Part result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -174,17 +174,17 @@ public static Part readPart(de.haumacher.msgbuf.json.JsonReader in) throws java. @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(NAME); + out.name(NAME__PROP); out.value(getName()); - out.name(INDEX); + out.name(INDEX__PROP); out.value(getIndex()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case NAME: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; - case INDEX: setIndex(in.nextInt()); break; + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case INDEX__PROP: setIndex(in.nextInt()); break; default: super.readField(in, field); } } @@ -193,8 +193,8 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t public abstract R visit(Visitor v, A arg); @Override - public final R visit(DefinitionBase.Visitor v, A arg) { - return visit((Part.Visitor) v, arg); + public final R visit(de.haumacher.msgbuf.generator.ast.DefinitionBase.Visitor v, A arg) { + return visit((de.haumacher.msgbuf.generator.ast.Part.Visitor) v, arg); } } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/PrimitiveType.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/PrimitiveType.java index ac7f8061..1c7c3f27 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/PrimitiveType.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/PrimitiveType.java @@ -182,24 +182,24 @@ public static Kind readKind(de.haumacher.msgbuf.binary.DataReader in) throws jav } /** - * Creates a {@link PrimitiveType} instance. + * Creates a {@link de.haumacher.msgbuf.generator.ast.PrimitiveType} instance. */ - public static PrimitiveType create() { + public static de.haumacher.msgbuf.generator.ast.PrimitiveType create() { return new de.haumacher.msgbuf.generator.ast.PrimitiveType(); } - /** Identifier for the {@link PrimitiveType} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.generator.ast.PrimitiveType} type in JSON format. */ public static final String PRIMITIVE_TYPE__TYPE = "PrimitiveType"; /** @see #getKind() */ - public static final String KIND = "kind"; + public static final String KIND__PROP = "kind"; - private Kind _kind = de.haumacher.msgbuf.generator.ast.PrimitiveType.Kind.INT_32; + private de.haumacher.msgbuf.generator.ast.PrimitiveType.Kind _kind = de.haumacher.msgbuf.generator.ast.PrimitiveType.Kind.INT_32; /** * Creates a {@link PrimitiveType} instance. * - * @see PrimitiveType#create() + * @see de.haumacher.msgbuf.generator.ast.PrimitiveType#create() */ protected PrimitiveType() { super(); @@ -213,22 +213,22 @@ public TypeKind kind() { /** * The type kind. */ - public final Kind getKind() { + public final de.haumacher.msgbuf.generator.ast.PrimitiveType.Kind getKind() { return _kind; } /** * @see #getKind() */ - public PrimitiveType setKind(Kind value) { + public de.haumacher.msgbuf.generator.ast.PrimitiveType setKind(de.haumacher.msgbuf.generator.ast.PrimitiveType.Kind value) { internalSetKind(value); return this; } /** Internal setter for {@link #getKind()} without chain call utility. */ - protected final void internalSetKind(Kind value) { + protected final void internalSetKind(de.haumacher.msgbuf.generator.ast.PrimitiveType.Kind value) { if (value == null) throw new IllegalArgumentException("Property 'kind' cannot be null."); - _listener.beforeSet(this, KIND, value); + _listener.beforeSet(this, KIND__PROP, value); _kind = value; } @@ -239,7 +239,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - KIND)); + KIND__PROP)); @Override public java.util.List properties() { @@ -249,7 +249,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case KIND: return getKind(); + case KIND__PROP: return getKind(); default: return super.get(field); } } @@ -257,13 +257,13 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case KIND: internalSetKind((Kind) value); break; + case KIND__PROP: internalSetKind((de.haumacher.msgbuf.generator.ast.PrimitiveType.Kind) value); break; default: super.set(field, value); break; } } /** Reads a new instance from the given reader. */ - public static PrimitiveType readPrimitiveType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.generator.ast.PrimitiveType readPrimitiveType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { de.haumacher.msgbuf.generator.ast.PrimitiveType result = new de.haumacher.msgbuf.generator.ast.PrimitiveType(); result.readContent(in); return result; @@ -272,20 +272,20 @@ public static PrimitiveType readPrimitiveType(de.haumacher.msgbuf.json.JsonReade @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(KIND); + out.name(KIND__PROP); getKind().writeTo(out); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case KIND: setKind(de.haumacher.msgbuf.generator.ast.PrimitiveType.Kind.readKind(in)); break; + case KIND__PROP: setKind(de.haumacher.msgbuf.generator.ast.PrimitiveType.Kind.readKind(in)); break; default: super.readField(in, field); } } @Override - public R visit(Type.Visitor v, A arg) { + public R visit(de.haumacher.msgbuf.generator.ast.Type.Visitor v, A arg) { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/QName.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/QName.java index 29350803..3ccf0221 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/QName.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/QName.java @@ -6,34 +6,34 @@ public class QName extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.observer.Observable { /** - * Creates a {@link QName} instance. + * Creates a {@link de.haumacher.msgbuf.generator.ast.QName} instance. */ - public static QName create() { + public static de.haumacher.msgbuf.generator.ast.QName create() { return new de.haumacher.msgbuf.generator.ast.QName(); } - /** Identifier for the {@link QName} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.generator.ast.QName} type in JSON format. */ public static final String QNAME__TYPE = "QName"; /** @see #getNames() */ - public static final String NAMES = "names"; + public static final String NAMES__PROP = "names"; - private final java.util.List _names = new de.haumacher.msgbuf.util.ReferenceList() { + private final java.util.List _names = new de.haumacher.msgbuf.util.ReferenceList<>() { @Override protected void beforeAdd(int index, String element) { - _listener.beforeAdd(QName.this, NAMES, index, element); + _listener.beforeAdd(QName.this, NAMES__PROP, index, element); } @Override protected void afterRemove(int index, String element) { - _listener.afterRemove(QName.this, NAMES, index, element); + _listener.afterRemove(QName.this, NAMES__PROP, index, element); } }; /** * Creates a {@link QName} instance. * - * @see QName#create() + * @see de.haumacher.msgbuf.generator.ast.QName#create() */ protected QName() { super(); @@ -49,7 +49,7 @@ public final java.util.List getNames() { /** * @see #getNames() */ - public QName setNames(java.util.List value) { + public de.haumacher.msgbuf.generator.ast.QName setNames(java.util.List value) { internalSetNames(value); return this; } @@ -63,7 +63,7 @@ protected final void internalSetNames(java.util.List value) { /** * Adds a value to the {@link #getNames()} list. */ - public QName addName(String value) { + public de.haumacher.msgbuf.generator.ast.QName addName(String value) { internalAddName(value); return this; } @@ -83,7 +83,7 @@ public final void removeName(String value) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public QName registerListener(de.haumacher.msgbuf.observer.Listener l) { + public de.haumacher.msgbuf.generator.ast.QName registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -93,7 +93,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public QName unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public de.haumacher.msgbuf.generator.ast.QName unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -109,7 +109,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - NAMES)); + NAMES__PROP)); @Override public java.util.List properties() { @@ -119,7 +119,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case NAMES: return getNames(); + case NAMES__PROP: return getNames(); default: return null; } } @@ -127,12 +127,12 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case NAMES: internalSetNames(de.haumacher.msgbuf.util.Conversions.asList(String.class, value)); break; + case NAMES__PROP: internalSetNames(de.haumacher.msgbuf.util.Conversions.asList(String.class, value)); break; } } /** Reads a new instance from the given reader. */ - public static QName readQName(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.generator.ast.QName readQName(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { de.haumacher.msgbuf.generator.ast.QName result = new de.haumacher.msgbuf.generator.ast.QName(); result.readContent(in); return result; @@ -146,7 +146,7 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(NAMES); + out.name(NAMES__PROP); out.beginArray(); for (String x : getNames()) { out.value(x); @@ -157,7 +157,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case NAMES: { + case NAMES__PROP: { in.beginArray(); while (in.hasNext()) { addName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/StringOption.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/StringOption.java index 70303206..42f25ac7 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/StringOption.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/StringOption.java @@ -6,24 +6,24 @@ public class StringOption extends Option { /** - * Creates a {@link StringOption} instance. + * Creates a {@link de.haumacher.msgbuf.generator.ast.StringOption} instance. */ - public static StringOption create() { + public static de.haumacher.msgbuf.generator.ast.StringOption create() { return new de.haumacher.msgbuf.generator.ast.StringOption(); } - /** Identifier for the {@link StringOption} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.generator.ast.StringOption} type in JSON format. */ public static final String STRING_OPTION__TYPE = "StringOption"; /** @see #getValue() */ - public static final String VALUE = "value"; + public static final String VALUE__PROP = "value"; private String _value = ""; /** * Creates a {@link StringOption} instance. * - * @see StringOption#create() + * @see de.haumacher.msgbuf.generator.ast.StringOption#create() */ protected StringOption() { super(); @@ -44,14 +44,14 @@ public final String getValue() { /** * @see #getValue() */ - public StringOption setValue(String value) { + public de.haumacher.msgbuf.generator.ast.StringOption setValue(String value) { internalSetValue(value); return this; } /** Internal setter for {@link #getValue()} without chain call utility. */ protected final void internalSetValue(String value) { - _listener.beforeSet(this, VALUE, value); + _listener.beforeSet(this, VALUE__PROP, value); _value = value; } @@ -62,7 +62,7 @@ public String jsonType() { private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - VALUE)); + VALUE__PROP)); @Override public java.util.List properties() { @@ -72,7 +72,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case VALUE: return getValue(); + case VALUE__PROP: return getValue(); default: return super.get(field); } } @@ -80,13 +80,13 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case VALUE: internalSetValue((String) value); break; + case VALUE__PROP: internalSetValue((String) value); break; default: super.set(field, value); break; } } /** Reads a new instance from the given reader. */ - public static StringOption readStringOption(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.generator.ast.StringOption readStringOption(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { de.haumacher.msgbuf.generator.ast.StringOption result = new de.haumacher.msgbuf.generator.ast.StringOption(); result.readContent(in); return result; @@ -95,20 +95,20 @@ public static StringOption readStringOption(de.haumacher.msgbuf.json.JsonReader @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(VALUE); + out.name(VALUE__PROP); out.value(getValue()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case VALUE: setValue(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case VALUE__PROP: setValue(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; default: super.readField(in, field); } } @Override - public R visit(Option.Visitor v, A arg) { + public R visit(de.haumacher.msgbuf.generator.ast.Option.Visitor v, A arg) { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Type.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Type.java index c6302235..8b402034 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Type.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Type.java @@ -5,32 +5,32 @@ */ public abstract class Type extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.observer.Observable { - /** Type codes for the {@link Type} hierarchy. */ + /** Type codes for the {@link de.haumacher.msgbuf.generator.ast.Type} hierarchy. */ public enum TypeKind { - /** Type literal for {@link CustomType}. */ + /** Type literal for {@link de.haumacher.msgbuf.generator.ast.CustomType}. */ CUSTOM_TYPE, - /** Type literal for {@link PrimitiveType}. */ + /** Type literal for {@link de.haumacher.msgbuf.generator.ast.PrimitiveType}. */ PRIMITIVE_TYPE, - /** Type literal for {@link MapType}. */ + /** Type literal for {@link de.haumacher.msgbuf.generator.ast.MapType}. */ MAP_TYPE, ; } - /** Visitor interface for the {@link Type} hierarchy.*/ + /** Visitor interface for the {@link de.haumacher.msgbuf.generator.ast.Type} hierarchy.*/ public interface Visitor { - /** Visit case for {@link CustomType}.*/ - R visit(CustomType self, A arg); + /** Visit case for {@link de.haumacher.msgbuf.generator.ast.CustomType}.*/ + R visit(de.haumacher.msgbuf.generator.ast.CustomType self, A arg); - /** Visit case for {@link PrimitiveType}.*/ - R visit(PrimitiveType self, A arg); + /** Visit case for {@link de.haumacher.msgbuf.generator.ast.PrimitiveType}.*/ + R visit(de.haumacher.msgbuf.generator.ast.PrimitiveType self, A arg); - /** Visit case for {@link MapType}.*/ - R visit(MapType self, A arg); + /** Visit case for {@link de.haumacher.msgbuf.generator.ast.MapType}.*/ + R visit(de.haumacher.msgbuf.generator.ast.MapType self, A arg); } @@ -47,7 +47,7 @@ protected Type() { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public Type registerListener(de.haumacher.msgbuf.observer.Listener l) { + public de.haumacher.msgbuf.generator.ast.Type registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -57,7 +57,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public Type unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public de.haumacher.msgbuf.generator.ast.Type unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -67,8 +67,8 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis } /** Reads a new instance from the given reader. */ - public static Type readType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - Type result; + public static de.haumacher.msgbuf.generator.ast.Type readType(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.generator.ast.Type result; in.beginArray(); String type = in.nextString(); switch (type) { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/WithOptions.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/WithOptions.java index 2e301d11..c1fc8f1a 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/WithOptions.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/WithOptions.java @@ -5,45 +5,55 @@ */ public abstract class WithOptions extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.observer.Observable { - /** Type codes for the {@link WithOptions} hierarchy. */ + /** Type codes for the {@link de.haumacher.msgbuf.generator.ast.WithOptions} hierarchy. */ public enum TypeKind { - /** Type literal for {@link OptionContainer}. */ + /** Type literal for {@link de.haumacher.msgbuf.generator.ast.OptionContainer}. */ OPTION_CONTAINER, - /** Type literal for {@link Constant}. */ + /** Type literal for {@link de.haumacher.msgbuf.generator.ast.Constant}. */ CONSTANT, - /** Type literal for {@link Field}. */ + /** Type literal for {@link de.haumacher.msgbuf.generator.ast.Field}. */ FIELD, - /** Type literal for {@link EnumDef}. */ + /** Type literal for {@link de.haumacher.msgbuf.generator.ast.EnumDef}. */ ENUM_DEF, - /** Type literal for {@link MessageDef}. */ + /** Type literal for {@link de.haumacher.msgbuf.generator.ast.MessageDef}. */ MESSAGE_DEF, - /** Type literal for {@link DefinitionFile}. */ + /** Type literal for {@link de.haumacher.msgbuf.generator.ast.DefinitionFile}. */ DEFINITION_FILE, ; } - /** Visitor interface for the {@link WithOptions} hierarchy.*/ - public interface Visitor extends DefinitionBase.Visitor { + /** Visitor interface for the {@link de.haumacher.msgbuf.generator.ast.WithOptions} hierarchy.*/ + public interface Visitor extends de.haumacher.msgbuf.generator.ast.DefinitionBase.Visitor { - /** Visit case for {@link OptionContainer}.*/ - R visit(OptionContainer self, A arg); + /** Visit case for {@link de.haumacher.msgbuf.generator.ast.OptionContainer}.*/ + R visit(de.haumacher.msgbuf.generator.ast.OptionContainer self, A arg); - /** Visit case for {@link DefinitionFile}.*/ - R visit(DefinitionFile self, A arg); + /** Visit case for {@link de.haumacher.msgbuf.generator.ast.DefinitionFile}.*/ + R visit(de.haumacher.msgbuf.generator.ast.DefinitionFile self, A arg); } /** @see #getOptions() */ - public static final String OPTIONS = "options"; + public static final String OPTIONS__PROP = "options"; - private final java.util.Map _options = new java.util.HashMap<>(); + private final java.util.Map _options = new de.haumacher.msgbuf.util.ReferenceMap<>() { + @Override + protected void beforeAdd(String index, de.haumacher.msgbuf.generator.ast.Option element) { + _listener.beforeAdd(WithOptions.this, OPTIONS__PROP, index, element); + } + + @Override + protected void afterRemove(String index, de.haumacher.msgbuf.generator.ast.Option element) { + _listener.afterRemove(WithOptions.this, OPTIONS__PROP, index, element); + } + }; /** * Creates a {@link WithOptions} instance. @@ -58,20 +68,20 @@ protected WithOptions() { /** * Annotations to this definition. */ - public final java.util.Map getOptions() { + public final java.util.Map getOptions() { return _options; } /** * @see #getOptions() */ - public WithOptions setOptions(java.util.Map value) { + public de.haumacher.msgbuf.generator.ast.WithOptions setOptions(java.util.Map value) { internalSetOptions(value); return this; } /** Internal setter for {@link #getOptions()} without chain call utility. */ - protected final void internalSetOptions(java.util.Map value) { + protected final void internalSetOptions(java.util.Map value) { if (value == null) throw new IllegalArgumentException("Property 'options' cannot be null."); _options.clear(); _options.putAll(value); @@ -80,13 +90,13 @@ protected final void internalSetOptions(java.util.Map value) { /** * Adds a key value pair to the {@link #getOptions()} map. */ - public WithOptions putOption(String key, Option value) { + public de.haumacher.msgbuf.generator.ast.WithOptions putOption(String key, de.haumacher.msgbuf.generator.ast.Option value) { internalPutOption(key, value); return this; } - /** Implementation of {@link #putOption(String, Option)} without chain call utility. */ - protected final void internalPutOption(String key, Option value) { + /** Implementation of {@link #putOption(String, de.haumacher.msgbuf.generator.ast.Option)} without chain call utility. */ + protected final void internalPutOption(String key, de.haumacher.msgbuf.generator.ast.Option value) { if (_options.containsKey(key)) { throw new IllegalArgumentException("Property 'options' already contains a value for key '" + key + "'."); } @@ -103,7 +113,7 @@ public final void removeOption(String key) { protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override - public WithOptions registerListener(de.haumacher.msgbuf.observer.Listener l) { + public de.haumacher.msgbuf.generator.ast.WithOptions registerListener(de.haumacher.msgbuf.observer.Listener l) { internalRegisterListener(l); return this; } @@ -113,7 +123,7 @@ protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Liste } @Override - public WithOptions unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + public de.haumacher.msgbuf.generator.ast.WithOptions unregisterListener(de.haumacher.msgbuf.observer.Listener l) { internalUnregisterListener(l); return this; } @@ -124,7 +134,7 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( java.util.Arrays.asList( - OPTIONS)); + OPTIONS__PROP)); @Override public java.util.List properties() { @@ -134,7 +144,7 @@ public java.util.List properties() { @Override public Object get(String field) { switch (field) { - case OPTIONS: return getOptions(); + case OPTIONS__PROP: return getOptions(); default: return null; } } @@ -142,13 +152,13 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { - case OPTIONS: internalSetOptions((java.util.Map) value); break; + case OPTIONS__PROP: internalSetOptions((java.util.Map) value); break; } } /** Reads a new instance from the given reader. */ - public static WithOptions readWithOptions(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - WithOptions result; + public static de.haumacher.msgbuf.generator.ast.WithOptions readWithOptions(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.generator.ast.WithOptions result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -175,9 +185,9 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(OPTIONS); + out.name(OPTIONS__PROP); out.beginObject(); - for (java.util.Map.Entry entry : getOptions().entrySet()) { + for (java.util.Map.Entry entry : getOptions().entrySet()) { out.name(entry.getKey()); entry.getValue().writeTo(out); } @@ -187,7 +197,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case OPTIONS: { + case OPTIONS__PROP: { in.beginObject(); while (in.hasNext()) { putOption(in.nextName(), de.haumacher.msgbuf.generator.ast.Option.readOption(in)); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto index e64ec1d0..be613fb3 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto @@ -1,6 +1,7 @@ package de.haumacher.msgbuf.generator.ast; option NoBinary; +option NoXml; option NoReflection; option NoVisitorExceptions; option NoInterfaces; @@ -88,6 +89,7 @@ message EnumDef extends Definition { /** * {@link Definition} of a data class. */ +@Operations("de.haumacher.msgbuf.generator.MessageDefOperations") message MessageDef extends Definition { /** Whether this class only serves as super type for other data classes. */ boolean `abstract`; From 9ea5b6bf96394f6102b10f16487908da49118028 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 14 Apr 2024 18:32:08 +0200 Subject: [PATCH 058/207] Added missing generation of self() access method for operation mix-ins. --- .../msgbuf/generator/MessageGenerator.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index dbf19fc5..1a4731cb 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -302,6 +302,10 @@ private void generateClassContents() { } if (_interface || _noInterfaces) { + if (_def.getOptions().get("Operations") != null) { + generateSelfAccess(); + } + include(_plugin.messageInterfaceContents(getOptions(), _def)); } @@ -1953,6 +1957,16 @@ private DataType mkBinaryType(PrimitiveType.Kind primitive) { throw new RuntimeException("No such type: " + primitive); } + private void generateSelfAccess() { + nl(); + line("@Override"); + line((_noInterfaces ? "public" : "default") + " " + typeName(_def) + " self() {"); + { + line("return this;"); + } + line("}"); + } + private void generateVisitMethods() { if (_def.isAbstract()) { if (_interface || _noInterfaces) { From b446f32209c456246c16a31da0b6c4a4d5b98968 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 14 Apr 2024 18:34:43 +0200 Subject: [PATCH 059/207] Bugfix: Generated type kind literal even for non-abstract root type. --- .../msgbuf/generator/AbstractMessageGenerator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/AbstractMessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/AbstractMessageGenerator.java index 291729e8..f727e8b0 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/AbstractMessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/AbstractMessageGenerator.java @@ -72,11 +72,11 @@ protected static List concreteSpecializations(MessageDef def) { } private static void addConcreteSpecializations(ArrayList result, MessageDef def) { + if (!def.isAbstract()) { + result.add(def); + } + for (MessageDef specialization : def.getSpecializations()) { - if (!specialization.isAbstract()) { - result.add(specialization); - } - addConcreteSpecializations(result, specialization); } } From 87c6f2dacf684996195e8fdb0441b8f799754d79 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 14 Apr 2024 18:37:43 +0200 Subject: [PATCH 060/207] Added test case for operations mix-in. --- .../java/test/operations/DataOperations.java | 24 +++++++ .../test/operations/ExtendedOperations.java | 24 +++++++ .../java/test/operations/TestOperations.java | 30 +++++++++ .../test/java/test/operations/data/Data.java | 58 ++++++++++++++++ .../test/operations/data/ExtendedData.java | 43 ++++++++++++ .../test/operations/data/impl/Data_Impl.java | 65 ++++++++++++++++++ .../data/impl/ExtendedData_Impl.java | 66 +++++++++++++++++++ .../test/operations/data/operations.proto | 20 ++++++ 8 files changed, 330 insertions(+) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/operations/DataOperations.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/operations/ExtendedOperations.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/operations/TestOperations.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/operations/data/Data.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/operations/data/ExtendedData.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/operations/data/impl/Data_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/operations/data/impl/ExtendedData_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/operations/data/operations.proto diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/operations/DataOperations.java b/de.haumacher.msgbuf.generator/src/test/java/test/operations/DataOperations.java new file mode 100644 index 00000000..b04740e3 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/operations/DataOperations.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Bernhard Haumacher et al. All Rights Reserved. + */ +package test.operations; + +import test.operations.data.Data; + +/** + * Operations mix-in for the {@link Data} class. + */ +public interface DataOperations { + + /** + * Access to the data class. + */ + Data self(); + + /** + * Increments {@link Data#getX()} + */ + default void inc() { + self().setX(self().getX() + 1); + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/operations/ExtendedOperations.java b/de.haumacher.msgbuf.generator/src/test/java/test/operations/ExtendedOperations.java new file mode 100644 index 00000000..b2d56037 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/operations/ExtendedOperations.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 Bernhard Haumacher et al. All Rights Reserved. + */ +package test.operations; + +import test.operations.data.Data; +import test.operations.data.ExtendedData; + +/** + * Mix-in interface for the extended data class {@link ExtendedData}. + */ +public interface ExtendedOperations extends DataOperations { + + @Override + public ExtendedData self(); + + + /** + * Adds the current {@link Data#getX()} value to {@link ExtendedData#getY()}. + */ + default void addToY() { + self().setY(self().getY() + self().getX()); + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/operations/TestOperations.java b/de.haumacher.msgbuf.generator/src/test/java/test/operations/TestOperations.java new file mode 100644 index 00000000..a4b13e64 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/operations/TestOperations.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Bernhard Haumacher et al. All Rights Reserved. + */ +package test.operations; + +import junit.framework.TestCase; +import test.operations.data.Data; +import test.operations.data.ExtendedData; + +/** + * Test case for data classes with operation mix-ins. + */ +@SuppressWarnings("javadoc") +public class TestOperations extends TestCase { + + public void testOperations() { + Data data = Data.create(); + data.inc(); + data.inc(); + assertEquals(2, data.getX()); + + ExtendedData extended = ExtendedData.create(); + extended.inc(); + extended.inc(); + extended.addToY(); + extended.addToY(); + assertEquals(2, extended.getX()); + assertEquals(4, extended.getY()); + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/operations/data/Data.java b/de.haumacher.msgbuf.generator/src/test/java/test/operations/data/Data.java new file mode 100644 index 00000000..5a258f31 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/operations/data/Data.java @@ -0,0 +1,58 @@ +package test.operations.data; + +/** + * Data class for testing operation mix-ins. + */ +public interface Data extends de.haumacher.msgbuf.data.DataObject, test.operations.DataOperations { + + /** Type codes for the {@link test.operations.data.Data} hierarchy. */ + public enum TypeKind { + + /** Type literal for {@link test.operations.data.Data}. */ + DATA, + + /** Type literal for {@link test.operations.data.ExtendedData}. */ + EXTENDED_DATA, + ; + + } + + /** + * Creates a {@link test.operations.data.Data} instance. + */ + static test.operations.data.Data create() { + return new test.operations.data.impl.Data_Impl(); + } + + /** Identifier for the {@link test.operations.data.Data} type in JSON format. */ + String DATA__TYPE = "Data"; + + /** @see #getX() */ + String X__PROP = "x"; + + /** The type code of this instance. */ + TypeKind kind(); + + /** + * Some integer data field. + */ + int getX(); + + /** + * @see #getX() + */ + test.operations.data.Data setX(int value); + + /** Reads a new instance from the given reader. */ + static test.operations.data.Data readData(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.operations.data.impl.Data_Impl result = new test.operations.data.impl.Data_Impl(); + result.readContent(in); + return result; + } + + @Override + default Data self() { + return this; + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/operations/data/ExtendedData.java b/de.haumacher.msgbuf.generator/src/test/java/test/operations/data/ExtendedData.java new file mode 100644 index 00000000..16716b1a --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/operations/data/ExtendedData.java @@ -0,0 +1,43 @@ +package test.operations.data; + +public interface ExtendedData extends Data, test.operations.ExtendedOperations { + + /** + * Creates a {@link test.operations.data.ExtendedData} instance. + */ + static test.operations.data.ExtendedData create() { + return new test.operations.data.impl.ExtendedData_Impl(); + } + + /** Identifier for the {@link test.operations.data.ExtendedData} type in JSON format. */ + String EXTENDED_DATA__TYPE = "ExtendedData"; + + /** @see #getY() */ + String Y__PROP = "y"; + + /** + * Some other integer data field. + */ + int getY(); + + /** + * @see #getY() + */ + test.operations.data.ExtendedData setY(int value); + + @Override + test.operations.data.ExtendedData setX(int value); + + /** Reads a new instance from the given reader. */ + static test.operations.data.ExtendedData readExtendedData(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.operations.data.impl.ExtendedData_Impl result = new test.operations.data.impl.ExtendedData_Impl(); + result.readContent(in); + return result; + } + + @Override + default ExtendedData self() { + return this; + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/operations/data/impl/Data_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/operations/data/impl/Data_Impl.java new file mode 100644 index 00000000..117de3db --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/operations/data/impl/Data_Impl.java @@ -0,0 +1,65 @@ +package test.operations.data.impl; + +/** + * Implementation of {@link test.operations.data.Data}. + */ +public class Data_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.operations.data.Data { + + private int _x = 0; + + /** + * Creates a {@link Data_Impl} instance. + * + * @see test.operations.data.Data#create() + */ + public Data_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.DATA; + } + + @Override + public final int getX() { + return _x; + } + + @Override + public test.operations.data.Data setX(int value) { + internalSetX(value); + return this; + } + + /** Internal setter for {@link #getX()} without chain call utility. */ + protected final void internalSetX(int value) { + _x = value; + } + + /** The type identifier for this concrete subtype. */ + public String jsonType() { + return DATA__TYPE; + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(X__PROP); + out.value(getX()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case X__PROP: setX(in.nextInt()); break; + default: super.readField(in, field); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/operations/data/impl/ExtendedData_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/operations/data/impl/ExtendedData_Impl.java new file mode 100644 index 00000000..48cf4830 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/operations/data/impl/ExtendedData_Impl.java @@ -0,0 +1,66 @@ +package test.operations.data.impl; + +/** + * Implementation of {@link test.operations.data.ExtendedData}. + */ +public class ExtendedData_Impl extends test.operations.data.impl.Data_Impl implements test.operations.data.ExtendedData { + + private int _y = 0; + + /** + * Creates a {@link ExtendedData_Impl} instance. + * + * @see test.operations.data.ExtendedData#create() + */ + public ExtendedData_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.EXTENDED_DATA; + } + + @Override + public final int getY() { + return _y; + } + + @Override + public test.operations.data.ExtendedData setY(int value) { + internalSetY(value); + return this; + } + + /** Internal setter for {@link #getY()} without chain call utility. */ + protected final void internalSetY(int value) { + _y = value; + } + + @Override + public test.operations.data.ExtendedData setX(int value) { + internalSetX(value); + return this; + } + + @Override + public String jsonType() { + return EXTENDED_DATA__TYPE; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(Y__PROP); + out.value(getY()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case Y__PROP: setY(in.nextInt()); break; + default: super.readField(in, field); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/operations/data/operations.proto b/de.haumacher.msgbuf.generator/src/test/java/test/operations/data/operations.proto new file mode 100644 index 00000000..c740238f --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/operations/data/operations.proto @@ -0,0 +1,20 @@ +package test.operations.data; + +option NoBinary; +option NoXml; +option NoReflection; +option NoVisitorExceptions; +option NoListener; + +/** Data class for testing operation mix-ins. */ +@Operations("test.operations.DataOperations") +message Data { + /** Some integer data field. */ + int x; +} + +@Operations("test.operations.ExtendedOperations") +message ExtendedData extends Data { + /** Some other integer data field. */ + int y; +} \ No newline at end of file From b3cb55eb9c91b06f9aa9a2a01c14b0a0d7a76e4c Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 14 Apr 2024 19:16:54 +0200 Subject: [PATCH 061/207] Added test case for embedding references in XML serialization. --- .../test/java/test/embedded/TestEmbedded.java | 53 +++ .../src/test/java/test/embedded/data/A.java | 39 ++ .../src/test/java/test/embedded/data/B.java | 39 ++ .../test/java/test/embedded/data/Base.java | 79 ++++ .../java/test/embedded/data/Container.java | 78 ++++ .../embedded/data/EmbeddingContainer.java | 78 ++++ .../data/EmbeddingSingleContainer.java | 73 ++++ .../test/embedded/data/SingleContainer.java | 73 ++++ .../java/test/embedded/data/embedded.proto | 43 +++ .../java/test/embedded/data/impl/A_Impl.java | 90 +++++ .../java/test/embedded/data/impl/B_Impl.java | 90 +++++ .../test/embedded/data/impl/Base_Impl.java | 164 ++++++++ .../embedded/data/impl/Container_Impl.java | 341 +++++++++++++++++ .../data/impl/EmbeddingContainer_Impl.java | 349 ++++++++++++++++++ .../impl/EmbeddingSingleContainer_Impl.java | 297 +++++++++++++++ .../data/impl/SingleContainer_Impl.java | 289 +++++++++++++++ 16 files changed, 2175 insertions(+) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/TestEmbedded.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/A.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/B.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/Base.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/Container.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/EmbeddingContainer.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/EmbeddingSingleContainer.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/SingleContainer.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/embedded.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/A_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/B_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Base_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/TestEmbedded.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/TestEmbedded.java new file mode 100644 index 00000000..824c78d4 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/TestEmbedded.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 Bernhard Haumacher et al. All Rights Reserved. + */ +package test.embedded; + +import java.io.StringReader; + +import javax.xml.stream.FactoryConfigurationError; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; +import test.embedded.data.Container; +import test.embedded.data.EmbeddingContainer; +import test.embedded.data.EmbeddingSingleContainer; +import test.embedded.data.SingleContainer; + +/** + * Test case for embedding references in XML serialization. + */ +@SuppressWarnings("javadoc") +public class TestEmbedded extends TestCase { + + public void testRead() throws XMLStreamException, FactoryConfigurationError { + Container container = Container.readContainer(reader("")); + assertEquals(2, container.getContents().size()); + } + + public void testReadEmbedding() throws XMLStreamException, FactoryConfigurationError { + EmbeddingContainer container1 = EmbeddingContainer.readEmbeddingContainer(reader("")); + EmbeddingContainer container2 = EmbeddingContainer.readEmbeddingContainer(reader("")); + assertEquals(2, container1.getContents().size()); + assertEquals(2, container2.getContents().size()); + } + + public void testReadSingle() throws XMLStreamException, FactoryConfigurationError { + SingleContainer container = SingleContainer.readSingleContainer(reader("")); + assertNotNull(container.getContents()); + } + + public void testReadSingleEmbedding() throws XMLStreamException, FactoryConfigurationError { + EmbeddingSingleContainer container1 = EmbeddingSingleContainer.readEmbeddingSingleContainer(reader("")); + EmbeddingSingleContainer container2 = EmbeddingSingleContainer.readEmbeddingSingleContainer(reader("")); + assertNotNull(container1.getContents()); + assertNotNull(container2.getContents()); + } + + + private XMLStreamReader reader(String xml) throws XMLStreamException, FactoryConfigurationError { + return XMLInputFactory.newFactory().createXMLStreamReader(new StringReader(xml)); + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/A.java new file mode 100644 index 00000000..9f4db576 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/A.java @@ -0,0 +1,39 @@ +package test.embedded.data; + +public interface A extends Base { + + /** + * Creates a {@link test.embedded.data.A} instance. + */ + static test.embedded.data.A create() { + return new test.embedded.data.impl.A_Impl(); + } + + /** Identifier for the {@link test.embedded.data.A} type in JSON format. */ + String A__TYPE = "A"; + + /** Identifier for the {@link test.embedded.data.A} type in binary format. */ + static final int A__TYPE_ID = 1; + + /** Reads a new instance from the given reader. */ + static test.embedded.data.A readA(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.embedded.data.impl.A_Impl result = new test.embedded.data.impl.A_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.embedded.data.A readA(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.embedded.data.A result = test.embedded.data.impl.A_Impl.readA_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static A readA(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.embedded.data.impl.A_Impl.readA_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/B.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/B.java new file mode 100644 index 00000000..d227a63d --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/B.java @@ -0,0 +1,39 @@ +package test.embedded.data; + +public interface B extends Base { + + /** + * Creates a {@link test.embedded.data.B} instance. + */ + static test.embedded.data.B create() { + return new test.embedded.data.impl.B_Impl(); + } + + /** Identifier for the {@link test.embedded.data.B} type in JSON format. */ + String B__TYPE = "B"; + + /** Identifier for the {@link test.embedded.data.B} type in binary format. */ + static final int B__TYPE_ID = 2; + + /** Reads a new instance from the given reader. */ + static test.embedded.data.B readB(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.embedded.data.impl.B_Impl result = new test.embedded.data.impl.B_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.embedded.data.B readB(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.embedded.data.B result = test.embedded.data.impl.B_Impl.readB_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static B readB(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.embedded.data.impl.B_Impl.readB_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/Base.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/Base.java new file mode 100644 index 00000000..fd7e6d97 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/Base.java @@ -0,0 +1,79 @@ +package test.embedded.data; + +public interface Base extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** Type codes for the {@link test.embedded.data.Base} hierarchy. */ + public enum TypeKind { + + /** Type literal for {@link test.embedded.data.A}. */ + A, + + /** Type literal for {@link test.embedded.data.B}. */ + B, + ; + + } + + /** Visitor interface for the {@link test.embedded.data.Base} hierarchy.*/ + public interface Visitor { + + /** Visit case for {@link test.embedded.data.A}.*/ + R visit(test.embedded.data.A self, A arg) throws E; + + /** Visit case for {@link test.embedded.data.B}.*/ + R visit(test.embedded.data.B self, A arg) throws E; + + } + + /** The type code of this instance. */ + TypeKind kind(); + + @Override + public test.embedded.data.Base registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.embedded.data.Base unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.embedded.data.Base readBase(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.embedded.data.Base result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case A.A__TYPE: result = test.embedded.data.A.readA(in); break; + case B.B__TYPE: result = test.embedded.data.B.readB(in); break; + default: in.skipValue(); result = null; break; + } + in.endArray(); + return result; + } + + /** The binary identifier for this concrete type in the polymorphic {@link test.embedded.data.Base} hierarchy. */ + abstract int typeId(); + + /** Reads a new instance from the given reader. */ + static test.embedded.data.Base readBase(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + int typeField = in.nextName(); + assert typeField == 0; + int type = in.nextInt(); + test.embedded.data.Base result; + switch (type) { + case test.embedded.data.A.A__TYPE_ID: result = test.embedded.data.impl.A_Impl.readA_Content(in); break; + case test.embedded.data.B.B__TYPE_ID: result = test.embedded.data.impl.B_Impl.readB_Content(in); break; + default: result = null; while (in.hasNext()) {in.skipValue(); } + } + in.endObject(); + return result; + } + + /** Creates a new {@link Base} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Base readBase(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.embedded.data.impl.Base_Impl.readBase_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/Container.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/Container.java new file mode 100644 index 00000000..928339c2 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/Container.java @@ -0,0 +1,78 @@ +package test.embedded.data; + +public interface Container extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.embedded.data.Container} instance. + */ + static test.embedded.data.Container create() { + return new test.embedded.data.impl.Container_Impl(); + } + + /** Identifier for the {@link test.embedded.data.Container} type in JSON format. */ + String CONTAINER__TYPE = "Container"; + + /** @see #getName() */ + String NAME__PROP = "name"; + + /** @see #getContents() */ + String CONTENTS__PROP = "contents"; + + /** Identifier for the property {@link #getName()} in binary format. */ + static final int NAME__ID = 1; + + /** Identifier for the property {@link #getContents()} in binary format. */ + static final int CONTENTS__ID = 2; + + String getName(); + + /** + * @see #getName() + */ + test.embedded.data.Container setName(String value); + + java.util.List getContents(); + + /** + * @see #getContents() + */ + test.embedded.data.Container setContents(java.util.List value); + + /** + * Adds a value to the {@link #getContents()} list. + */ + test.embedded.data.Container addContent(test.embedded.data.Base value); + + /** + * Removes a value from the {@link #getContents()} list. + */ + void removeContent(test.embedded.data.Base value); + + @Override + public test.embedded.data.Container registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.embedded.data.Container unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.embedded.data.Container readContainer(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.embedded.data.impl.Container_Impl result = new test.embedded.data.impl.Container_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.embedded.data.Container readContainer(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.embedded.data.Container result = test.embedded.data.impl.Container_Impl.readContainer_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Container} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Container readContainer(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.embedded.data.impl.Container_Impl.readContainer_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/EmbeddingContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/EmbeddingContainer.java new file mode 100644 index 00000000..f0c3fb18 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/EmbeddingContainer.java @@ -0,0 +1,78 @@ +package test.embedded.data; + +public interface EmbeddingContainer extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.embedded.data.EmbeddingContainer} instance. + */ + static test.embedded.data.EmbeddingContainer create() { + return new test.embedded.data.impl.EmbeddingContainer_Impl(); + } + + /** Identifier for the {@link test.embedded.data.EmbeddingContainer} type in JSON format. */ + String EMBEDDING_CONTAINER__TYPE = "EmbeddingContainer"; + + /** @see #getName() */ + String NAME__PROP = "name"; + + /** @see #getContents() */ + String CONTENTS__PROP = "contents"; + + /** Identifier for the property {@link #getName()} in binary format. */ + static final int NAME__ID = 1; + + /** Identifier for the property {@link #getContents()} in binary format. */ + static final int CONTENTS__ID = 2; + + String getName(); + + /** + * @see #getName() + */ + test.embedded.data.EmbeddingContainer setName(String value); + + java.util.List getContents(); + + /** + * @see #getContents() + */ + test.embedded.data.EmbeddingContainer setContents(java.util.List value); + + /** + * Adds a value to the {@link #getContents()} list. + */ + test.embedded.data.EmbeddingContainer addContent(test.embedded.data.Base value); + + /** + * Removes a value from the {@link #getContents()} list. + */ + void removeContent(test.embedded.data.Base value); + + @Override + public test.embedded.data.EmbeddingContainer registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.embedded.data.EmbeddingContainer unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.embedded.data.EmbeddingContainer readEmbeddingContainer(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.embedded.data.impl.EmbeddingContainer_Impl result = new test.embedded.data.impl.EmbeddingContainer_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.embedded.data.EmbeddingContainer readEmbeddingContainer(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.embedded.data.EmbeddingContainer result = test.embedded.data.impl.EmbeddingContainer_Impl.readEmbeddingContainer_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link EmbeddingContainer} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static EmbeddingContainer readEmbeddingContainer(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.embedded.data.impl.EmbeddingContainer_Impl.readEmbeddingContainer_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/EmbeddingSingleContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/EmbeddingSingleContainer.java new file mode 100644 index 00000000..c9688742 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/EmbeddingSingleContainer.java @@ -0,0 +1,73 @@ +package test.embedded.data; + +public interface EmbeddingSingleContainer extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.embedded.data.EmbeddingSingleContainer} instance. + */ + static test.embedded.data.EmbeddingSingleContainer create() { + return new test.embedded.data.impl.EmbeddingSingleContainer_Impl(); + } + + /** Identifier for the {@link test.embedded.data.EmbeddingSingleContainer} type in JSON format. */ + String EMBEDDING_SINGLE_CONTAINER__TYPE = "EmbeddingSingleContainer"; + + /** @see #getName() */ + String NAME__PROP = "name"; + + /** @see #getContents() */ + String CONTENTS__PROP = "contents"; + + /** Identifier for the property {@link #getName()} in binary format. */ + static final int NAME__ID = 1; + + /** Identifier for the property {@link #getContents()} in binary format. */ + static final int CONTENTS__ID = 2; + + String getName(); + + /** + * @see #getName() + */ + test.embedded.data.EmbeddingSingleContainer setName(String value); + + test.embedded.data.Base getContents(); + + /** + * @see #getContents() + */ + test.embedded.data.EmbeddingSingleContainer setContents(test.embedded.data.Base value); + + /** + * Checks, whether {@link #getContents()} has a value. + */ + boolean hasContents(); + + @Override + public test.embedded.data.EmbeddingSingleContainer registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.embedded.data.EmbeddingSingleContainer unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.embedded.data.EmbeddingSingleContainer readEmbeddingSingleContainer(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.embedded.data.impl.EmbeddingSingleContainer_Impl result = new test.embedded.data.impl.EmbeddingSingleContainer_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.embedded.data.EmbeddingSingleContainer readEmbeddingSingleContainer(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.embedded.data.EmbeddingSingleContainer result = test.embedded.data.impl.EmbeddingSingleContainer_Impl.readEmbeddingSingleContainer_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link EmbeddingSingleContainer} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static EmbeddingSingleContainer readEmbeddingSingleContainer(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.embedded.data.impl.EmbeddingSingleContainer_Impl.readEmbeddingSingleContainer_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/SingleContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/SingleContainer.java new file mode 100644 index 00000000..e345a40f --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/SingleContainer.java @@ -0,0 +1,73 @@ +package test.embedded.data; + +public interface SingleContainer extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.embedded.data.SingleContainer} instance. + */ + static test.embedded.data.SingleContainer create() { + return new test.embedded.data.impl.SingleContainer_Impl(); + } + + /** Identifier for the {@link test.embedded.data.SingleContainer} type in JSON format. */ + String SINGLE_CONTAINER__TYPE = "SingleContainer"; + + /** @see #getName() */ + String NAME__PROP = "name"; + + /** @see #getContents() */ + String CONTENTS__PROP = "contents"; + + /** Identifier for the property {@link #getName()} in binary format. */ + static final int NAME__ID = 1; + + /** Identifier for the property {@link #getContents()} in binary format. */ + static final int CONTENTS__ID = 2; + + String getName(); + + /** + * @see #getName() + */ + test.embedded.data.SingleContainer setName(String value); + + test.embedded.data.Base getContents(); + + /** + * @see #getContents() + */ + test.embedded.data.SingleContainer setContents(test.embedded.data.Base value); + + /** + * Checks, whether {@link #getContents()} has a value. + */ + boolean hasContents(); + + @Override + public test.embedded.data.SingleContainer registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.embedded.data.SingleContainer unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.embedded.data.SingleContainer readSingleContainer(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.embedded.data.impl.SingleContainer_Impl result = new test.embedded.data.impl.SingleContainer_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.embedded.data.SingleContainer readSingleContainer(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.embedded.data.SingleContainer result = test.embedded.data.impl.SingleContainer_Impl.readSingleContainer_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link SingleContainer} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SingleContainer readSingleContainer(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.embedded.data.impl.SingleContainer_Impl.readSingleContainer_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/embedded.proto b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/embedded.proto new file mode 100644 index 00000000..256b4703 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/embedded.proto @@ -0,0 +1,43 @@ +package test.embedded.data; + +message Container { + + string name; + + repeated Base contents; + +} + +message EmbeddingContainer { + + string name; + + @Embedded + repeated Base contents; + +} + +message SingleContainer { + + string name; + + Base contents; + +} + +message EmbeddingSingleContainer { + + string name; + + @Embedded + Base contents; + +} + +abstract message Base { + +} + +message A extends Base {} + +message B extends Base {} \ No newline at end of file diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/A_Impl.java new file mode 100644 index 00000000..9028a237 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/A_Impl.java @@ -0,0 +1,90 @@ +package test.embedded.data.impl; + +/** + * Implementation of {@link test.embedded.data.A}. + */ +public class A_Impl extends test.embedded.data.impl.Base_Impl implements test.embedded.data.A { + + /** + * Creates a {@link A_Impl} instance. + * + * @see test.embedded.data.A#create() + */ + public A_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.A; + } + + @Override + public String jsonType() { + return A__TYPE; + } + + @Override + public int typeId() { + return A__TYPE_ID; + } + + /** Helper for creating an object of type {@link test.embedded.data.A} from a polymorphic composition. */ + public static test.embedded.data.A readA_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.embedded.data.impl.A_Impl result = new A_Impl(); + result.readContent(in); + return result; + } + + /** XML element name representing a {@link test.embedded.data.A} type. */ + public static final String A__XML_ELEMENT = "a"; + + @Override + public String getXmlTagName() { + return A__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.embedded.data.A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static A_Impl readA_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + A_Impl result = new A_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.embedded.data.Base.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/B_Impl.java new file mode 100644 index 00000000..7c7a28a9 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/B_Impl.java @@ -0,0 +1,90 @@ +package test.embedded.data.impl; + +/** + * Implementation of {@link test.embedded.data.B}. + */ +public class B_Impl extends test.embedded.data.impl.Base_Impl implements test.embedded.data.B { + + /** + * Creates a {@link B_Impl} instance. + * + * @see test.embedded.data.B#create() + */ + public B_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.B; + } + + @Override + public String jsonType() { + return B__TYPE; + } + + @Override + public int typeId() { + return B__TYPE_ID; + } + + /** Helper for creating an object of type {@link test.embedded.data.B} from a polymorphic composition. */ + public static test.embedded.data.B readB_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.embedded.data.impl.B_Impl result = new B_Impl(); + result.readContent(in); + return result; + } + + /** XML element name representing a {@link test.embedded.data.B} type. */ + public static final String B__XML_ELEMENT = "b"; + + @Override + public String getXmlTagName() { + return B__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.embedded.data.B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static B_Impl readB_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + B_Impl result = new B_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.embedded.data.Base.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Base_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Base_Impl.java new file mode 100644 index 00000000..ef9f3828 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Base_Impl.java @@ -0,0 +1,164 @@ +package test.embedded.data.impl; + +/** + * Implementation of {@link test.embedded.data.Base}. + */ +public abstract class Base_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.embedded.data.Base { + + /** + * Creates a {@link Base_Impl} instance. + */ + public Base_Impl() { + super(); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.embedded.data.Base registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.embedded.data.Base unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.beginArray(); + out.value(jsonType()); + writeContent(out); + out.endArray(); + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + out.name(0); + out.value(typeId()); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + // No fields to write, hook for subclasses. + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.embedded.data.Base} type. */ + public static final String BASE__XML_ELEMENT = "base"; + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.embedded.data.Base} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Base_Impl readBase_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case A_Impl.A__XML_ELEMENT: { + return test.embedded.data.impl.A_Impl.readA_XmlContent(in); + } + + case B_Impl.B__XML_ELEMENT: { + return test.embedded.data.impl.B_Impl.readB_XmlContent(in); + } + + default: { + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java new file mode 100644 index 00000000..818b473c --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java @@ -0,0 +1,341 @@ +package test.embedded.data.impl; + +/** + * Implementation of {@link test.embedded.data.Container}. + */ +public class Container_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.embedded.data.Container { + + private String _name = ""; + + private final java.util.List _contents = new de.haumacher.msgbuf.util.ReferenceList<>() { + @Override + protected void beforeAdd(int index, test.embedded.data.Base element) { + _listener.beforeAdd(Container_Impl.this, CONTENTS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.embedded.data.Base element) { + _listener.afterRemove(Container_Impl.this, CONTENTS__PROP, index, element); + } + }; + + /** + * Creates a {@link Container_Impl} instance. + * + * @see test.embedded.data.Container#create() + */ + public Container_Impl() { + super(); + } + + @Override + public final String getName() { + return _name; + } + + @Override + public test.embedded.data.Container setName(String value) { + internalSetName(value); + return this; + } + + /** Internal setter for {@link #getName()} without chain call utility. */ + protected final void internalSetName(String value) { + _listener.beforeSet(this, NAME__PROP, value); + _name = value; + } + + @Override + public final java.util.List getContents() { + return _contents; + } + + @Override + public test.embedded.data.Container setContents(java.util.List value) { + internalSetContents(value); + return this; + } + + /** Internal setter for {@link #getContents()} without chain call utility. */ + protected final void internalSetContents(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'contents' cannot be null."); + _contents.clear(); + _contents.addAll(value); + } + + @Override + public test.embedded.data.Container addContent(test.embedded.data.Base value) { + internalAddContent(value); + return this; + } + + /** Implementation of {@link #addContent(test.embedded.data.Base)} without chain call utility. */ + protected final void internalAddContent(test.embedded.data.Base value) { + _contents.add(value); + } + + @Override + public final void removeContent(test.embedded.data.Base value) { + _contents.remove(value); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.embedded.data.Container registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.embedded.data.Container unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return CONTAINER__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + NAME__PROP, + CONTENTS__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NAME__PROP: return getName(); + case CONTENTS__PROP: return getContents(); + default: return test.embedded.data.Container.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NAME__PROP: internalSetName((String) value); break; + case CONTENTS__PROP: internalSetContents(de.haumacher.msgbuf.util.Conversions.asList(test.embedded.data.Base.class, value)); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NAME__PROP); + out.value(getName()); + out.name(CONTENTS__PROP); + out.beginArray(); + for (test.embedded.data.Base x : getContents()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case CONTENTS__PROP: { + in.beginArray(); + while (in.hasNext()) { + addContent(test.embedded.data.Base.readBase(in)); + } + in.endArray(); + } + break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(NAME__ID); + out.value(getName()); + out.name(CONTENTS__ID); + { + java.util.List values = getContents(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.embedded.data.Base x : values) { + x.writeTo(out); + } + out.endArray(); + } + } + + /** Helper for creating an object of type {@link test.embedded.data.Container} from a polymorphic composition. */ + public static test.embedded.data.Container readContainer_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.embedded.data.impl.Container_Impl result = new Container_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case NAME__ID: setName(in.nextString()); break; + case CONTENTS__ID: { + in.beginArray(); + while (in.hasNext()) { + addContent(test.embedded.data.Base.readBase(in)); + } + in.endArray(); + } + break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.embedded.data.Container} type. */ + public static final String CONTAINER__XML_ELEMENT = "container"; + + /** XML attribute or element name of a {@link #getName} property. */ + private static final String NAME__XML_ATTR = "name"; + + /** XML attribute or element name of a {@link #getContents} property. */ + private static final String CONTENTS__XML_ATTR = "contents"; + + @Override + public String getXmlTagName() { + return CONTAINER__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeStartElement(CONTENTS__XML_ATTR); + for (test.embedded.data.Base element : getContents()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.embedded.data.Container} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Container_Impl readContainer_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Container_Impl result = new Container_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NAME__XML_ATTR: { + setName(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NAME__XML_ATTR: { + setName(in.getElementText()); + break; + } + case CONTENTS__XML_ATTR: { + internalReadContentsListXml(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadContentsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addContent(test.embedded.data.impl.Base_Impl.readBase_XmlContent(in)); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java new file mode 100644 index 00000000..a8584a77 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java @@ -0,0 +1,349 @@ +package test.embedded.data.impl; + +/** + * Implementation of {@link test.embedded.data.EmbeddingContainer}. + */ +public class EmbeddingContainer_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.embedded.data.EmbeddingContainer { + + private String _name = ""; + + private final java.util.List _contents = new de.haumacher.msgbuf.util.ReferenceList<>() { + @Override + protected void beforeAdd(int index, test.embedded.data.Base element) { + _listener.beforeAdd(EmbeddingContainer_Impl.this, CONTENTS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.embedded.data.Base element) { + _listener.afterRemove(EmbeddingContainer_Impl.this, CONTENTS__PROP, index, element); + } + }; + + /** + * Creates a {@link EmbeddingContainer_Impl} instance. + * + * @see test.embedded.data.EmbeddingContainer#create() + */ + public EmbeddingContainer_Impl() { + super(); + } + + @Override + public final String getName() { + return _name; + } + + @Override + public test.embedded.data.EmbeddingContainer setName(String value) { + internalSetName(value); + return this; + } + + /** Internal setter for {@link #getName()} without chain call utility. */ + protected final void internalSetName(String value) { + _listener.beforeSet(this, NAME__PROP, value); + _name = value; + } + + @Override + public final java.util.List getContents() { + return _contents; + } + + @Override + public test.embedded.data.EmbeddingContainer setContents(java.util.List value) { + internalSetContents(value); + return this; + } + + /** Internal setter for {@link #getContents()} without chain call utility. */ + protected final void internalSetContents(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'contents' cannot be null."); + _contents.clear(); + _contents.addAll(value); + } + + @Override + public test.embedded.data.EmbeddingContainer addContent(test.embedded.data.Base value) { + internalAddContent(value); + return this; + } + + /** Implementation of {@link #addContent(test.embedded.data.Base)} without chain call utility. */ + protected final void internalAddContent(test.embedded.data.Base value) { + _contents.add(value); + } + + @Override + public final void removeContent(test.embedded.data.Base value) { + _contents.remove(value); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.embedded.data.EmbeddingContainer registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.embedded.data.EmbeddingContainer unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return EMBEDDING_CONTAINER__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + NAME__PROP, + CONTENTS__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NAME__PROP: return getName(); + case CONTENTS__PROP: return getContents(); + default: return test.embedded.data.EmbeddingContainer.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NAME__PROP: internalSetName((String) value); break; + case CONTENTS__PROP: internalSetContents(de.haumacher.msgbuf.util.Conversions.asList(test.embedded.data.Base.class, value)); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NAME__PROP); + out.value(getName()); + out.name(CONTENTS__PROP); + out.beginArray(); + for (test.embedded.data.Base x : getContents()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case CONTENTS__PROP: { + in.beginArray(); + while (in.hasNext()) { + addContent(test.embedded.data.Base.readBase(in)); + } + in.endArray(); + } + break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(NAME__ID); + out.value(getName()); + out.name(CONTENTS__ID); + { + java.util.List values = getContents(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.embedded.data.Base x : values) { + x.writeTo(out); + } + out.endArray(); + } + } + + /** Helper for creating an object of type {@link test.embedded.data.EmbeddingContainer} from a polymorphic composition. */ + public static test.embedded.data.EmbeddingContainer readEmbeddingContainer_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.embedded.data.impl.EmbeddingContainer_Impl result = new EmbeddingContainer_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case NAME__ID: setName(in.nextString()); break; + case CONTENTS__ID: { + in.beginArray(); + while (in.hasNext()) { + addContent(test.embedded.data.Base.readBase(in)); + } + in.endArray(); + } + break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.embedded.data.EmbeddingContainer} type. */ + public static final String EMBEDDING_CONTAINER__XML_ELEMENT = "embedding-container"; + + /** XML attribute or element name of a {@link #getName} property. */ + private static final String NAME__XML_ATTR = "name"; + + /** XML attribute or element name of a {@link #getContents} property. */ + private static final String CONTENTS__XML_ATTR = "contents"; + + @Override + public String getXmlTagName() { + return EMBEDDING_CONTAINER__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeStartElement(CONTENTS__XML_ATTR); + for (test.embedded.data.Base element : getContents()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.embedded.data.EmbeddingContainer} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static EmbeddingContainer_Impl readEmbeddingContainer_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + EmbeddingContainer_Impl result = new EmbeddingContainer_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NAME__XML_ATTR: { + setName(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NAME__XML_ATTR: { + setName(in.getElementText()); + break; + } + case test.embedded.data.impl.A_Impl.A__XML_ELEMENT: { + addContent(test.embedded.data.impl.A_Impl.readA_XmlContent(in)); + break; + } + case test.embedded.data.impl.B_Impl.B__XML_ELEMENT: { + addContent(test.embedded.data.impl.B_Impl.readB_XmlContent(in)); + break; + } + case CONTENTS__XML_ATTR: { + internalReadContentsListXml(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadContentsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addContent(test.embedded.data.impl.Base_Impl.readBase_XmlContent(in)); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java new file mode 100644 index 00000000..355e5597 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java @@ -0,0 +1,297 @@ +package test.embedded.data.impl; + +/** + * Implementation of {@link test.embedded.data.EmbeddingSingleContainer}. + */ +public class EmbeddingSingleContainer_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.embedded.data.EmbeddingSingleContainer { + + private String _name = ""; + + private test.embedded.data.Base _contents = null; + + /** + * Creates a {@link EmbeddingSingleContainer_Impl} instance. + * + * @see test.embedded.data.EmbeddingSingleContainer#create() + */ + public EmbeddingSingleContainer_Impl() { + super(); + } + + @Override + public final String getName() { + return _name; + } + + @Override + public test.embedded.data.EmbeddingSingleContainer setName(String value) { + internalSetName(value); + return this; + } + + /** Internal setter for {@link #getName()} without chain call utility. */ + protected final void internalSetName(String value) { + _listener.beforeSet(this, NAME__PROP, value); + _name = value; + } + + @Override + public final test.embedded.data.Base getContents() { + return _contents; + } + + @Override + public test.embedded.data.EmbeddingSingleContainer setContents(test.embedded.data.Base value) { + internalSetContents(value); + return this; + } + + /** Internal setter for {@link #getContents()} without chain call utility. */ + protected final void internalSetContents(test.embedded.data.Base value) { + _listener.beforeSet(this, CONTENTS__PROP, value); + _contents = value; + } + + @Override + public final boolean hasContents() { + return _contents != null; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.embedded.data.EmbeddingSingleContainer registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.embedded.data.EmbeddingSingleContainer unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return EMBEDDING_SINGLE_CONTAINER__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + NAME__PROP, + CONTENTS__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NAME__PROP: return getName(); + case CONTENTS__PROP: return getContents(); + default: return test.embedded.data.EmbeddingSingleContainer.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NAME__PROP: internalSetName((String) value); break; + case CONTENTS__PROP: internalSetContents((test.embedded.data.Base) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NAME__PROP); + out.value(getName()); + if (hasContents()) { + out.name(CONTENTS__PROP); + getContents().writeTo(out); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case CONTENTS__PROP: setContents(test.embedded.data.Base.readBase(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(NAME__ID); + out.value(getName()); + if (hasContents()) { + out.name(CONTENTS__ID); + getContents().writeTo(out); + } + } + + /** Helper for creating an object of type {@link test.embedded.data.EmbeddingSingleContainer} from a polymorphic composition. */ + public static test.embedded.data.EmbeddingSingleContainer readEmbeddingSingleContainer_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.embedded.data.impl.EmbeddingSingleContainer_Impl result = new EmbeddingSingleContainer_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case NAME__ID: setName(in.nextString()); break; + case CONTENTS__ID: setContents(test.embedded.data.Base.readBase(in)); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.embedded.data.EmbeddingSingleContainer} type. */ + public static final String EMBEDDING_SINGLE_CONTAINER__XML_ELEMENT = "embedding-single-container"; + + /** XML attribute or element name of a {@link #getName} property. */ + private static final String NAME__XML_ATTR = "name"; + + /** XML attribute or element name of a {@link #getContents} property. */ + private static final String CONTENTS__XML_ATTR = "contents"; + + @Override + public String getXmlTagName() { + return EMBEDDING_SINGLE_CONTAINER__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasContents()) { + out.writeStartElement(CONTENTS__XML_ATTR); + getContents().writeTo(out); + out.writeEndElement(); + } + } + + /** Creates a new {@link test.embedded.data.EmbeddingSingleContainer} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static EmbeddingSingleContainer_Impl readEmbeddingSingleContainer_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + EmbeddingSingleContainer_Impl result = new EmbeddingSingleContainer_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NAME__XML_ATTR: { + setName(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NAME__XML_ATTR: { + setName(in.getElementText()); + break; + } + case test.embedded.data.impl.A_Impl.A__XML_ELEMENT: { + setContents(test.embedded.data.impl.A_Impl.readA_XmlContent(in)); + break; + } + case test.embedded.data.impl.B_Impl.B__XML_ELEMENT: { + setContents(test.embedded.data.impl.B_Impl.readB_XmlContent(in)); + break; + } + case CONTENTS__XML_ATTR: { + in.nextTag(); + setContents(test.embedded.data.impl.Base_Impl.readBase_XmlContent(in)); + internalSkipUntilMatchingEndElement(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java new file mode 100644 index 00000000..5653c518 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java @@ -0,0 +1,289 @@ +package test.embedded.data.impl; + +/** + * Implementation of {@link test.embedded.data.SingleContainer}. + */ +public class SingleContainer_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.embedded.data.SingleContainer { + + private String _name = ""; + + private test.embedded.data.Base _contents = null; + + /** + * Creates a {@link SingleContainer_Impl} instance. + * + * @see test.embedded.data.SingleContainer#create() + */ + public SingleContainer_Impl() { + super(); + } + + @Override + public final String getName() { + return _name; + } + + @Override + public test.embedded.data.SingleContainer setName(String value) { + internalSetName(value); + return this; + } + + /** Internal setter for {@link #getName()} without chain call utility. */ + protected final void internalSetName(String value) { + _listener.beforeSet(this, NAME__PROP, value); + _name = value; + } + + @Override + public final test.embedded.data.Base getContents() { + return _contents; + } + + @Override + public test.embedded.data.SingleContainer setContents(test.embedded.data.Base value) { + internalSetContents(value); + return this; + } + + /** Internal setter for {@link #getContents()} without chain call utility. */ + protected final void internalSetContents(test.embedded.data.Base value) { + _listener.beforeSet(this, CONTENTS__PROP, value); + _contents = value; + } + + @Override + public final boolean hasContents() { + return _contents != null; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.embedded.data.SingleContainer registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.embedded.data.SingleContainer unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return SINGLE_CONTAINER__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + NAME__PROP, + CONTENTS__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NAME__PROP: return getName(); + case CONTENTS__PROP: return getContents(); + default: return test.embedded.data.SingleContainer.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NAME__PROP: internalSetName((String) value); break; + case CONTENTS__PROP: internalSetContents((test.embedded.data.Base) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NAME__PROP); + out.value(getName()); + if (hasContents()) { + out.name(CONTENTS__PROP); + getContents().writeTo(out); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case CONTENTS__PROP: setContents(test.embedded.data.Base.readBase(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(NAME__ID); + out.value(getName()); + if (hasContents()) { + out.name(CONTENTS__ID); + getContents().writeTo(out); + } + } + + /** Helper for creating an object of type {@link test.embedded.data.SingleContainer} from a polymorphic composition. */ + public static test.embedded.data.SingleContainer readSingleContainer_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.embedded.data.impl.SingleContainer_Impl result = new SingleContainer_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case NAME__ID: setName(in.nextString()); break; + case CONTENTS__ID: setContents(test.embedded.data.Base.readBase(in)); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.embedded.data.SingleContainer} type. */ + public static final String SINGLE_CONTAINER__XML_ELEMENT = "single-container"; + + /** XML attribute or element name of a {@link #getName} property. */ + private static final String NAME__XML_ATTR = "name"; + + /** XML attribute or element name of a {@link #getContents} property. */ + private static final String CONTENTS__XML_ATTR = "contents"; + + @Override + public String getXmlTagName() { + return SINGLE_CONTAINER__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasContents()) { + out.writeStartElement(CONTENTS__XML_ATTR); + getContents().writeTo(out); + out.writeEndElement(); + } + } + + /** Creates a new {@link test.embedded.data.SingleContainer} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static SingleContainer_Impl readSingleContainer_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + SingleContainer_Impl result = new SingleContainer_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NAME__XML_ATTR: { + setName(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NAME__XML_ATTR: { + setName(in.getElementText()); + break; + } + case CONTENTS__XML_ATTR: { + in.nextTag(); + setContents(test.embedded.data.impl.Base_Impl.readBase_XmlContent(in)); + internalSkipUntilMatchingEndElement(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} From 7bf424b0a2bb61e908408584c2e1afa69aa348fa Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 14 Apr 2024 19:17:10 +0200 Subject: [PATCH 062/207] Fixed type in JavaDoc. --- .../src/test/java/test/hierarchy/data/Optional.java | 2 +- .../src/test/java/test/hierarchy/data/hierarchy.proto | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java index 7aabdee1..67ab3cbe 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/Optional.java @@ -41,7 +41,7 @@ static test.hierarchy.data.Optional create() { test.hierarchy.data.Optional setHidden(boolean value); /** - * A {@link Shape} that can be dynamically hidden.. + * A {@link Shape} that can be dynamically hidden. */ test.hierarchy.data.Shape getShape(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/hierarchy.proto b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/hierarchy.proto index ff762422..b1165382 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/hierarchy.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/hierarchy.proto @@ -112,7 +112,7 @@ message Optional extends Shape { boolean hidden; /** - * A {@link Shape} that can be dynamically hidden.. + * A {@link Shape} that can be dynamically hidden. */ @Embedded Shape shape; From 53cd71ab197ca1c4d07f6c8fb0489d865392ea43 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 14 Apr 2024 19:33:22 +0200 Subject: [PATCH 063/207] Removed duplicate _options field. --- .../de/haumacher/msgbuf/generator/MessageGenerator.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 1a4731cb..0ccf3269 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -50,7 +50,6 @@ public class MessageGenerator extends AbstractMessageGenerator implements Defini private boolean _visitEx; private boolean _typeKind; - private Map _options; private boolean _listener; private boolean _interface; @@ -61,7 +60,6 @@ public class MessageGenerator extends AbstractMessageGenerator implements Defini public MessageGenerator(NameTable table, Map options, boolean isInterface, String packageSuffix, MessageDef def, GeneratorPlugin plugin) { super(options, packageSuffix); _table = table; - _options = options; _interface = isInterface; _def = def; _plugin = plugin; @@ -205,7 +203,7 @@ private void addImplements(List generalizations) { } private void addMixins(List generalizations) { - _plugin.addInterfaces(_options, _def, generalizations); + _plugin.addInterfaces(getOptions(), _def, generalizations); Option operations = _def.getOptions().get("Operations"); if (operations != null) { @@ -390,7 +388,7 @@ public Void visit(EnumDef def, Void arg) { @Override public Void visit(MessageDef def, Void arg) { - include(new MessageGenerator(_table, _options, _interface, _packageSuffix, def, _plugin)); + include(new MessageGenerator(_table, getOptions(), _interface, _packageSuffix, def, _plugin)); return null; } From 315c211ecf5a285403a6dca3ca2dcd0c55a3b689 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 14 Apr 2024 19:53:47 +0200 Subject: [PATCH 064/207] Added documentation for protocol options. --- README.md | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/README.md b/README.md index 8a408033..0edd9629 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,129 @@ message Group extends Shape { Passing these definitions to the `msgbuf` compiler gives you a class hierarchy with classes `Shape`, `Circle`, `Rectangle`, and `Group`. You can inspect the generation result in the test package [test.hierarchy](https://github.com/msgbuf/msgbuf/tree/main/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data) of the compiler. The source of the example data class definitions can be seen in the [hierarchy.proto](https://github.com/msgbuf/msgbuf/tree/main/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/hierarchy.proto) file. +## Global protocol options + +### `@NoJson` +Disables generation of read and write methods for the JSON format. + +### `@NoBinary` +Disables generation of read and write methods for binary format. + +### `@NoXml` +Disables generation of read and write methods for XML format. + +### `@NoXmlNames` +Disables generation of constants for the XML format. + +### `@NoInterfaces` +Disables generation interfaces for data classes. Normally, data classes are represented by a Java interface. This +enables multiple inheritance for data classes. To reduce the amout of generated code, this can be disabled for simple +cases, where no multiple inheritance is required. + +### `@NoListener` +Disables generation of listener interfaces and corresponding registration methods. Add this options, if observing +data classes for changes is not required. + +### `@NoReflection` +Disables generation of reflective access methods that allow access to properties through their property names. + +### `@NoVisitor` +Disables generation of visitor interfaces and visit methods. + +### `@NoVisitorExceptions` +Produces visitor interfaces that cannot throw declared exceptions. + +### `@NoTypeKind` +Suppresses the type kind enumeration for a data class hierarchy. + +### `@SharedGraph` +Allows to handle multiple synchronized instances of a data class graph. Each graph can be observed for changes. Changes +generate synchronization messages to keep other instances of the same shared graph up to date. With this option, +a shared graph can be instantiated on a server, transfered to a client while keeping the state in sync when changes +occur on each side. + +## Message options + +### Mix-in interfaces (`@Operations(...)`) + +The data classes can extends mix-in interfaces with operations. + +``` +/** The data class */ +@Operations("test.operations.DataOperations") +message Data { + int x; +} + +/** The mix-in interface with operations on data. */ +public interface DataOperations { + /** Access to the data. */ + Data self(); + + /** Operation added to data class. */ + default void inc() { + self().setX(self().getX() + 1); + } +} + +/** Testing the mix-in operation. */ +public void testOperations() { + Data data = Data.create(); + data.inc(); + data.inc(); + assertEquals(2, data.getX()); +} +``` + +## Property options + +### `@Nullable` +A property of a primitive type that does not allow `null` values (e.g. `int` and `string`) can be explicitly marked to +allow `null` values. + +### `@Name("myProp")` +Sets a custom property name. This name is used in JSON serialization. + +### `@XmlName("myProp")` +Sets a custom tag name for XML serialization. + +### `@Reverse("otherProp")` +Marks a reference to be the reverse end of the reference with the given name in the target type. + +### `@Container` +Marks a reference point to the container of the current object. + +### `@type_id(4711)` +Sets a custom ID for binary serialization. + + +### XML reference embedding (`@Embedded`) +When serializing data classes to XML, all data fields and references are normally represented by XML tags with the same +name as the field or reference. By adding the `@Embedded` annotation to a reference, the tag for the reference can be +omitted. The contents of the reference is placed directly within the tag for the containing element. Care must be taken +that the tag names for referenced elements do not clash with tag names of other attributes and references of the +container. + +In the following example, a container with contents A and B can be written `` instead of +wrapping the contents into an extra element as in ``. + +``` +message Container { + @Embedded + repeated Base contents; +} + +abstract message Base {} +message A extends Base {} +message B extends Base {} +``` + +However, even with the `@Embedded` annotation, the verbose serialization with the wrapping reference element is also +understood. + +## Plugin options +`@DartLib("../lib/protocol.dart")` + ## Installation in Eclipse There is an Eclipse plugin providing a project builder that automatically generates corresponding Java files whenever you create or modify a `*.proto` definition file. To install and enable the plugin with the following steps: From d4be6a05aab0d91775a90b2969287ad8b42f305a Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 14 Apr 2024 20:05:58 +0200 Subject: [PATCH 065/207] [maven-release-plugin] prepare release msgbuf-api-1.1.5 --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index de72fdcb..2b87e3e8 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.5-SNAPSHOT + 1.1.5 msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.5-SNAPSHOT + 1.1.5 diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 7d9da016..bcf5f1e9 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.5-SNAPSHOT + 1.1.5 msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 79ff10ab..720d5783 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.5-SNAPSHOT + 1.1.5 msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.5-SNAPSHOT + 1.1.5 diff --git a/pom.xml b/pom.xml index eb3bdb46..e530e66a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.5-SNAPSHOT + 1.1.5 pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - HEAD + msgbuf-api-1.1.5 From cd12036585504c2538734f091e0e6fd1219aa254 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 14 Apr 2024 20:06:00 +0200 Subject: [PATCH 066/207] [maven-release-plugin] prepare for next development iteration --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 2b87e3e8..e7f9eef8 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.5 + 1.1.6-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.5 + 1.1.6-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index bcf5f1e9..afb398d1 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.5 + 1.1.6-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 720d5783..ab79680c 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.5 + 1.1.6-SNAPSHOT msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.5 + 1.1.6-SNAPSHOT diff --git a/pom.xml b/pom.xml index e530e66a..51801605 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.5 + 1.1.6-SNAPSHOT pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - msgbuf-api-1.1.5 + HEAD From 3746e36c5ce58da77f253f89f8afcfce676a4b32 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 14 Apr 2024 20:09:45 +0200 Subject: [PATCH 067/207] Updated version in README. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0edd9629..3f985019 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ In contrast to `protobuf`, `msgbuf` supports: de.haumacher.msgbuf msgbuf-api - 1.1.4 + 1.1.5 ``` @@ -32,7 +32,7 @@ To the `build/plugins` section add: de.haumacher.msgbuf msgbuf-generator-maven-plugin - 1.1.4 + 1.1.5 From aabd922b5968bb3233c561bf109ec11c31bb6f91 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 14 Apr 2024 20:11:23 +0200 Subject: [PATCH 068/207] Replaced tab with spaces in README. --- README.md | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 3f985019..fb1553fd 100644 --- a/README.md +++ b/README.md @@ -30,18 +30,18 @@ To the `build/plugins` section add: ``` - de.haumacher.msgbuf - msgbuf-generator-maven-plugin - 1.1.5 - - - - generate-protocols - - generate - - - + de.haumacher.msgbuf + msgbuf-generator-maven-plugin + 1.1.5 + + + + generate-protocols + + generate + + + ``` @@ -144,21 +144,21 @@ message Data { /** The mix-in interface with operations on data. */ public interface DataOperations { - /** Access to the data. */ - Data self(); - - /** Operation added to data class. */ - default void inc() { - self().setX(self().getX() + 1); - } + /** Access to the data. */ + Data self(); + + /** Operation added to data class. */ + default void inc() { + self().setX(self().getX() + 1); + } } /** Testing the mix-in operation. */ public void testOperations() { - Data data = Data.create(); - data.inc(); - data.inc(); - assertEquals(2, data.getX()); + Data data = Data.create(); + data.inc(); + data.inc(); + assertEquals(2, data.getX()); } ``` @@ -196,8 +196,8 @@ wrapping the contents into an extra element as in ` ``` message Container { - @Embedded - repeated Base contents; + @Embedded + repeated Base contents; } abstract message Base {} From 17b194cb3f31c77ceec3f475349d6abb10de771f Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 14 Apr 2024 20:12:42 +0200 Subject: [PATCH 069/207] Added format annotations. --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fb1553fd..f5434f13 100644 --- a/README.md +++ b/README.md @@ -135,13 +135,14 @@ occur on each side. The data classes can extends mix-in interfaces with operations. -``` +```protobuf /** The data class */ @Operations("test.operations.DataOperations") message Data { int x; } - +``` +```java /** The mix-in interface with operations on data. */ public interface DataOperations { /** Access to the data. */ @@ -194,7 +195,7 @@ container. In the following example, a container with contents A and B can be written `` instead of wrapping the contents into an extra element as in ``. -``` +```protobuf message Container { @Embedded repeated Base contents; From b381f8c87e49c5fd1f9bcd03fce87895439996b9 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sun, 14 Apr 2024 20:14:05 +0200 Subject: [PATCH 070/207] Added format annotations to Maven snippets. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f5434f13..5c7e6659 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ In contrast to `protobuf`, `msgbuf` supports: ### Add the MsgBuf runtime libary dependency to your project -``` +```xml de.haumacher.msgbuf msgbuf-api @@ -28,7 +28,7 @@ In contrast to `protobuf`, `msgbuf` supports: To the `build/plugins` section add: -``` +```xml de.haumacher.msgbuf msgbuf-generator-maven-plugin From b4fead68a59eab8d0e9b5d4b8eb22882ba1cf8fd Mon Sep 17 00:00:00 2001 From: Daniel Busche Date: Fri, 4 Apr 2025 11:32:15 +0200 Subject: [PATCH 071/207] Use scope method to get id of node. When the scope has overridden the id(...) method, accessing the ID will return a wrong value. --- .../main/java/de/haumacher/msgbuf/graph/DefaultScope.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java index ce91ec0f..ef77b7ca 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java @@ -87,7 +87,7 @@ public void beforeSet(Observable obj, String property, Object value) { return; } AbstractSharedGraphNode node = (AbstractSharedGraphNode) obj; - changes(node).put(property, SetProperty.create().setNode(node).setId(node.id()).setProperty(property)); + changes(node).put(property, SetProperty.create().setNode(node).setId(id(node)).setProperty(property)); } @Override @@ -98,7 +98,7 @@ public void beforeAdd(Observable obj, String property, int index, Object element AbstractSharedGraphNode node = (AbstractSharedGraphNode) obj; Map changes = changes(node); InsertElement insert = InsertElement.create(); - insert.setElement(element).setIndex(index).setNode(node).setId(node.id()).setProperty(property); + insert.setElement(element).setIndex(index).setNode(node).setId(id(node)).setProperty(property); putUpdate(changes, property, insert); } @@ -111,7 +111,7 @@ public void afterRemove(Observable obj, String property, int index, Object eleme AbstractSharedGraphNode node = (AbstractSharedGraphNode) obj; Map changes = changes(node); RemoveElement remove = RemoveElement.create(); - remove.setIndex(index).setNode(node).setId(node.id()).setProperty(property); + remove.setIndex(index).setNode(node).setId(id(node)).setProperty(property); putUpdate(changes, property, remove); } From 93fa66e101576a1e3e6da6416b212086d5c3d53e Mon Sep 17 00:00:00 2001 From: Daniel Busche Date: Fri, 4 Apr 2025 11:33:04 +0200 Subject: [PATCH 072/207] Changed patch format. The patch is now a list of commands where a command is a list with the command configuration at position 0 followed by optional additional arguments. --- .../haumacher/msgbuf/graph/DefaultScope.java | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java index ef77b7ca..2a999a9d 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java @@ -4,7 +4,6 @@ package de.haumacher.msgbuf.graph; import java.io.IOException; -import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -156,42 +155,52 @@ private static Command append(final ListUpdate clash, ListUpdate update) { *

* The recored changes are reset when this method completes. *

+ * + *

+ * The patch is a list containing an entry for each command. Each entry is a + * list with the command configuration at position 0 followed by optional + * additional arguments for the command. + *

+ * + * @see #applyChanges(JsonReader) */ public void createPatch(JsonWriter json) throws IOException { json.beginArray(); - json.beginArray(); - foreachCommand(command -> command.writeTo(json)); - json.endArray(); + foreachCommand(command -> { - json.beginArray(); - foreachCommand(command -> command.visit(_extractor, json)); - json.endArray(); + json.beginArray(); + command.writeTo(json); + command.visit(_extractor, json); + json.endArray(); + + }); json.endArray(); _changes.clear(); } /** - * Applies changes read from the given {@link JsonReader}. + * Applies changes read from the given {@link JsonReader}. + * + *

+ * It is expected that the patch has the format as in + * {@link #createPatch(JsonWriter)}. + *

+ * + * @see #createPatch(JsonWriter) */ public void applyChanges(JsonReader json) throws IOException { boolean before = _applying; _applying = true; try { - List commands = new ArrayList<>(); - json.beginArray(); json.beginArray(); while (json.hasNext()) { - commands.add(Command.readCommand(json)); - } - json.endArray(); - - json.beginArray(); - for (Command command : commands) { + json.beginArray(); + Command command = Command.readCommand(json); command.visit(_applicator, json); + json.endArray(); } json.endArray(); - json.endArray(); } finally { _applying = before; } From 25807c6a75d6b84382aa3cc1d77f72651aaa68a0 Mon Sep 17 00:00:00 2001 From: Daniel Busche Date: Fri, 4 Apr 2025 11:34:03 +0200 Subject: [PATCH 073/207] Added possibility to check whether a scope has changes. --- .../de/haumacher/msgbuf/graph/DefaultScope.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java index 2a999a9d..baee84c8 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java @@ -148,6 +148,20 @@ private static Command append(final ListUpdate clash, ListUpdate update) { current.setNext(update); return clash; } + + /** + * Checks whether there are changes to create a patch. + */ + public boolean hasChanges() { + return !_changes.isEmpty(); + } + + /** + * Removes all recorded changes. + */ + public void dropChanges() { + _changes.clear(); + } /** * Exports recorded changes to the given {@link JsonWriter}. @@ -163,6 +177,7 @@ private static Command append(final ListUpdate clash, ListUpdate update) { *

* * @see #applyChanges(JsonReader) + * @see #hasChanges() */ public void createPatch(JsonWriter json) throws IOException { json.beginArray(); @@ -176,7 +191,7 @@ public void createPatch(JsonWriter json) throws IOException { }); json.endArray(); - _changes.clear(); + dropChanges(); } /** From d5f2b6db81722d1ee037f0b07b997e2dd5380802 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 4 Apr 2025 12:52:51 +0200 Subject: [PATCH 074/207] Updated distribution management. --- pom.xml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 51801605..7059f0af 100644 --- a/pom.xml +++ b/pom.xml @@ -43,10 +43,16 @@ - + ossrh - https://s01.oss.sonatype.org/content/repositories/snapshots - + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + true + + + false + + From 33d453b21efeb55dd3284fb1b7980a55ff130e11 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 4 Apr 2025 13:20:20 +0200 Subject: [PATCH 075/207] Migrated to publishing through the Central Portal. --- pom.xml | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index 7059f0af..bd78e157 100644 --- a/pom.xml +++ b/pom.xml @@ -42,19 +42,6 @@ HEAD - - - ossrh - https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ - - true - - - false - - - - 11 11 @@ -132,14 +119,14 @@ - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 + org.sonatype.central + central-publishing-maven-plugin + 0.6.0 true - ossrh - https://s01.oss.sonatype.org/ - false + central + true + published From c1015b4b6a7c01abbf8685582df6eebf27cdd6d4 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 4 Apr 2025 13:34:44 +0200 Subject: [PATCH 076/207] [maven-release-plugin] prepare release msgbuf-api-1.1.6 --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index e7f9eef8..1c37b078 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.6-SNAPSHOT + 1.1.6 msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.6-SNAPSHOT + 1.1.6 diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index afb398d1..fbe63227 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.6-SNAPSHOT + 1.1.6 msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index ab79680c..26d74a07 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.6-SNAPSHOT + 1.1.6 msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.6-SNAPSHOT + 1.1.6 diff --git a/pom.xml b/pom.xml index bd78e157..d6741f13 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.6-SNAPSHOT + 1.1.6 pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - HEAD + msgbuf-api-1.1.6 From 64745d61f664c911441e760bde22f99137518a1a Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 4 Apr 2025 13:34:45 +0200 Subject: [PATCH 077/207] [maven-release-plugin] prepare for next development iteration --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 1c37b078..2f3d8aab 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.6 + 1.1.7-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.6 + 1.1.7-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index fbe63227..4e2413af 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.6 + 1.1.7-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 26d74a07..1b017bab 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.6 + 1.1.7-SNAPSHOT msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.6 + 1.1.7-SNAPSHOT diff --git a/pom.xml b/pom.xml index d6741f13..569d9bf5 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.6 + 1.1.7-SNAPSHOT pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - msgbuf-api-1.1.6 + HEAD From 0e652bce7cf54b59d4a4be4ffb2940c96505beba Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 4 Apr 2025 14:39:37 +0200 Subject: [PATCH 078/207] Update HOWTO-RELEASE.md --- HOWTO-RELEASE.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/HOWTO-RELEASE.md b/HOWTO-RELEASE.md index e3ee79b3..95cdcbcc 100644 --- a/HOWTO-RELEASE.md +++ b/HOWTO-RELEASE.md @@ -1,20 +1,13 @@ # How to release to Maven Central -## Set stable version number +## Set stable version number and tag version ``` mvn release:clean release:prepare ``` -## Create staging repository - -``` -mvn release:perform -``` - ## Release to Maven Central ``` -cd target/checkout/ -mvn nexus-staging:release +mvn release:perform ``` From 16b4ee17a91ef51c306fd920be3f821c04faf0f9 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 4 Apr 2025 14:41:13 +0200 Subject: [PATCH 079/207] Update version in README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5c7e6659..6215e8b2 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ In contrast to `protobuf`, `msgbuf` supports: de.haumacher.msgbuf msgbuf-api - 1.1.5 + 1.1.6 ``` @@ -32,7 +32,7 @@ To the `build/plugins` section add: de.haumacher.msgbuf msgbuf-generator-maven-plugin - 1.1.5 + 1.1.6 From ceeb7aeb159e46097eb76ff52fb4c61c98dbfc64 Mon Sep 17 00:00:00 2001 From: Daniel Busche Date: Fri, 4 Apr 2025 16:57:24 +0200 Subject: [PATCH 080/207] Use setter when reading repeated field. The method "readField" is also used to update the value on a property change. When the field is repeated, adding the elements is actually an "add all" instaed of "set". --- .../msgbuf/generator/MessageGenerator.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 0ccf3269..a3945bd3 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -6,7 +6,7 @@ import static de.haumacher.msgbuf.generator.CodeConvention.*; import static de.haumacher.msgbuf.generator.DefaultValueGenerator.*; import static de.haumacher.msgbuf.generator.TypeGenerator.*; -import static de.haumacher.msgbuf.generator.util.CodeUtil.*; +import static de.haumacher.msgbuf.generator.util.CodeUtil.stringLiteral; import java.util.ArrayList; import java.util.List; @@ -1395,13 +1395,15 @@ private void jsonReadField(Field field) { if (field.isRepeated()) { line("case " + constant(field) + ": {"); { + line(mkType(field)+ " newValue = new java.util.ArrayList<>();"); line("in.beginArray();"); line("while (in.hasNext()) {"); { - line(adderName(field) + "(" + jsonReadEntry(type) + ");"); + line("newValue.add(" + jsonReadEntry(type) + ");"); } line("}"); line("in.endArray();"); + line(setterName(field) + "(newValue);"); } line("}"); line("break;"); @@ -1412,14 +1414,17 @@ private void jsonReadField(Field field) { Type keyType = mapType.getKeyType(); Type valueType = mapType.getValueType(); if (keyType instanceof PrimitiveType && ((PrimitiveType) keyType).getKind() == Kind.STRING) { + line(mkType(field)+ " newValue = new java.util.LinkedHashMap<>();"); line("in.beginObject();"); line("while (in.hasNext()) {"); { - line(adderName(field) + "(in.nextName(), " + jsonReadEntry(valueType) + ");"); + line("newValue.put(in.nextName(), " + jsonReadEntry(valueType) + ");"); } line("}"); line("in.endObject();"); + line(setterName(field) + "(newValue);"); } else { + line(mkType(field)+ " newValue = new java.util.LinkedHashMap<>();"); line("in.beginArray();"); line("while (in.hasNext()) {"); { @@ -1435,11 +1440,12 @@ private void jsonReadField(Field field) { line("}"); } line("}"); - line(adderName(field) + "(key, value);"); + line("newValue.put(key, value);"); line("in.endObject();"); } line("}"); line("in.endArray();"); + line(setterName(field) + "(newValue);"); } } line("break;"); From a4a06fed44b347fdb648ac7c25f125ce51e757e4 Mon Sep 17 00:00:00 2001 From: Daniel Busche Date: Fri, 4 Apr 2025 16:57:39 +0200 Subject: [PATCH 081/207] Regenerated test classes. --- .../test/container/model/impl/MyContainer_Impl.java | 8 ++++++-- .../java/test/embedded/data/impl/Container_Impl.java | 4 +++- .../embedded/data/impl/EmbeddingContainer_Impl.java | 4 +++- .../test/java/test/graph/data/impl/Group_Impl.java | 4 +++- .../java/test/hierarchy/data/impl/Group_Impl.java | 4 +++- .../java/test/maptype/data/impl/MyMessage_Impl.java | 8 ++++++-- .../test/nested/data/impl/SearchResponse_Impl.java | 8 ++++++-- .../src/test/java/test/nointerfaces/Group.java | 4 +++- .../test/java/test/nolistener/impl/Group_Impl.java | 4 +++- .../src/test/java/test/noreflection/Group.java | 4 +++- .../test/java/test/notypekind/impl/Group_Impl.java | 4 +++- .../src/test/java/test/novisit/impl/Group_Impl.java | 4 +++- .../java/test/novisitexceptions/impl/Group_Impl.java | 4 +++- .../test/nullable/data/impl/NullableValues_Impl.java | 12 +++++++++--- .../test/java/test/references/data/impl/A_Impl.java | 12 +++++++++--- 15 files changed, 66 insertions(+), 22 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java index b871e89e..5ca4e47e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java @@ -323,19 +323,23 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t case CONTENT_1__PROP: setContent1(test.container.model.MyContent.readMyContent(in)); break; case CONTENT_2__PROP: setContent2(test.container.model.MyContent.readMyContent(in)); break; case CONTENT_LIST__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addContentList(test.container.model.MyContent.readMyContent(in)); + newValue.add(test.container.model.MyContent.readMyContent(in)); } in.endArray(); + setContentList(newValue); } break; case CONTENT_MAP__PROP: { + java.util.Map newValue = new java.util.LinkedHashMap<>(); in.beginObject(); while (in.hasNext()) { - putContentMap(in.nextName(), test.container.model.MyContent.readMyContent(in)); + newValue.put(in.nextName(), test.container.model.MyContent.readMyContent(in)); } in.endObject(); + setContentMap(newValue); break; } default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java index 818b473c..4f27c6be 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java @@ -156,11 +156,13 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t switch (field) { case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; case CONTENTS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addContent(test.embedded.data.Base.readBase(in)); + newValue.add(test.embedded.data.Base.readBase(in)); } in.endArray(); + setContents(newValue); } break; default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java index a8584a77..e17aeff0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java @@ -156,11 +156,13 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t switch (field) { case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; case CONTENTS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addContent(test.embedded.data.Base.readBase(in)); + newValue.add(test.embedded.data.Base.readBase(in)); } in.endArray(); + setContents(newValue); } break; default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java index 632f0bce..e26a4902 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java @@ -137,11 +137,13 @@ public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher. public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { case SHAPES__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addShape(test.graph.data.Shape.readShape(scope, in)); + newValue.add(test.graph.data.Shape.readShape(scope, in)); } in.endArray(); + setShapes(newValue); } break; default: super.readField(scope, in, field); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java index 2c465b89..2ca07d4a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java @@ -128,11 +128,13 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { case SHAPES__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addShape(test.hierarchy.data.Shape.readShape(in)); + newValue.add(test.hierarchy.data.Shape.readShape(in)); } in.endArray(); + setShapes(newValue); } break; default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java index 51ae6ca8..0c7b1db0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java @@ -198,14 +198,17 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { case PROJECTS__PROP: { + java.util.Map newValue = new java.util.LinkedHashMap<>(); in.beginObject(); while (in.hasNext()) { - putProject(in.nextName(), test.maptype.data.Project.readProject(in)); + newValue.put(in.nextName(), test.maptype.data.Project.readProject(in)); } in.endObject(); + setProjects(newValue); break; } case RATING__PROP: { + java.util.Map newValue = new java.util.LinkedHashMap<>(); in.beginArray(); while (in.hasNext()) { in.beginObject(); @@ -218,10 +221,11 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t default: in.skipValue(); break; } } - putRating(key, value); + newValue.put(key, value); in.endObject(); } in.endArray(); + setRating(newValue); break; } default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java index 3294bf2b..58ef8bfd 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java @@ -184,11 +184,13 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t case URL__PROP: setUrl(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; case TITLE__PROP: setTitle(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; case SNIPPETS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addSnippet(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); + newValue.add(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); } in.endArray(); + setSnippets(newValue); } break; default: super.readField(in, field); @@ -499,11 +501,13 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { case RESULTS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addResult(test.nested.data.SearchResponse.Result.readResult(in)); + newValue.add(test.nested.data.SearchResponse.Result.readResult(in)); } in.endArray(); + setResults(newValue); } break; default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java index 68645e41..4345e64f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java @@ -160,11 +160,13 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { case SHAPES__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addShape(test.nointerfaces.Shape.readShape(in)); + newValue.add(test.nointerfaces.Shape.readShape(in)); } in.endArray(); + setShapes(newValue); } break; default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java index 99744cb2..6f93b8d5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java @@ -112,11 +112,13 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { case SHAPES__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addShape(test.nolistener.Shape.readShape(in)); + newValue.add(test.nolistener.Shape.readShape(in)); } in.endArray(); + setShapes(newValue); } break; default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group.java index e4639ee3..6f52742c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/noreflection/Group.java @@ -114,11 +114,13 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { case SHAPES__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addShape(test.noreflection.Shape.readShape(in)); + newValue.add(test.noreflection.Shape.readShape(in)); } in.endArray(); + setShapes(newValue); } break; default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java index eee0c52e..c0d473b7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java @@ -117,11 +117,13 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { case SHAPES__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addShape(test.notypekind.Shape.readShape(in)); + newValue.add(test.notypekind.Shape.readShape(in)); } in.endArray(); + setShapes(newValue); } break; default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java index 6bc63e66..40a5c421 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java @@ -122,11 +122,13 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { case SHAPES__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addShape(test.novisit.Shape.readShape(in)); + newValue.add(test.novisit.Shape.readShape(in)); } in.endArray(); + setShapes(newValue); } break; default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java index 729e8e5f..27c2d9a0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java @@ -122,11 +122,13 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { case SHAPES__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addShape(test.novisitexceptions.Shape.readShape(in)); + newValue.add(test.novisitexceptions.Shape.readShape(in)); } in.endArray(); + setShapes(newValue); } break; default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java index 40895fdf..134d30c2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java @@ -374,27 +374,33 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t case BOOLEAN__PROP: setBoolean(in.nextBoolean()); break; case STRING__PROP: setString(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; case INT_LIST__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addIntList(in.nextInt()); + newValue.add(in.nextInt()); } in.endArray(); + setIntList(newValue); } break; case STRING_LIST__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addStringList(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); + newValue.add(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); } in.endArray(); + setStringList(newValue); } break; case STRING_INT_MAP__PROP: { + java.util.Map newValue = new java.util.LinkedHashMap<>(); in.beginObject(); while (in.hasNext()) { - putStringIntMap(in.nextName(), in.nextInt()); + newValue.put(in.nextName(), in.nextInt()); } in.endObject(); + setStringIntMap(newValue); break; } case OPTIONAL_DECISION__PROP: setOptionalDecision(test.nullable.data.Decision.readDecision(in)); break; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java index 8ca52b01..5c991081 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java @@ -480,29 +480,35 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; case CONTENTS__PROP: setContents(test.references.data.A.readA(in)); break; case CHILDREN__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addChildren(test.references.data.A.readA(in)); + newValue.add(test.references.data.A.readA(in)); } in.endArray(); + setChildren(newValue); } break; case BS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addBs(test.references.data.B.readB(in)); + newValue.add(test.references.data.B.readB(in)); } in.endArray(); + setBs(newValue); } break; case B__PROP: setB(test.references.data.B.readB(in)); break; case OTHER__PROP: setOther(test.references.data.A.readA(in)); break; case OTHERS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addOthers(test.references.data.A.readA(in)); + newValue.add(test.references.data.A.readA(in)); } in.endArray(); + setOthers(newValue); } break; default: super.readField(in, field); From 050d6665feace1e7391f2690e8e5842d956aaa22 Mon Sep 17 00:00:00 2001 From: Daniel Busche Date: Wed, 9 Apr 2025 16:42:27 +0200 Subject: [PATCH 082/207] Added missing override for "set". Ensure that listeners are informed when a value in the list is replaced via "set(int,Object)". --- .../main/java/de/haumacher/msgbuf/util/ReferenceList.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java index 4a9a30e6..92e4dfa4 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java @@ -108,4 +108,12 @@ private boolean doRemoveAll(Collection c, boolean removePresent) { protected abstract void afterRemove(int index, T element); + @Override + public T set(int index, T element) { + beforeAdd(index, element); + T oldValue = super.set(index, element); + afterRemove(index, oldValue); + return oldValue; + } + } From fdd4253c2e9d7fd5c8061307c4a8313ea13633b1 Mon Sep 17 00:00:00 2001 From: Daniel Busche Date: Wed, 9 Apr 2025 16:53:56 +0200 Subject: [PATCH 083/207] Set simulates add and remove for the listeners, therefore the index in remove must be incremented. --- .../src/main/java/de/haumacher/msgbuf/util/ReferenceList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java index 92e4dfa4..785db83b 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java @@ -112,7 +112,7 @@ private boolean doRemoveAll(Collection c, boolean removePresent) { public T set(int index, T element) { beforeAdd(index, element); T oldValue = super.set(index, element); - afterRemove(index, oldValue); + afterRemove(index + 1, oldValue); return oldValue; } From bb2386514a65b83842eebd041d209ad0563c8dc1 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 9 Apr 2025 17:02:28 +0200 Subject: [PATCH 084/207] [maven-release-plugin] prepare release msgbuf-api-1.1.7 --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 2f3d8aab..dac1a4a1 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.7-SNAPSHOT + 1.1.7 msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.7-SNAPSHOT + 1.1.7 diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 4e2413af..1bc1dbe6 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.7-SNAPSHOT + 1.1.7 msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 1b017bab..e7911621 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.7-SNAPSHOT + 1.1.7 msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.7-SNAPSHOT + 1.1.7 diff --git a/pom.xml b/pom.xml index 569d9bf5..2b803ef6 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.7-SNAPSHOT + 1.1.7 pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - HEAD + msgbuf-api-1.1.7 From 4e4ff38aed0ac358db08c3c11642613a8049d5c3 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 9 Apr 2025 17:02:34 +0200 Subject: [PATCH 085/207] [maven-release-plugin] prepare for next development iteration --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index dac1a4a1..edfc3a02 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.7 + 1.1.8-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.7 + 1.1.8-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 1bc1dbe6..0079e859 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.7 + 1.1.8-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index e7911621..f4a8cda3 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.7 + 1.1.8-SNAPSHOT msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.7 + 1.1.8-SNAPSHOT diff --git a/pom.xml b/pom.xml index 2b803ef6..9ee12537 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.7 + 1.1.8-SNAPSHOT pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - msgbuf-api-1.1.7 + HEAD From abe360e3bd4d9cef9c2968d458dee2cd83075b53 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 9 Apr 2025 17:13:05 +0200 Subject: [PATCH 086/207] Update version to 1.1.7. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6215e8b2..47402f7e 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ In contrast to `protobuf`, `msgbuf` supports: de.haumacher.msgbuf msgbuf-api - 1.1.6 + 1.1.7 ``` @@ -32,7 +32,7 @@ To the `build/plugins` section add: de.haumacher.msgbuf msgbuf-generator-maven-plugin - 1.1.6 + 1.1.7 From 3ae68f33f7ee934bcbb15bac85a68607fb77d63c Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 15 Apr 2025 15:32:24 +0200 Subject: [PATCH 087/207] Added missing documentation for @Ref. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 47402f7e..074f204c 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,9 @@ Marks a reference to be the reverse end of the reference with the given name in ### `@Container` Marks a reference point to the container of the current object. +### `@Ref` +Marks a reference as cross reference (non-composition). When setting values to fields marked as cross reference, container properties are not updated. + ### `@type_id(4711)` Sets a custom ID for binary serialization. From 956184267fb16516fa34abd0d23e6ae7db664f1a Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 15 Apr 2025 15:21:34 +0200 Subject: [PATCH 088/207] Allow to specify field default values. Replaced the original syntax for assigning the field ID with an initializer expression for the default value. An alternative syntax for assigning the field ID is not yet available. Only primitive types can have default values (booleans, strings, and numbers). The default value must match the type of the field. This constraint is not yet checked, but errors would occurr in the generated output if violated. --- de.haumacher.msgbuf.generator/pom.xml | 52 + .../generator/DefaultValueGenerator.java | 5 + .../msgbuf/generator/ast/DefinitionFile.java | 4 +- .../msgbuf/generator/ast/EnumDef.java | 4 +- .../haumacher/msgbuf/generator/ast/Field.java | 43 +- .../msgbuf/generator/ast/MessageDef.java | 8 +- .../haumacher/msgbuf/generator/ast/QName.java | 4 +- .../msgbuf/generator/ast/WithOptions.java | 4 +- .../msgbuf/generator/ast/proto.proto | 12 +- .../generator/parser/ParseException.java | 48 +- .../generator/parser/ProtobufParser.java | 771 +++++----- .../parser/ProtobufParserConstants.java | 24 +- .../parser/ProtobufParserTokenManager.java | 1240 +++++++++-------- .../generator/parser/SimpleCharStream.java | 21 +- .../msgbuf/generator/parser/Token.java | 6 +- .../generator/parser/TokenMgrError.java | 36 +- .../msgbuf/generator/parser/protobuf.jj | 12 +- .../test/java/test/comments/comments.proto | 6 +- .../test/defaultvalue/TestDefaultValue.java | 23 + .../test/java/test/defaultvalue/data/A.java | 94 ++ .../test/defaultvalue/data/defaultvalue.proto | 10 + .../test/defaultvalue/data/impl/A_Impl.java | 359 +++++ .../src/test/java/test/enumeration/enum.proto | 10 +- .../java/test/maptype/data/MyMessage.java | 4 +- .../src/test/java/test/maptype/maptype.proto | 4 +- .../src/test/java/test/nested/nested.proto | 8 +- .../src/test/java/test/types/types.proto | 6 +- 27 files changed, 1793 insertions(+), 1025 deletions(-) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/TestDefaultValue.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/A.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/defaultvalue.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index edfc3a02..0c0029f5 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -60,6 +60,23 @@ 3.8.1 + + org.codehaus.mojo + javacc-maven-plugin + 3.1.1 + + + + javacc + + + ${project.basedir}/src/main/java + ${project.basedir}/src/main/java + + + + + org.apache.maven.plugins maven-shade-plugin @@ -82,5 +99,40 @@ + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.codehaus.mojo + + + javacc-maven-plugin + + + [3.1.1,) + + + javacc + + + + + + + + + + + + \ No newline at end of file diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/DefaultValueGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/DefaultValueGenerator.java index d0ca7aa8..292f5347 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/DefaultValueGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/DefaultValueGenerator.java @@ -22,6 +22,11 @@ final class DefaultValueGenerator implements Type.Visitor { public static String mkDefaultValue(Field field) { + String defaultValue = field.getDefaultValue(); + if (defaultValue != null) { + return defaultValue; + } + boolean nullable = Util.isNullable(field); if (nullable) { return "null"; diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java index 52d74c99..fed07f6a 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java @@ -193,11 +193,13 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t switch (field) { case PACKAGE__PROP: setPackage(de.haumacher.msgbuf.generator.ast.QName.readQName(in)); break; case DEFINITIONS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addDefinition(de.haumacher.msgbuf.generator.ast.Definition.readDefinition(in)); + newValue.add(de.haumacher.msgbuf.generator.ast.Definition.readDefinition(in)); } in.endArray(); + setDefinitions(newValue); } break; default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/EnumDef.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/EnumDef.java index 00166bfa..3618246f 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/EnumDef.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/EnumDef.java @@ -174,11 +174,13 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { case CONSTANTS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addConstant(de.haumacher.msgbuf.generator.ast.Constant.readConstant(in)); + newValue.add(de.haumacher.msgbuf.generator.ast.Constant.readConstant(in)); } in.endArray(); + setConstants(newValue); } break; default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java index a25cdc59..62a967ef 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java @@ -24,12 +24,17 @@ public static de.haumacher.msgbuf.generator.ast.Field create() { /** @see #getType() */ public static final String TYPE__PROP = "type"; + /** @see #getDefaultValue() */ + public static final String DEFAULT_VALUE__PROP = "defaultValue"; + private boolean _transient = false; private boolean _repeated = false; private de.haumacher.msgbuf.generator.ast.Type _type = null; + private String _defaultValue = null; + /** * Creates a {@link Field} instance. * @@ -114,6 +119,34 @@ public final boolean hasType() { return _type != null; } + /** + * The initializer value to assign to the field. + */ + public final String getDefaultValue() { + return _defaultValue; + } + + /** + * @see #getDefaultValue() + */ + public de.haumacher.msgbuf.generator.ast.Field setDefaultValue(String value) { + internalSetDefaultValue(value); + return this; + } + + /** Internal setter for {@link #getDefaultValue()} without chain call utility. */ + protected final void internalSetDefaultValue(String value) { + _listener.beforeSet(this, DEFAULT_VALUE__PROP, value); + _defaultValue = value; + } + + /** + * Checks, whether {@link #getDefaultValue()} has a value. + */ + public final boolean hasDefaultValue() { + return _defaultValue != null; + } + @Override public de.haumacher.msgbuf.generator.ast.Field setName(String value) { internalSetName(value); @@ -159,7 +192,8 @@ public String jsonType() { java.util.Arrays.asList( TRANSIENT__PROP, REPEATED__PROP, - TYPE__PROP)); + TYPE__PROP, + DEFAULT_VALUE__PROP)); @Override public java.util.List properties() { @@ -172,6 +206,7 @@ public Object get(String field) { case TRANSIENT__PROP: return isTransient(); case REPEATED__PROP: return isRepeated(); case TYPE__PROP: return getType(); + case DEFAULT_VALUE__PROP: return getDefaultValue(); default: return super.get(field); } } @@ -182,6 +217,7 @@ public void set(String field, Object value) { case TRANSIENT__PROP: internalSetTransient((boolean) value); break; case REPEATED__PROP: internalSetRepeated((boolean) value); break; case TYPE__PROP: internalSetType((de.haumacher.msgbuf.generator.ast.Type) value); break; + case DEFAULT_VALUE__PROP: internalSetDefaultValue((String) value); break; default: super.set(field, value); break; } } @@ -204,6 +240,10 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. out.name(TYPE__PROP); getType().writeTo(out); } + if (hasDefaultValue()) { + out.name(DEFAULT_VALUE__PROP); + out.value(getDefaultValue()); + } } @Override @@ -212,6 +252,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t case TRANSIENT__PROP: setTransient(in.nextBoolean()); break; case REPEATED__PROP: setRepeated(in.nextBoolean()); break; case TYPE__PROP: setType(de.haumacher.msgbuf.generator.ast.Type.readType(in)); break; + case DEFAULT_VALUE__PROP: setDefaultValue(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; default: super.readField(in, field); } } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java index 1ab789a6..c471a5a4 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java @@ -444,19 +444,23 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t case ABSTRACT__PROP: setAbstract(in.nextBoolean()); break; case EXTENDS__PROP: setExtends(de.haumacher.msgbuf.generator.ast.QName.readQName(in)); break; case DEFINITIONS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addDefinition(de.haumacher.msgbuf.generator.ast.Definition.readDefinition(in)); + newValue.add(de.haumacher.msgbuf.generator.ast.Definition.readDefinition(in)); } in.endArray(); + setDefinitions(newValue); } break; case FIELDS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addField(de.haumacher.msgbuf.generator.ast.Field.readField(in)); + newValue.add(de.haumacher.msgbuf.generator.ast.Field.readField(in)); } in.endArray(); + setFields(newValue); } break; default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/QName.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/QName.java index 3ccf0221..1c2e5035 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/QName.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/QName.java @@ -158,11 +158,13 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { case NAMES__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); in.beginArray(); while (in.hasNext()) { - addName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); + newValue.add(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); } in.endArray(); + setNames(newValue); } break; default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/WithOptions.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/WithOptions.java index c1fc8f1a..3574327c 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/WithOptions.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/WithOptions.java @@ -198,11 +198,13 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { case OPTIONS__PROP: { + java.util.Map newValue = new java.util.LinkedHashMap<>(); in.beginObject(); while (in.hasNext()) { - putOption(in.nextName(), de.haumacher.msgbuf.generator.ast.Option.readOption(in)); + newValue.put(in.nextName(), de.haumacher.msgbuf.generator.ast.Option.readOption(in)); } in.endObject(); + setOptions(newValue); break; } default: super.readField(in, field); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto index be613fb3..b144a18c 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto @@ -29,9 +29,6 @@ abstract message Part extends DefinitionBase { /** The name of this member. */ string name; - /** The numeric identifier for this member.*/ - int index; - /** The {@link Definition} definint this {@link Part}. */ transient Definition owner; } @@ -42,7 +39,10 @@ abstract message Part extends DefinitionBase { * @see EnumDef#constants */ message Constant extends Part { - // No additional members. + + /** The numeric identifier for this constant.*/ + int index; + } /** @@ -136,6 +136,10 @@ message Field extends Part { /** The type of values that can be stored in this field. */ Type type; + /** The initializer value to assign to the field. */ + @Nullable + string defaultValue; + } /** diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ParseException.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ParseException.java index 390c2bcb..b2260516 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ParseException.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ParseException.java @@ -1,5 +1,5 @@ -/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */ -/* JavaCCOptions:KEEP_LINE_COL=null */ +/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 7.0 */ +/* JavaCCOptions:KEEP_LINE_COLUMN=true */ package de.haumacher.msgbuf.generator.parser; /** @@ -20,6 +20,11 @@ public class ParseException extends Exception { */ private static final long serialVersionUID = 1L; + /** + * The end of line string for this machine. + */ + protected static String EOL = System.getProperty("line.separator", "\n"); + /** * This constructor is used by the method "generateParseException" * in the generated parser. Calling this constructor generates @@ -60,7 +65,7 @@ public ParseException(String message) { /** * This is the last token that has been consumed successfully. If * this object has been created due to a parse error, the token - * followng this token will (therefore) be the first error token. + * following this token will (therefore) be the first error token. */ public Token currentToken; @@ -88,8 +93,8 @@ public ParseException(String message) { private static String initialise(Token currentToken, int[][] expectedTokenSequences, String[] tokenImage) { - String eol = System.getProperty("line.separator", "\n"); - StringBuffer expected = new StringBuffer(); + + StringBuilder expected = new StringBuilder(); int maxSize = 0; for (int i = 0; i < expectedTokenSequences.length; i++) { if (maxSize < expectedTokenSequences[i].length) { @@ -101,7 +106,7 @@ private static String initialise(Token currentToken, if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { expected.append("..."); } - expected.append(eol).append(" "); + expected.append(EOL).append(" "); } String retval = "Encountered \""; Token tok = currentToken.next; @@ -117,21 +122,26 @@ private static String initialise(Token currentToken, retval += " \""; tok = tok.next; } - retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; - retval += "." + eol; - if (expectedTokenSequences.length == 1) { - retval += "Was expecting:" + eol + " "; + if (currentToken.next != null) { + retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; + } + retval += "." + EOL; + + + if (expectedTokenSequences.length == 0) { + // Nothing to add here } else { - retval += "Was expecting one of:" + eol + " "; + if (expectedTokenSequences.length == 1) { + retval += "Was expecting:" + EOL + " "; + } else { + retval += "Was expecting one of:" + EOL + " "; + } + retval += expected.toString(); } - retval += expected.toString(); + return retval; } - /** - * The end of line string for this machine. - */ - protected String eol = System.getProperty("line.separator", "\n"); /** * Used to convert raw characters to their escaped version @@ -139,13 +149,11 @@ private static String initialise(Token currentToken, * string literal. */ static String add_escapes(String str) { - StringBuffer retval = new StringBuffer(); + StringBuilder retval = new StringBuilder(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { - case 0 : - continue; case '\b': retval.append("\\b"); continue; @@ -184,4 +192,4 @@ static String add_escapes(String str) { } } -/* JavaCC - OriginalChecksum=790c9056a53b6f69ac158c6aec634d2e (do not edit this line) */ +/* JavaCC - OriginalChecksum=b29aa32c2c570384b1b287ad3c4ecb93 (do not edit this line) */ diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParser.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParser.java index 4d5711c0..f7dd4de6 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParser.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParser.java @@ -1,46 +1,49 @@ +/* ProtobufParser.java */ /* Generated By:JavaCC: Do not edit this line. ProtobufParser.java */ package de.haumacher.msgbuf.generator.parser; -import de.haumacher.msgbuf.generator.ast.*; import de.haumacher.msgbuf.generator.common.Util; +import de.haumacher.msgbuf.generator.ast.*; /** * Parser for protobuf definition files.. */ public class ProtobufParser implements ProtobufParserConstants { - final public DefinitionFile file() throws ParseException { - DefinitionFile result = DefinitionFile.create(); + final public DefinitionFile file() throws ParseException {DefinitionFile result = DefinitionFile.create(); QName pkgName; Definition def; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SYNTAX: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case SYNTAX:{ jj_consume_token(SYNTAX); - jj_consume_token(33); + jj_consume_token(35); jj_consume_token(STRING); - jj_consume_token(34); + jj_consume_token(36); break; + } default: jj_la1[0] = jj_gen; ; } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case PACKAGE: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case PACKAGE:{ jj_consume_token(PACKAGE); pkgName = qName(); - jj_consume_token(34); - result.setPackage(pkgName); + jj_consume_token(36); +result.setPackage(pkgName); break; + } default: jj_la1[1] = jj_gen; ; } label_1: while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case OPTION: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case OPTION:{ ; break; + } default: jj_la1[2] = jj_gen; break label_1; @@ -49,114 +52,120 @@ final public DefinitionFile file() throws ParseException { } label_2: while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case MESSAGE: case ENUM: case ABSTRACT: - case 37: + case 39:{ ; break; + } default: jj_la1[3] = jj_gen; break label_2; } def = definition(); - result.addDefinition(def); +result.addDefinition(def); } - {if (true) return result;} +{if ("" != null) return result;} throw new Error("Missing return statement in function"); - } +} final public void optionStatement(WithOptions part) throws ParseException { jj_consume_token(OPTION); optionAssignment(part); - jj_consume_token(34); - } + jj_consume_token(36); +} - final public void optionAssignment(WithOptions part) throws ParseException { - Option option; + final public void optionAssignment(WithOptions part) throws ParseException {Option option; Token t; t = jj_consume_token(NAME); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 33: - jj_consume_token(33); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 35:{ + jj_consume_token(35); option = value(); - part.getOptions().put(t.image, option); +part.getOptions().put(t.image, option); break; + } default: jj_la1[4] = jj_gen; - part.getOptions().put(t.image, Flag.create().setValue(true)); +part.getOptions().put(t.image, Flag.create().setValue(true)); } - } +} - final public Option value() throws ParseException { - Option result; + final public Option value() throws ParseException {Option result; Token t; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STRING: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case STRING:{ t = jj_consume_token(STRING); - result = StringOption.create().setValue(Util.stringContent(t.image)); +result = StringOption.create().setValue(Util.stringContent(t.image)); break; - case NUMBER: + } + case NUMBER:{ t = jj_consume_token(NUMBER); - result = NumberOption.create().setValue(Double.parseDouble(t.image)); +result = NumberOption.create().setValue(Double.parseDouble(t.image)); break; - case TRUE: + } + case TRUE:{ jj_consume_token(TRUE); - result = Flag.create().setValue(true); +result = Flag.create().setValue(true); break; - case FALSE: + } + case FALSE:{ jj_consume_token(FALSE); - result = Flag.create().setValue(false); +result = Flag.create().setValue(false); break; + } default: jj_la1[5] = jj_gen; jj_consume_token(-1); throw new ParseException(); } - {if (true) return result;} +{if ("" != null) return result;} throw new Error("Missing return statement in function"); - } +} - final public Definition definition() throws ParseException { - String comment; + final public Definition definition() throws ParseException {String comment; Definition result; WithOptions options; - comment = Util.stripComment(token.next); +comment = Util.stripComment(token.next); options = javaAnnotations(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case MESSAGE: - case ABSTRACT: + case ABSTRACT:{ result = message(); break; - case ENUM: + } + case ENUM:{ result = enumeration(); break; + } default: jj_la1[6] = jj_gen; jj_consume_token(-1); throw new ParseException(); } - result.setComment(comment); +result.setComment(comment); if (options != null) result.setOptions(options.getOptions()); - {if (true) return result;} + {if ("" != null) return result;} throw new Error("Missing return statement in function"); - } +} - final public DefinitionBase memberDefinition() throws ParseException { - String comment; + final public DefinitionBase memberDefinition() throws ParseException {String comment; DefinitionBase result; WithOptions options; - comment = Util.stripComment(token.next); +comment = Util.stripComment(token.next); options = javaAnnotations(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case MESSAGE: - case ABSTRACT: + case ABSTRACT:{ result = message(); break; - case ENUM: + } + case ENUM:{ result = enumeration(); break; + } case MAP: case REPEATED: case TRANSIENT: @@ -167,36 +176,37 @@ final public DefinitionBase memberDefinition() throws ParseException { case BOOLEAN_TYPE: case TYPE: case XNAME: - case NAME: + case NAME:{ result = field(); break; + } default: jj_la1[7] = jj_gen; jj_consume_token(-1); throw new ParseException(); } - result.setComment(comment); +result.setComment(comment); if (options != null) result.setOptions(options.getOptions()); - {if (true) return result;} + {if ("" != null) return result;} throw new Error("Missing return statement in function"); - } +} - final public EnumDef enumeration() throws ParseException { - EnumDef result = EnumDef.create(); + final public EnumDef enumeration() throws ParseException {EnumDef result = EnumDef.create(); String name; Constant constant; Token d; d = jj_consume_token(ENUM); name = name(); - jj_consume_token(35); - result.setName(name); + jj_consume_token(37); +result.setName(name); result.setComment(Util.stripComment(d)); label_3: while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case OPTION: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case OPTION:{ ; break; + } default: jj_la1[8] = jj_gen; break label_3; @@ -205,99 +215,103 @@ final public EnumDef enumeration() throws ParseException { } label_4: while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case RESERVED: case TO: case MAX: case XNAME: case NAME: - case 37: + case 39:{ ; break; + } default: jj_la1[9] = jj_gen; break label_4; } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case TO: case MAX: case XNAME: case NAME: - case 37: + case 39:{ constant = constant(); - result.addConstant(constant); +result.addConstant(constant); break; - case RESERVED: + } + case RESERVED:{ reserved(); break; + } default: jj_la1[10] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } - jj_consume_token(36); - {if (true) return result;} + jj_consume_token(38); +{if ("" != null) return result;} throw new Error("Missing return statement in function"); - } +} - final public Constant constant() throws ParseException { - Constant result = Constant.create(); + final public Constant constant() throws ParseException {Constant result = Constant.create(); String name; Token index; - result.setComment(Util.stripComment(token.next)); +result.setComment(Util.stripComment(token.next)); javaAnnotationsFor(result); name = name(); - result.setName(name); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 33: - jj_consume_token(33); +result.setName(name); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 35:{ + jj_consume_token(35); index = jj_consume_token(NUMBER); - result.setIndex(Integer.parseInt(index.image)); +result.setIndex(Integer.parseInt(index.image)); break; + } default: jj_la1[11] = jj_gen; ; } partOptions(result); - jj_consume_token(34); - {if (true) return result;} + jj_consume_token(36); +{if ("" != null) return result;} throw new Error("Missing return statement in function"); - } +} - final public MessageDef message() throws ParseException { - MessageDef result = MessageDef.create(); + final public MessageDef message() throws ParseException {MessageDef result = MessageDef.create(); String name; QName generalization; WithOptions def; Field field; Token comment; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ABSTRACT: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case ABSTRACT:{ jj_consume_token(ABSTRACT); - result.setAbstract(true); +result.setAbstract(true); break; + } default: jj_la1[12] = jj_gen; ; } jj_consume_token(MESSAGE); name = name(); - result.setName(name); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case EXTENDS: +result.setName(name); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case EXTENDS:{ jj_consume_token(EXTENDS); generalization = qName(); - result.setExtends(generalization); +result.setExtends(generalization); break; + } default: jj_la1[13] = jj_gen; ; } - jj_consume_token(35); + jj_consume_token(37); label_5: while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case MESSAGE: case ENUM: case MAP: @@ -315,17 +329,19 @@ final public MessageDef message() throws ParseException { case TYPE: case XNAME: case NAME: - case 37: + case 39:{ ; break; + } default: jj_la1[14] = jj_gen; break label_5; } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case OPTION: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case OPTION:{ optionStatement(result); break; + } case MESSAGE: case ENUM: case MAP: @@ -340,215 +356,254 @@ final public MessageDef message() throws ParseException { case TYPE: case XNAME: case NAME: - case 37: + case 39:{ def = memberDefinition(); - if (def instanceof Field) { +if (def instanceof Field) { result.addField((Field) def); } else { result.addDefinition((Definition) def); } break; - case ONEOF: + } + case ONEOF:{ oneof(); break; - case RESERVED: + } + case RESERVED:{ reserved(); break; + } default: jj_la1[15] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } - jj_consume_token(36); - {if (true) return result;} + jj_consume_token(38); +{if ("" != null) return result;} throw new Error("Missing return statement in function"); - } +} - final public Field field() throws ParseException { - Field result = Field.create(); + final public Field field() throws ParseException {Field result = Field.create(); Type type; String name; - Token index; + Token def; Token comment; Option option; Token optionName; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case TRANSIENT: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case TRANSIENT:{ jj_consume_token(TRANSIENT); - result.setTransient(true); +result.setTransient(true); break; + } default: jj_la1[16] = jj_gen; ; } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case REPEATED: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case REPEATED:{ jj_consume_token(REPEATED); - result.setRepeated(true); +result.setRepeated(true); break; + } default: jj_la1[17] = jj_gen; ; } type = type(); - result.setType(type); +result.setType(type); name = name(); - result.setName(name); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 33: - jj_consume_token(33); - index = jj_consume_token(NUMBER); - result.setIndex(Integer.parseInt(index.image)); +result.setName(name); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 35:{ + jj_consume_token(35); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case NUMBER:{ + def = jj_consume_token(NUMBER); + break; + } + case TRUE:{ + def = jj_consume_token(TRUE); + break; + } + case FALSE:{ + def = jj_consume_token(FALSE); + break; + } + case STRING:{ + def = jj_consume_token(STRING); + break; + } + case NULL:{ + def = jj_consume_token(NULL); + break; + } + default: + jj_la1[18] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +result.setDefaultValue(def.image); break; + } default: - jj_la1[18] = jj_gen; + jj_la1[19] = jj_gen; ; } partOptions(result); - jj_consume_token(34); - {if (true) return result;} + jj_consume_token(36); +{if ("" != null) return result;} throw new Error("Missing return statement in function"); - } +} - final public WithOptions javaAnnotations() throws ParseException { - WithOptions result; + final public WithOptions javaAnnotations() throws ParseException {WithOptions result; result = javaAnnotationsFor(null); - {if (true) return result;} +{if ("" != null) return result;} throw new Error("Missing return statement in function"); - } +} - final public WithOptions javaAnnotationsFor(WithOptions result) throws ParseException { - Token optionName; + final public WithOptions javaAnnotationsFor(WithOptions result) throws ParseException {Token optionName; Option option; label_6: while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 37: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 39:{ ; break; + } default: - jj_la1[19] = jj_gen; + jj_la1[20] = jj_gen; break label_6; } - if (result == null) result = OptionContainer.create(); - jj_consume_token(37); +if (result == null) result = OptionContainer.create(); + jj_consume_token(39); optionName = jj_consume_token(NAME); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 38: - jj_consume_token(38); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 40:{ + jj_consume_token(40); option = value(); - jj_consume_token(39); - result.getOptions().put(optionName.image, option); + jj_consume_token(41); +result.getOptions().put(optionName.image, option); break; + } default: - jj_la1[20] = jj_gen; - result.getOptions().put(optionName.image, Flag.create().setValue(true)); + jj_la1[21] = jj_gen; +result.getOptions().put(optionName.image, Flag.create().setValue(true)); } } - {if (true) return result;} +{if ("" != null) return result;} throw new Error("Missing return statement in function"); - } +} final public void partOptions(Part part) throws ParseException { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 40: - jj_consume_token(40); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 42:{ + jj_consume_token(42); optionAssignment(part); label_7: while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 41: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 43:{ ; break; + } default: - jj_la1[21] = jj_gen; + jj_la1[22] = jj_gen; break label_7; } - jj_consume_token(41); + jj_consume_token(43); optionAssignment(part); } - jj_consume_token(42); + jj_consume_token(44); break; + } default: - jj_la1[22] = jj_gen; + jj_la1[23] = jj_gen; ; } - } +} final public void reserved() throws ParseException { jj_consume_token(RESERVED); reservation(); label_8: while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 41: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 43:{ ; break; + } default: - jj_la1[23] = jj_gen; + jj_la1[24] = jj_gen; break label_8; } - jj_consume_token(41); + jj_consume_token(43); reservation(); } - jj_consume_token(34); - } + jj_consume_token(36); +} final public void reservation() throws ParseException { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case NUMBER: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case NUMBER:{ jj_consume_token(NUMBER); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case TO: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case TO:{ jj_consume_token(TO); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case NUMBER: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case NUMBER:{ jj_consume_token(NUMBER); break; - case MAX: + } + case MAX:{ jj_consume_token(MAX); break; + } default: - jj_la1[24] = jj_gen; + jj_la1[25] = jj_gen; jj_consume_token(-1); throw new ParseException(); } break; + } default: - jj_la1[25] = jj_gen; + jj_la1[26] = jj_gen; ; } break; - case STRING: + } + case STRING:{ jj_consume_token(STRING); break; + } default: - jj_la1[26] = jj_gen; + jj_la1[27] = jj_gen; jj_consume_token(-1); throw new ParseException(); } - } +} final public void oneof() throws ParseException { jj_consume_token(ONEOF); jj_consume_token(NAME); - jj_consume_token(35); + jj_consume_token(37); label_9: while (true) { type(); jj_consume_token(NAME); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 33: - jj_consume_token(33); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 35:{ + jj_consume_token(35); jj_consume_token(NUMBER); break; + } default: - jj_la1[27] = jj_gen; + jj_la1[28] = jj_gen; ; } - jj_consume_token(34); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + jj_consume_token(36); + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case MAP: case TO: case MAX: @@ -557,144 +612,151 @@ final public void oneof() throws ParseException { case BOOLEAN_TYPE: case TYPE: case XNAME: - case NAME: + case NAME:{ ; break; + } default: - jj_la1[28] = jj_gen; + jj_la1[29] = jj_gen; break label_9; } } - jj_consume_token(36); - } + jj_consume_token(38); +} - final public Type type() throws ParseException { - Type result; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + final public Type type() throws ParseException {Type result; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case INT_TYPE: case LONG_TYPE: case BOOLEAN_TYPE: - case TYPE: + case TYPE:{ result = primitiveType(); break; + } case TO: case MAX: case XNAME: - case NAME: + case NAME:{ result = customType(); break; - case MAP: + } + case MAP:{ result = map(); break; + } default: - jj_la1[29] = jj_gen; + jj_la1[30] = jj_gen; jj_consume_token(-1); throw new ParseException(); } - {if (true) return result;} +{if ("" != null) return result;} throw new Error("Missing return statement in function"); - } +} - final public PrimitiveType primitiveType() throws ParseException { - Token t; + final public PrimitiveType primitiveType() throws ParseException {Token t; PrimitiveType result; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case TYPE: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case TYPE:{ t = jj_consume_token(TYPE); - result = PrimitiveType.create().setKind(PrimitiveType.Kind.valueOfProtocol(t.image.toUpperCase())); +result = PrimitiveType.create().setKind(PrimitiveType.Kind.valueOfProtocol(t.image.toUpperCase())); break; - case INT_TYPE: + } + case INT_TYPE:{ t = jj_consume_token(INT_TYPE); - result = PrimitiveType.create().setKind(PrimitiveType.Kind.INT_32); +result = PrimitiveType.create().setKind(PrimitiveType.Kind.INT_32); break; - case LONG_TYPE: + } + case LONG_TYPE:{ t = jj_consume_token(LONG_TYPE); - result = PrimitiveType.create().setKind(PrimitiveType.Kind.INT_64); +result = PrimitiveType.create().setKind(PrimitiveType.Kind.INT_64); break; - case BOOLEAN_TYPE: + } + case BOOLEAN_TYPE:{ t = jj_consume_token(BOOLEAN_TYPE); - result = PrimitiveType.create().setKind(PrimitiveType.Kind.BOOL); +result = PrimitiveType.create().setKind(PrimitiveType.Kind.BOOL); break; + } default: - jj_la1[30] = jj_gen; + jj_la1[31] = jj_gen; jj_consume_token(-1); throw new ParseException(); } - {if (true) return result;} +{if ("" != null) return result;} throw new Error("Missing return statement in function"); - } +} - final public CustomType customType() throws ParseException { - QName name; + final public CustomType customType() throws ParseException {QName name; name = qName(); - {if (true) return CustomType.create().setName(name);} +{if ("" != null) return CustomType.create().setName(name);} throw new Error("Missing return statement in function"); - } +} - final public MapType map() throws ParseException { - Type keyType; + final public MapType map() throws ParseException {Type keyType; Type valueType; jj_consume_token(MAP); - jj_consume_token(43); + jj_consume_token(45); keyType = type(); - jj_consume_token(41); + jj_consume_token(43); valueType = type(); - jj_consume_token(44); - {if (true) return MapType.create().setKeyType(keyType).setValueType(valueType);} + jj_consume_token(46); +{if ("" != null) return MapType.create().setKeyType(keyType).setValueType(valueType);} throw new Error("Missing return statement in function"); - } +} - final public QName qName() throws ParseException { - QName result = QName.create(); + final public QName qName() throws ParseException {QName result = QName.create(); String name; name = name(); - result.addName(name); +result.addName(name); label_10: while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 45: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 47:{ ; break; + } default: - jj_la1[31] = jj_gen; + jj_la1[32] = jj_gen; break label_10; } - jj_consume_token(45); + jj_consume_token(47); name = name(); - result.addName(name); +result.addName(name); } - {if (true) return result;} +{if ("" != null) return result;} throw new Error("Missing return statement in function"); - } +} - final public String name() throws ParseException { - Token t; + final public String name() throws ParseException {Token t; String result; - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case NAME: + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case NAME:{ t = jj_consume_token(NAME); - result = t.image; +result = t.image; break; - case TO: + } + case TO:{ t = jj_consume_token(TO); - result = t.image; +result = t.image; break; - case MAX: + } + case MAX:{ t = jj_consume_token(MAX); - result = t.image; +result = t.image; break; - case XNAME: + } + case XNAME:{ t = jj_consume_token(XNAME); - result = t.image.substring(1, t.image.length() - 1); +result = t.image.substring(1, t.image.length() - 1); break; + } default: - jj_la1[32] = jj_gen; + jj_la1[33] = jj_gen; jj_consume_token(-1); throw new ParseException(); } - {if (true) return result;} +{if ("" != null) return result;} throw new Error("Missing return statement in function"); - } +} /** Generated Token Manager. */ public ProtobufParserTokenManager token_source; @@ -705,125 +767,133 @@ final public String name() throws ParseException { public Token jj_nt; private int jj_ntk; private int jj_gen; - final private int[] jj_la1 = new int[33]; + final private int[] jj_la1 = new int[34]; static private int[] jj_la1_0; static private int[] jj_la1_1; static { - jj_la1_init_0(); - jj_la1_init_1(); - } - private static void jj_la1_init_0() { - jj_la1_0 = new int[] {0x200,0x100,0x10000,0x40c00,0x0,0x30c00000,0x40c00,0x4f34dc00,0x10000,0x40380000,0x40380000,0x0,0x40000,0x20000,0x4f3dfc00,0x4f3dfc00,0x8000,0x4000,0x0,0x0,0x0,0x0,0x0,0x0,0x10200000,0x100000,0x30000000,0x0,0x4f301000,0x4f301000,0xf000000,0x0,0x40300000,}; - } - private static void jj_la1_init_1() { - jj_la1_1 = new int[] {0x0,0x0,0x0,0x20,0x2,0x0,0x0,0x1,0x0,0x21,0x21,0x2,0x0,0x0,0x21,0x21,0x0,0x0,0x2,0x20,0x40,0x200,0x100,0x200,0x0,0x0,0x0,0x2,0x1,0x1,0x0,0x2000,0x1,}; - } + jj_la1_init_0(); + jj_la1_init_1(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x200,0x100,0x10000,0x40c00,0x0,0xc0c00000,0x40c00,0x1e34dc00,0x10000,0x380000,0x380000,0x0,0x40000,0x20000,0x1e3dfc00,0x1e3dfc00,0x8000,0x4000,0xc1c00000,0x0,0x0,0x0,0x0,0x0,0x0,0x40200000,0x100000,0xc0000000,0x0,0x1e301000,0x1e301000,0x1e000000,0x0,0x300000,}; + } + private static void jj_la1_init_1() { + jj_la1_1 = new int[] {0x0,0x0,0x0,0x80,0x8,0x0,0x0,0x5,0x0,0x85,0x85,0x8,0x0,0x0,0x85,0x85,0x0,0x0,0x0,0x8,0x80,0x100,0x800,0x400,0x800,0x0,0x0,0x0,0x8,0x5,0x5,0x0,0x8000,0x5,}; + } /** Constructor with InputStream. */ public ProtobufParser(java.io.InputStream stream) { - this(stream, null); + this(stream, null); } /** Constructor with InputStream and supplied encoding */ public ProtobufParser(java.io.InputStream stream, String encoding) { - try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } - token_source = new ProtobufParserTokenManager(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 33; i++) jj_la1[i] = -1; + try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source = new ProtobufParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 34; i++) jj_la1[i] = -1; } /** Reinitialise. */ public void ReInit(java.io.InputStream stream) { - ReInit(stream, null); + ReInit(stream, null); } /** Reinitialise. */ public void ReInit(java.io.InputStream stream, String encoding) { - try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } - token_source.ReInit(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 33; i++) jj_la1[i] = -1; + try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 34; i++) jj_la1[i] = -1; } /** Constructor. */ public ProtobufParser(java.io.Reader stream) { - jj_input_stream = new SimpleCharStream(stream, 1, 1); - token_source = new ProtobufParserTokenManager(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 33; i++) jj_la1[i] = -1; + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new ProtobufParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 34; i++) jj_la1[i] = -1; } /** Reinitialise. */ public void ReInit(java.io.Reader stream) { - jj_input_stream.ReInit(stream, 1, 1); - token_source.ReInit(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 33; i++) jj_la1[i] = -1; + if (jj_input_stream == null) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + } else { + jj_input_stream.ReInit(stream, 1, 1); + } + if (token_source == null) { + token_source = new ProtobufParserTokenManager(jj_input_stream); + } + + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 34; i++) jj_la1[i] = -1; } /** Constructor with generated Token Manager. */ public ProtobufParser(ProtobufParserTokenManager tm) { - token_source = tm; - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 33; i++) jj_la1[i] = -1; + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 34; i++) jj_la1[i] = -1; } /** Reinitialise. */ public void ReInit(ProtobufParserTokenManager tm) { - token_source = tm; - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 33; i++) jj_la1[i] = -1; + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 34; i++) jj_la1[i] = -1; } private Token jj_consume_token(int kind) throws ParseException { - Token oldToken; - if ((oldToken = token).next != null) token = token.next; - else token = token.next = token_source.getNextToken(); - jj_ntk = -1; - if (token.kind == kind) { - jj_gen++; - return token; - } - token = oldToken; - jj_kind = kind; - throw generateParseException(); + Token oldToken; + if ((oldToken = token).next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); } /** Get the next Token. */ final public Token getNextToken() { - if (token.next != null) token = token.next; - else token = token.next = token_source.getNextToken(); - jj_ntk = -1; - jj_gen++; - return token; + if (token.next != null) token = token.next; + else token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; } /** Get the specific Token. */ final public Token getToken(int index) { - Token t = token; - for (int i = 0; i < index; i++) { - if (t.next != null) t = t.next; - else t = t.next = token_source.getNextToken(); - } - return t; + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next != null) t = t.next; + else t = t.next = token_source.getNextToken(); + } + return t; } - private int jj_ntk() { - if ((jj_nt=token.next) == null) - return (jj_ntk = (token.next=token_source.getNextToken()).kind); - else - return (jj_ntk = jj_nt.kind); + private int jj_ntk_f() { + if ((jj_nt=token.next) == null) + return (jj_ntk = (token.next=token_source.getNextToken()).kind); + else + return (jj_ntk = jj_nt.kind); } private java.util.List jj_expentries = new java.util.ArrayList(); @@ -832,36 +902,43 @@ private int jj_ntk() { /** Generate ParseException. */ public ParseException generateParseException() { - jj_expentries.clear(); - boolean[] la1tokens = new boolean[46]; - if (jj_kind >= 0) { - la1tokens[jj_kind] = true; - jj_kind = -1; - } - for (int i = 0; i < 33; i++) { - if (jj_la1[i] == jj_gen) { - for (int j = 0; j < 32; j++) { - if ((jj_la1_0[i] & (1<= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 34; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1<", + "", "", "", "", diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParserTokenManager.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParserTokenManager.java index b8876ed9..bd4a5c7e 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParserTokenManager.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParserTokenManager.java @@ -1,149 +1,148 @@ +/* ProtobufParserTokenManager.java */ /* Generated By:JavaCC: Do not edit this line. ProtobufParserTokenManager.java */ package de.haumacher.msgbuf.generator.parser; -import de.haumacher.msgbuf.generator.ast.*; import de.haumacher.msgbuf.generator.common.Util; +import de.haumacher.msgbuf.generator.ast.*; /** Token Manager. */ -public class ProtobufParserTokenManager implements ProtobufParserConstants -{ +@SuppressWarnings ("unused") +public class ProtobufParserTokenManager implements ProtobufParserConstants { /** Debug output. */ public java.io.PrintStream debugStream = System.out; /** Set debug output. */ public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } -private final int jjStopStringLiteralDfa_0(int pos, long active0) -{ +private final int jjStopStringLiteralDfa_0(int pos, long active0){ switch (pos) { case 0: - if ((active0 & 0x800000L) != 0L) + if ((active0 & 0x200L) != 0L) { - jjmatchedKind = 32; - return 35; + jjmatchedKind = 34; + return 73; } - if ((active0 & 0x27ffd00L) != 0L) + if ((active0 & 0x800000L) != 0L) { - jjmatchedKind = 32; - return 30; + jjmatchedKind = 34; + return 40; } - if ((active0 & 0x1000000L) != 0L) + if ((active0 & 0x8000000L) != 0L) { - jjmatchedKind = 32; - return 51; + jjmatchedKind = 34; + return 98; } - if ((active0 & 0x200L) != 0L) + if ((active0 & 0x2000000L) != 0L) { - jjmatchedKind = 32; - return 68; + jjmatchedKind = 34; + return 56; } - if ((active0 & 0x4000000L) != 0L) + if ((active0 & 0x57ffd00L) != 0L) { - jjmatchedKind = 32; - return 93; + jjmatchedKind = 34; + return 35; } return -1; case 1: - if ((active0 & 0x4000000L) != 0L) + if ((active0 & 0x2000000L) != 0L) { - jjmatchedKind = 32; + jjmatchedKind = 34; jjmatchedPos = 1; - return 92; + return 55; } - if ((active0 & 0x1000000L) != 0L) + if ((active0 & 0x5efff00L) != 0L) { - jjmatchedKind = 32; + jjmatchedKind = 34; jjmatchedPos = 1; - return 50; + return 35; } - if ((active0 & 0x2efff00L) != 0L) + if ((active0 & 0x100000L) != 0L) + return 35; + if ((active0 & 0x8000000L) != 0L) { - jjmatchedKind = 32; + jjmatchedKind = 34; jjmatchedPos = 1; - return 30; + return 97; } - if ((active0 & 0x100000L) != 0L) - return 30; return -1; case 2: - if ((active0 & 0x1000000L) != 0L) - return 49; - if ((active0 & 0x2cfef00L) != 0L) + if ((active0 & 0x8000000L) != 0L) { - jjmatchedKind = 32; + jjmatchedKind = 34; jjmatchedPos = 2; - return 30; + return 96; } - if ((active0 & 0x201000L) != 0L) - return 30; - if ((active0 & 0x4000000L) != 0L) + if ((active0 & 0x5cfef00L) != 0L) { - jjmatchedKind = 32; + jjmatchedKind = 34; jjmatchedPos = 2; - return 91; + return 35; } + if ((active0 & 0x201000L) != 0L) + return 35; + if ((active0 & 0x2000000L) != 0L) + return 54; return -1; case 3: + if ((active0 & 0x5400800L) != 0L) + return 35; if ((active0 & 0x8fe700L) != 0L) { - jjmatchedKind = 32; + jjmatchedKind = 34; jjmatchedPos = 3; - return 30; + return 35; } - if ((active0 & 0x4000000L) != 0L) + if ((active0 & 0x8000000L) != 0L) { - jjmatchedKind = 27; + jjmatchedKind = 28; jjmatchedPos = 3; - return 30; + return 35; } - if ((active0 & 0x2400800L) != 0L) - return 30; return -1; case 4: - if ((active0 & 0x40fc700L) != 0L) + if ((active0 & 0x802000L) != 0L) + return 35; + if ((active0 & 0x80fc700L) != 0L) { - jjmatchedKind = 32; + jjmatchedKind = 34; jjmatchedPos = 4; - return 30; + return 35; } - if ((active0 & 0x802000L) != 0L) - return 30; return -1; case 5: - if ((active0 & 0x40ec500L) != 0L) + if ((active0 & 0x80ec500L) != 0L) { - jjmatchedKind = 32; + jjmatchedKind = 34; jjmatchedPos = 5; - return 30; + return 35; } if ((active0 & 0x10200L) != 0L) - return 30; + return 35; return -1; case 6: - if ((active0 & 0x4020500L) != 0L) - return 30; + if ((active0 & 0x8020500L) != 0L) + return 35; if ((active0 & 0xcc000L) != 0L) { - jjmatchedKind = 32; + jjmatchedKind = 34; jjmatchedPos = 6; - return 30; + return 35; } return -1; case 7: + if ((active0 & 0xc4000L) != 0L) + return 35; if ((active0 & 0x8000L) != 0L) { - jjmatchedKind = 32; + jjmatchedKind = 34; jjmatchedPos = 7; - return 30; + return 35; } - if ((active0 & 0xc4000L) != 0L) - return 30; return -1; default : return -1; } } -private final int jjStartNfa_0(int pos, long active0) -{ +private final int jjStartNfa_0(int pos, long active0){ return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); } private int jjStopAtPos(int pos, int kind) @@ -152,46 +151,47 @@ private int jjStopAtPos(int pos, int kind) jjmatchedPos = pos; return pos + 1; } -private int jjMoveStringLiteralDfa0_0() -{ +private int jjMoveStringLiteralDfa0_0(){ switch(curChar) { case 40: - return jjStopAtPos(0, 38); + return jjStopAtPos(0, 40); case 41: - return jjStopAtPos(0, 39); - case 44: return jjStopAtPos(0, 41); + case 44: + return jjStopAtPos(0, 43); case 46: - return jjStopAtPos(0, 45); + return jjStopAtPos(0, 47); case 59: - return jjStopAtPos(0, 34); + return jjStopAtPos(0, 36); case 60: - return jjStopAtPos(0, 43); + return jjStopAtPos(0, 45); case 61: - return jjStopAtPos(0, 33); + return jjStopAtPos(0, 35); case 62: - return jjStopAtPos(0, 44); + return jjStopAtPos(0, 46); case 64: - return jjStopAtPos(0, 37); + return jjStopAtPos(0, 39); case 91: - return jjStopAtPos(0, 40); - case 93: return jjStopAtPos(0, 42); + case 93: + return jjStopAtPos(0, 44); case 97: return jjMoveStringLiteralDfa1_0(0x40000L); case 98: - return jjMoveStringLiteralDfa1_0(0x4000000L); + return jjMoveStringLiteralDfa1_0(0x8000000L); case 101: return jjMoveStringLiteralDfa1_0(0x20800L); case 102: return jjMoveStringLiteralDfa1_0(0x800000L); case 105: - return jjMoveStringLiteralDfa1_0(0x1000000L); - case 108: return jjMoveStringLiteralDfa1_0(0x2000000L); + case 108: + return jjMoveStringLiteralDfa1_0(0x4000000L); case 109: return jjMoveStringLiteralDfa1_0(0x201400L); + case 110: + return jjMoveStringLiteralDfa1_0(0x1000000L); case 111: return jjMoveStringLiteralDfa1_0(0x12000L); case 112: @@ -203,15 +203,14 @@ private int jjMoveStringLiteralDfa0_0() case 116: return jjMoveStringLiteralDfa1_0(0x508000L); case 123: - return jjStopAtPos(0, 35); + return jjStopAtPos(0, 37); case 125: - return jjStopAtPos(0, 36); + return jjStopAtPos(0, 38); default : return jjMoveNfa_0(5, 0); } } -private int jjMoveStringLiteralDfa1_0(long active0) -{ +private int jjMoveStringLiteralDfa1_0(long active0){ try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(0, active0); @@ -226,15 +225,17 @@ private int jjMoveStringLiteralDfa1_0(long active0) case 101: return jjMoveStringLiteralDfa2_0(active0, 0x84400L); case 110: - return jjMoveStringLiteralDfa2_0(active0, 0x1002800L); + return jjMoveStringLiteralDfa2_0(active0, 0x2002800L); case 111: if ((active0 & 0x100000L) != 0L) - return jjStartNfaWithStates_0(1, 20, 30); - return jjMoveStringLiteralDfa2_0(active0, 0x6000000L); + return jjStartNfaWithStates_0(1, 20, 35); + return jjMoveStringLiteralDfa2_0(active0, 0xc000000L); case 112: return jjMoveStringLiteralDfa2_0(active0, 0x10000L); case 114: return jjMoveStringLiteralDfa2_0(active0, 0x408000L); + case 117: + return jjMoveStringLiteralDfa2_0(active0, 0x1000000L); case 120: return jjMoveStringLiteralDfa2_0(active0, 0x20000L); case 121: @@ -244,8 +245,7 @@ private int jjMoveStringLiteralDfa1_0(long active0) } return jjStartNfa_0(0, active0); } -private int jjMoveStringLiteralDfa2_0(long old0, long active0) -{ +private int jjMoveStringLiteralDfa2_0(long old0, long active0){ if (((active0 &= old0)) == 0L) return jjStartNfa_0(0, old0); try { curChar = input_stream.readChar(); } @@ -262,34 +262,33 @@ private int jjMoveStringLiteralDfa2_0(long old0, long active0) case 101: return jjMoveStringLiteralDfa3_0(active0, 0x2000L); case 108: - return jjMoveStringLiteralDfa3_0(active0, 0x800000L); + return jjMoveStringLiteralDfa3_0(active0, 0x1800000L); case 110: - return jjMoveStringLiteralDfa3_0(active0, 0x2000200L); + return jjMoveStringLiteralDfa3_0(active0, 0x4000200L); case 111: - return jjMoveStringLiteralDfa3_0(active0, 0x4000000L); + return jjMoveStringLiteralDfa3_0(active0, 0x8000000L); case 112: if ((active0 & 0x1000L) != 0L) - return jjStartNfaWithStates_0(2, 12, 30); + return jjStartNfaWithStates_0(2, 12, 35); return jjMoveStringLiteralDfa3_0(active0, 0x4000L); case 115: return jjMoveStringLiteralDfa3_0(active0, 0xc0400L); case 116: - if ((active0 & 0x1000000L) != 0L) - return jjStartNfaWithStates_0(2, 24, 49); + if ((active0 & 0x2000000L) != 0L) + return jjStartNfaWithStates_0(2, 25, 54); return jjMoveStringLiteralDfa3_0(active0, 0x30000L); case 117: return jjMoveStringLiteralDfa3_0(active0, 0x400800L); case 120: if ((active0 & 0x200000L) != 0L) - return jjStartNfaWithStates_0(2, 21, 30); + return jjStartNfaWithStates_0(2, 21, 35); break; default : break; } return jjStartNfa_0(1, active0); } -private int jjMoveStringLiteralDfa3_0(long old0, long active0) -{ +private int jjMoveStringLiteralDfa3_0(long old0, long active0){ if (((active0 &= old0)) == 0L) return jjStartNfa_0(1, old0); try { curChar = input_stream.readChar(); } @@ -301,21 +300,23 @@ private int jjMoveStringLiteralDfa3_0(long old0, long active0) { case 101: if ((active0 & 0x400000L) != 0L) - return jjStartNfaWithStates_0(3, 22, 30); + return jjStartNfaWithStates_0(3, 22, 35); return jjMoveStringLiteralDfa4_0(active0, 0xa4000L); case 103: - if ((active0 & 0x2000000L) != 0L) - return jjStartNfaWithStates_0(3, 25, 30); + if ((active0 & 0x4000000L) != 0L) + return jjStartNfaWithStates_0(3, 26, 35); break; case 105: return jjMoveStringLiteralDfa4_0(active0, 0x10000L); case 107: return jjMoveStringLiteralDfa4_0(active0, 0x100L); case 108: - return jjMoveStringLiteralDfa4_0(active0, 0x4000000L); + if ((active0 & 0x1000000L) != 0L) + return jjStartNfaWithStates_0(3, 24, 35); + return jjMoveStringLiteralDfa4_0(active0, 0x8000000L); case 109: if ((active0 & 0x800L) != 0L) - return jjStartNfaWithStates_0(3, 11, 30); + return jjStartNfaWithStates_0(3, 11, 35); break; case 110: return jjMoveStringLiteralDfa4_0(active0, 0x8000L); @@ -330,8 +331,7 @@ private int jjMoveStringLiteralDfa3_0(long old0, long active0) } return jjStartNfa_0(2, active0); } -private int jjMoveStringLiteralDfa4_0(long old0, long active0) -{ +private int jjMoveStringLiteralDfa4_0(long old0, long active0){ if (((active0 &= old0)) == 0L) return jjStartNfa_0(2, old0); try { curChar = input_stream.readChar(); } @@ -345,11 +345,11 @@ private int jjMoveStringLiteralDfa4_0(long old0, long active0) return jjMoveStringLiteralDfa5_0(active0, 0x4700L); case 101: if ((active0 & 0x800000L) != 0L) - return jjStartNfaWithStates_0(4, 23, 30); - return jjMoveStringLiteralDfa5_0(active0, 0x4000000L); + return jjStartNfaWithStates_0(4, 23, 35); + return jjMoveStringLiteralDfa5_0(active0, 0x8000000L); case 102: if ((active0 & 0x2000L) != 0L) - return jjStartNfaWithStates_0(4, 13, 30); + return jjStartNfaWithStates_0(4, 13, 35); break; case 110: return jjMoveStringLiteralDfa5_0(active0, 0x20000L); @@ -364,8 +364,7 @@ private int jjMoveStringLiteralDfa4_0(long old0, long active0) } return jjStartNfa_0(3, active0); } -private int jjMoveStringLiteralDfa5_0(long old0, long active0) -{ +private int jjMoveStringLiteralDfa5_0(long old0, long active0){ if (((active0 &= old0)) == 0L) return jjStartNfa_0(3, old0); try { curChar = input_stream.readChar(); } @@ -376,7 +375,7 @@ private int jjMoveStringLiteralDfa5_0(long old0, long active0) switch(curChar) { case 97: - return jjMoveStringLiteralDfa6_0(active0, 0x4040000L); + return jjMoveStringLiteralDfa6_0(active0, 0x8040000L); case 100: return jjMoveStringLiteralDfa6_0(active0, 0x20000L); case 103: @@ -385,7 +384,7 @@ private int jjMoveStringLiteralDfa5_0(long old0, long active0) return jjMoveStringLiteralDfa6_0(active0, 0x8000L); case 110: if ((active0 & 0x10000L) != 0L) - return jjStartNfaWithStates_0(5, 16, 30); + return jjStartNfaWithStates_0(5, 16, 35); break; case 116: return jjMoveStringLiteralDfa6_0(active0, 0x4000L); @@ -393,15 +392,14 @@ private int jjMoveStringLiteralDfa5_0(long old0, long active0) return jjMoveStringLiteralDfa6_0(active0, 0x80000L); case 120: if ((active0 & 0x200L) != 0L) - return jjStartNfaWithStates_0(5, 9, 30); + return jjStartNfaWithStates_0(5, 9, 35); break; default : break; } return jjStartNfa_0(4, active0); } -private int jjMoveStringLiteralDfa6_0(long old0, long active0) -{ +private int jjMoveStringLiteralDfa6_0(long old0, long active0){ if (((active0 &= old0)) == 0L) return jjStartNfa_0(4, old0); try { curChar = input_stream.readChar(); } @@ -415,25 +413,24 @@ private int jjMoveStringLiteralDfa6_0(long old0, long active0) return jjMoveStringLiteralDfa7_0(active0, 0x40000L); case 101: if ((active0 & 0x100L) != 0L) - return jjStartNfaWithStates_0(6, 8, 30); + return jjStartNfaWithStates_0(6, 8, 35); else if ((active0 & 0x400L) != 0L) - return jjStartNfaWithStates_0(6, 10, 30); + return jjStartNfaWithStates_0(6, 10, 35); return jjMoveStringLiteralDfa7_0(active0, 0x8c000L); case 110: - if ((active0 & 0x4000000L) != 0L) - return jjStartNfaWithStates_0(6, 26, 30); + if ((active0 & 0x8000000L) != 0L) + return jjStartNfaWithStates_0(6, 27, 35); break; case 115: if ((active0 & 0x20000L) != 0L) - return jjStartNfaWithStates_0(6, 17, 30); + return jjStartNfaWithStates_0(6, 17, 35); break; default : break; } return jjStartNfa_0(5, active0); } -private int jjMoveStringLiteralDfa7_0(long old0, long active0) -{ +private int jjMoveStringLiteralDfa7_0(long old0, long active0){ if (((active0 &= old0)) == 0L) return jjStartNfa_0(5, old0); try { curChar = input_stream.readChar(); } @@ -445,23 +442,22 @@ private int jjMoveStringLiteralDfa7_0(long old0, long active0) { case 100: if ((active0 & 0x4000L) != 0L) - return jjStartNfaWithStates_0(7, 14, 30); + return jjStartNfaWithStates_0(7, 14, 35); else if ((active0 & 0x80000L) != 0L) - return jjStartNfaWithStates_0(7, 19, 30); + return jjStartNfaWithStates_0(7, 19, 35); break; case 110: return jjMoveStringLiteralDfa8_0(active0, 0x8000L); case 116: if ((active0 & 0x40000L) != 0L) - return jjStartNfaWithStates_0(7, 18, 30); + return jjStartNfaWithStates_0(7, 18, 35); break; default : break; } return jjStartNfa_0(6, active0); } -private int jjMoveStringLiteralDfa8_0(long old0, long active0) -{ +private int jjMoveStringLiteralDfa8_0(long old0, long active0){ if (((active0 &= old0)) == 0L) return jjStartNfa_0(6, old0); try { curChar = input_stream.readChar(); } @@ -473,7 +469,7 @@ private int jjMoveStringLiteralDfa8_0(long old0, long active0) { case 116: if ((active0 & 0x8000L) != 0L) - return jjStartNfaWithStates_0(8, 15, 30); + return jjStartNfaWithStates_0(8, 15, 35); break; default : break; @@ -497,7 +493,7 @@ private int jjStartNfaWithStates_0(int pos, int kind, int state) private int jjMoveNfa_0(int startState, int curPos) { int startsAt = 0; - jjnewStateCnt = 119; + jjnewStateCnt = 124; int i = 1; jjstateSet[0] = startState; int kind = 0x7fffffff; @@ -512,266 +508,288 @@ private int jjMoveNfa_0(int startState, int curPos) { switch(jjstateSet[--i]) { + case 55: case 35: - case 30: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 32) - kind = 32; - jjCheckNAdd(30); - break; - case 91: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 32) - kind = 32; - jjCheckNAdd(30); - break; - case 93: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 32) - kind = 32; - jjCheckNAdd(30); + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } break; - case 68: + case 96: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 32) - kind = 32; - jjCheckNAdd(30); + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } break; case 5: if ((0x3fe000000000000L & l) != 0L) { - if (kind > 28) - kind = 28; - jjCheckNAddTwoStates(11, 8); + if (kind > 30) + kind = 30; + { jjCheckNAddStates(0, 2); } } else if (curChar == 47) - jjAddStates(0, 4); + { jjAddStates(3, 7); } else if (curChar == 34) - jjCheckNAddStates(5, 7); + { jjCheckNAddStates(8, 10); } else if (curChar == 39) - jjCheckNAddStates(8, 10); + { jjCheckNAddStates(11, 13); } else if (curChar == 48) { - if (kind > 28) - kind = 28; - jjCheckNAdd(8); + if (kind > 30) + kind = 30; + { jjCheckNAddTwoStates(8, 10); } } else if (curChar == 45) - jjAddStates(11, 12); - break; - case 92: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 32) - kind = 32; - jjCheckNAdd(30); + { jjAddStates(14, 15); } break; - case 49: + case 54: if ((0x3ff000000000000L & l) != 0L) { - if (kind > 32) - kind = 32; - jjCheckNAdd(30); + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } } if (curChar == 54) - jjCheckNAdd(42); + { jjCheckNAdd(47); } else if (curChar == 51) - jjCheckNAdd(36); + { jjCheckNAdd(41); } break; - case 51: + case 40: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 32) - kind = 32; - jjCheckNAdd(30); + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } break; - case 50: + case 97: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 32) - kind = 32; - jjCheckNAdd(30); + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } + break; + case 73: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } + break; + case 98: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } + break; + case 56: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } break; case 6: if (curChar == 45) - jjAddStates(11, 12); + { jjAddStates(14, 15); } break; case 7: if (curChar != 48) break; - if (kind > 28) - kind = 28; - jjCheckNAdd(8); + if (kind > 30) + kind = 30; + { jjCheckNAddTwoStates(8, 10); } break; case 8: if (curChar == 46) - jjCheckNAdd(9); + { jjCheckNAdd(9); } break; case 9: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 28) - kind = 28; - jjCheckNAdd(9); + if (kind > 30) + kind = 30; + { jjCheckNAddTwoStates(9, 10); } break; - case 10: + case 11: + if ((0x280000000000L & l) != 0L) + { jjAddStates(16, 17); } + break; + case 12: + if (curChar == 48 && kind > 30) + kind = 30; + break; + case 13: if ((0x3fe000000000000L & l) == 0L) break; - if (kind > 28) - kind = 28; - jjCheckNAddTwoStates(11, 8); + if (kind > 30) + kind = 30; + { jjCheckNAdd(14); } break; - case 11: + case 14: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 28) - kind = 28; - jjCheckNAddTwoStates(11, 8); + if (kind > 30) + kind = 30; + { jjCheckNAdd(14); } + break; + case 15: + if ((0x3fe000000000000L & l) == 0L) + break; + if (kind > 30) + kind = 30; + { jjCheckNAddStates(0, 2); } + break; + case 16: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 30) + kind = 30; + { jjCheckNAddStates(0, 2); } break; - case 12: case 17: + case 22: if (curChar == 39) - jjCheckNAddStates(8, 10); + { jjCheckNAddStates(11, 13); } break; - case 13: + case 18: if ((0xffffff7fffffffffL & l) != 0L) - jjCheckNAddStates(8, 10); + { jjCheckNAddStates(11, 13); } break; - case 14: - if (curChar == 39 && kind > 29) - kind = 29; + case 19: + if (curChar == 39 && kind > 31) + kind = 31; break; - case 16: + case 21: if (curChar == 34) - jjCheckNAddStates(8, 10); + { jjCheckNAddStates(11, 13); } break; - case 19: - case 23: + case 24: + case 28: if (curChar == 34) - jjCheckNAddStates(5, 7); + { jjCheckNAddStates(8, 10); } break; - case 20: + case 25: if ((0xfffffffbffffffffL & l) != 0L) - jjCheckNAddStates(5, 7); + { jjCheckNAddStates(8, 10); } break; - case 21: - if (curChar == 34 && kind > 29) - kind = 29; + case 26: + if (curChar == 34 && kind > 31) + kind = 31; break; - case 24: + case 29: if (curChar == 39) - jjCheckNAddStates(5, 7); + { jjCheckNAddStates(8, 10); } break; - case 27: - jjAddStates(13, 14); + case 32: + { jjAddStates(18, 19); } break; - case 36: - if (curChar == 50 && kind > 27) - kind = 27; + case 41: + if (curChar == 50 && kind > 28) + kind = 28; break; - case 37: - case 56: - case 65: - case 69: + case 42: + case 61: + case 70: + case 74: if (curChar == 51) - jjCheckNAdd(36); + { jjCheckNAdd(41); } break; - case 42: - if (curChar == 52 && kind > 27) - kind = 27; + case 47: + if (curChar == 52 && kind > 28) + kind = 28; break; - case 43: - case 60: - case 75: - case 79: + case 48: + case 65: + case 80: + case 84: if (curChar == 54) - jjCheckNAdd(42); + { jjCheckNAdd(47); } break; - case 52: + case 57: if (curChar == 54) - jjCheckNAdd(42); + { jjCheckNAdd(47); } break; - case 98: + case 103: if (curChar == 47) - jjAddStates(0, 4); + { jjAddStates(3, 7); } break; - case 99: + case 104: if (curChar == 42) - jjCheckNAdd(100); + { jjCheckNAdd(105); } break; - case 100: + case 105: if ((0xfffffbffffffffffL & l) != 0L) - jjCheckNAddStates(15, 17); + { jjCheckNAddStates(20, 22); } break; - case 101: + case 106: if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 102; + jjstateSet[jjnewStateCnt++] = 107; break; - case 102: + case 107: if ((0xffff7fffffffffffL & l) != 0L) - jjCheckNAddStates(15, 17); + { jjCheckNAddStates(20, 22); } break; - case 103: + case 108: if (curChar == 47 && kind > 5) kind = 5; break; - case 104: - case 105: + case 109: + case 110: if (curChar == 42) - jjCheckNAdd(103); + { jjCheckNAdd(108); } break; - case 106: + case 111: if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 105; + jjstateSet[jjnewStateCnt++] = 110; break; - case 107: + case 112: if (curChar == 47) - jjCheckNAddTwoStates(108, 109); + { jjCheckNAddTwoStates(113, 114); } break; - case 108: + case 113: if ((0xffffffffffffdbffL & l) != 0L) - jjCheckNAddTwoStates(108, 109); + { jjCheckNAddTwoStates(113, 114); } break; - case 109: + case 114: if ((0x2400L & l) != 0L && kind > 6) kind = 6; break; - case 110: + case 115: if (curChar == 42) - jjCheckNAddStates(18, 20); + { jjCheckNAddStates(23, 25); } break; - case 111: + case 116: if ((0xfffffbffffffffffL & l) != 0L) - jjCheckNAddStates(18, 20); + { jjCheckNAddStates(23, 25); } break; - case 112: + case 117: if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 113; + jjstateSet[jjnewStateCnt++] = 118; break; - case 113: + case 118: if ((0xffff7fffffffffffL & l) != 0L) - jjCheckNAddStates(18, 20); + { jjCheckNAddStates(23, 25); } break; - case 114: + case 119: if (curChar == 47 && kind > 7) kind = 7; break; - case 115: - case 117: + case 120: + case 122: if (curChar == 42) - jjCheckNAdd(114); + { jjCheckNAdd(119); } break; - case 116: + case 121: if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 110; + jjstateSet[jjnewStateCnt++] = 115; break; - case 118: + case 123: if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 117; + jjstateSet[jjnewStateCnt++] = 122; break; default : break; } @@ -784,130 +802,130 @@ else if (curChar < 128) { switch(jjstateSet[--i]) { - case 35: + case 55: if ((0x7fffffe87fffffeL & l) != 0L) { - if (kind > 32) - kind = 32; - jjCheckNAdd(30); + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } } - if (curChar == 105) - jjstateSet[jjnewStateCnt++] = 46; - else if (curChar == 108) - jjstateSet[jjnewStateCnt++] = 34; - if (curChar == 105) - jjstateSet[jjnewStateCnt++] = 40; + if (curChar == 116) + jjstateSet[jjnewStateCnt++] = 57; + if (curChar == 116) + jjstateSet[jjnewStateCnt++] = 54; break; - case 91: + case 96: if ((0x7fffffe87fffffeL & l) != 0L) { - if (kind > 32) - kind = 32; - jjCheckNAdd(30); + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } } if (curChar == 108) { - if (kind > 27) - kind = 27; + if (kind > 28) + kind = 28; } break; - case 93: - if ((0x7fffffe87fffffeL & l) != 0L) - { - if (kind > 32) - kind = 32; - jjCheckNAdd(30); - } - if (curChar == 121) - jjstateSet[jjnewStateCnt++] = 96; - else if (curChar == 111) - jjstateSet[jjnewStateCnt++] = 92; - break; - case 68: - if ((0x7fffffe87fffffeL & l) != 0L) - { - if (kind > 32) - kind = 32; - jjCheckNAdd(30); - } - if (curChar == 116) - jjstateSet[jjnewStateCnt++] = 88; - else if (curChar == 102) - jjstateSet[jjnewStateCnt++] = 83; - else if (curChar == 105) - jjstateSet[jjnewStateCnt++] = 77; - if (curChar == 102) - jjstateSet[jjnewStateCnt++] = 73; - else if (curChar == 105) - jjstateSet[jjnewStateCnt++] = 67; - break; case 5: if ((0x7fffffe87fffffeL & l) != 0L) { - if (kind > 32) - kind = 32; - jjCheckNAdd(30); + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } } else if (curChar == 96) - jjCheckNAdd(27); + { jjCheckNAdd(32); } if (curChar == 98) - jjAddStates(21, 22); + { jjAddStates(26, 27); } else if (curChar == 115) - jjAddStates(23, 27); + { jjAddStates(28, 32); } else if (curChar == 117) - jjAddStates(28, 29); + { jjAddStates(33, 34); } else if (curChar == 105) - jjAddStates(30, 31); + { jjAddStates(35, 36); } else if (curChar == 102) - jjAddStates(32, 34); + { jjAddStates(37, 39); } else if (curChar == 100) jjstateSet[jjnewStateCnt++] = 4; break; - case 92: + case 54: + case 35: + if ((0x7fffffe87fffffeL & l) == 0L) + break; + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } + break; + case 40: + if ((0x7fffffe87fffffeL & l) != 0L) + { + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } + } + if (curChar == 105) + jjstateSet[jjnewStateCnt++] = 51; + else if (curChar == 108) + jjstateSet[jjnewStateCnt++] = 39; + if (curChar == 105) + jjstateSet[jjnewStateCnt++] = 45; + break; + case 97: if ((0x7fffffe87fffffeL & l) != 0L) { - if (kind > 32) - kind = 32; - jjCheckNAdd(30); + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } } if (curChar == 111) - jjstateSet[jjnewStateCnt++] = 91; + jjstateSet[jjnewStateCnt++] = 96; break; - case 49: - case 30: - if ((0x7fffffe87fffffeL & l) == 0L) - break; - if (kind > 32) - kind = 32; - jjCheckNAdd(30); + case 73: + if ((0x7fffffe87fffffeL & l) != 0L) + { + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } + } + if (curChar == 116) + jjstateSet[jjnewStateCnt++] = 93; + else if (curChar == 102) + jjstateSet[jjnewStateCnt++] = 88; + else if (curChar == 105) + jjstateSet[jjnewStateCnt++] = 82; + if (curChar == 102) + jjstateSet[jjnewStateCnt++] = 78; + else if (curChar == 105) + jjstateSet[jjnewStateCnt++] = 72; break; - case 51: + case 98: if ((0x7fffffe87fffffeL & l) != 0L) { - if (kind > 32) - kind = 32; - jjCheckNAdd(30); + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } } - if (curChar == 110) - jjstateSet[jjnewStateCnt++] = 53; - if (curChar == 110) - jjstateSet[jjnewStateCnt++] = 50; + if (curChar == 121) + jjstateSet[jjnewStateCnt++] = 101; + else if (curChar == 111) + jjstateSet[jjnewStateCnt++] = 97; break; - case 50: + case 56: if ((0x7fffffe87fffffeL & l) != 0L) { - if (kind > 32) - kind = 32; - jjCheckNAdd(30); + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } } - if (curChar == 116) - jjstateSet[jjnewStateCnt++] = 52; - if (curChar == 116) - jjstateSet[jjnewStateCnt++] = 49; + if (curChar == 110) + jjstateSet[jjnewStateCnt++] = 58; + if (curChar == 110) + jjstateSet[jjnewStateCnt++] = 55; break; case 0: - if (curChar == 101 && kind > 27) - kind = 27; + if (curChar == 101 && kind > 28) + kind = 28; break; case 1: if (curChar == 108) @@ -925,140 +943,128 @@ else if (curChar == 100) if (curChar == 111) jjstateSet[jjnewStateCnt++] = 3; break; - case 13: + case 10: + if ((0x2000000020L & l) != 0L) + { jjAddStates(40, 42); } + break; + case 18: if ((0xffffffffefffffffL & l) != 0L) - jjCheckNAddStates(8, 10); + { jjCheckNAddStates(11, 13); } break; - case 15: + case 20: if (curChar == 92) - jjAddStates(35, 37); + { jjAddStates(43, 45); } break; - case 18: + case 23: if (curChar == 92) - jjCheckNAddStates(8, 10); + { jjCheckNAddStates(11, 13); } break; - case 20: + case 25: if ((0xffffffffefffffffL & l) != 0L) - jjCheckNAddStates(5, 7); + { jjCheckNAddStates(8, 10); } break; - case 22: + case 27: if (curChar == 92) - jjAddStates(38, 40); + { jjAddStates(46, 48); } break; - case 25: + case 30: if (curChar == 92) - jjCheckNAddStates(5, 7); + { jjCheckNAddStates(8, 10); } break; - case 26: + case 31: if (curChar == 96) - jjCheckNAdd(27); + { jjCheckNAdd(32); } break; - case 27: + case 32: if ((0xfffffffeffffffffL & l) != 0L) - jjCheckNAddTwoStates(27, 28); + { jjCheckNAddTwoStates(32, 33); } break; - case 28: - if (curChar == 96 && kind > 30) - kind = 30; + case 33: + if (curChar == 96 && kind > 32) + kind = 32; break; - case 29: + case 34: if ((0x7fffffe87fffffeL & l) == 0L) break; - if (kind > 32) - kind = 32; - jjCheckNAdd(30); + if (kind > 34) + kind = 34; + { jjCheckNAdd(35); } break; - case 31: + case 36: if (curChar == 102) - jjAddStates(32, 34); + { jjAddStates(37, 39); } break; - case 32: - if (curChar == 116 && kind > 27) - kind = 27; + case 37: + if (curChar == 116 && kind > 28) + kind = 28; break; - case 33: + case 38: if (curChar == 97) - jjstateSet[jjnewStateCnt++] = 32; + jjstateSet[jjnewStateCnt++] = 37; break; - case 34: + case 39: if (curChar == 111) - jjstateSet[jjnewStateCnt++] = 33; + jjstateSet[jjnewStateCnt++] = 38; break; - case 38: + case 43: if (curChar == 100) - jjstateSet[jjnewStateCnt++] = 37; + jjstateSet[jjnewStateCnt++] = 42; break; - case 39: + case 44: if (curChar == 101) - jjstateSet[jjnewStateCnt++] = 38; + jjstateSet[jjnewStateCnt++] = 43; break; - case 40: + case 45: if (curChar == 120) - jjstateSet[jjnewStateCnt++] = 39; + jjstateSet[jjnewStateCnt++] = 44; break; - case 41: + case 46: if (curChar == 105) - jjstateSet[jjnewStateCnt++] = 40; + jjstateSet[jjnewStateCnt++] = 45; break; - case 44: + case 49: if (curChar == 100) - jjstateSet[jjnewStateCnt++] = 43; + jjstateSet[jjnewStateCnt++] = 48; break; - case 45: + case 50: if (curChar == 101) - jjstateSet[jjnewStateCnt++] = 44; + jjstateSet[jjnewStateCnt++] = 49; break; - case 46: + case 51: if (curChar == 120) - jjstateSet[jjnewStateCnt++] = 45; - break; - case 47: - if (curChar == 105) - jjstateSet[jjnewStateCnt++] = 46; + jjstateSet[jjnewStateCnt++] = 50; break; - case 48: + case 52: if (curChar == 105) - jjAddStates(30, 31); + jjstateSet[jjnewStateCnt++] = 51; break; case 53: - if (curChar == 116) - jjstateSet[jjnewStateCnt++] = 52; - break; - case 54: - if (curChar == 110) - jjstateSet[jjnewStateCnt++] = 53; - break; - case 55: - if (curChar == 117) - jjAddStates(28, 29); - break; - case 57: - if (curChar == 116) - jjstateSet[jjnewStateCnt++] = 56; + if (curChar == 105) + { jjAddStates(35, 36); } break; case 58: - if (curChar == 110) + if (curChar == 116) jjstateSet[jjnewStateCnt++] = 57; break; case 59: - if (curChar == 105) + if (curChar == 110) jjstateSet[jjnewStateCnt++] = 58; break; - case 61: - if (curChar == 116) - jjstateSet[jjnewStateCnt++] = 60; + case 60: + if (curChar == 117) + { jjAddStates(33, 34); } break; case 62: - if (curChar == 110) + if (curChar == 116) jjstateSet[jjnewStateCnt++] = 61; break; case 63: - if (curChar == 105) + if (curChar == 110) jjstateSet[jjnewStateCnt++] = 62; break; case 64: - if (curChar == 115) - jjAddStates(23, 27); + if (curChar == 105) + jjstateSet[jjnewStateCnt++] = 63; break; case 66: if (curChar == 116) @@ -1068,108 +1074,124 @@ else if (curChar == 100) if (curChar == 110) jjstateSet[jjnewStateCnt++] = 66; break; - case 70: - if (curChar == 100) - jjstateSet[jjnewStateCnt++] = 69; + case 68: + if (curChar == 105) + jjstateSet[jjnewStateCnt++] = 67; + break; + case 69: + if (curChar == 115) + { jjAddStates(28, 32); } break; case 71: - if (curChar == 101) + if (curChar == 116) jjstateSet[jjnewStateCnt++] = 70; break; case 72: - if (curChar == 120) + if (curChar == 110) jjstateSet[jjnewStateCnt++] = 71; break; - case 73: - if (curChar == 105) - jjstateSet[jjnewStateCnt++] = 72; - break; - case 74: - if (curChar == 102) - jjstateSet[jjnewStateCnt++] = 73; + case 75: + if (curChar == 100) + jjstateSet[jjnewStateCnt++] = 74; break; case 76: - if (curChar == 116) + if (curChar == 101) jjstateSet[jjnewStateCnt++] = 75; break; case 77: - if (curChar == 110) + if (curChar == 120) jjstateSet[jjnewStateCnt++] = 76; break; case 78: if (curChar == 105) jjstateSet[jjnewStateCnt++] = 77; break; - case 80: - if (curChar == 100) - jjstateSet[jjnewStateCnt++] = 79; + case 79: + if (curChar == 102) + jjstateSet[jjnewStateCnt++] = 78; break; case 81: - if (curChar == 101) + if (curChar == 116) jjstateSet[jjnewStateCnt++] = 80; break; case 82: - if (curChar == 120) + if (curChar == 110) jjstateSet[jjnewStateCnt++] = 81; break; case 83: if (curChar == 105) jjstateSet[jjnewStateCnt++] = 82; break; - case 84: - if (curChar == 102) - jjstateSet[jjnewStateCnt++] = 83; - break; case 85: - if (curChar == 103 && kind > 27) - kind = 27; + if (curChar == 100) + jjstateSet[jjnewStateCnt++] = 84; break; case 86: - if (curChar == 110) + if (curChar == 101) jjstateSet[jjnewStateCnt++] = 85; break; case 87: - if (curChar == 105) + if (curChar == 120) jjstateSet[jjnewStateCnt++] = 86; break; case 88: - if (curChar == 114) + if (curChar == 105) jjstateSet[jjnewStateCnt++] = 87; break; case 89: - if (curChar == 116) + if (curChar == 102) jjstateSet[jjnewStateCnt++] = 88; break; case 90: - if (curChar == 98) - jjAddStates(21, 22); + if (curChar == 103 && kind > 28) + kind = 28; + break; + case 91: + if (curChar == 110) + jjstateSet[jjnewStateCnt++] = 90; + break; + case 92: + if (curChar == 105) + jjstateSet[jjnewStateCnt++] = 91; + break; + case 93: + if (curChar == 114) + jjstateSet[jjnewStateCnt++] = 92; break; case 94: - if (curChar == 115 && kind > 27) - kind = 27; + if (curChar == 116) + jjstateSet[jjnewStateCnt++] = 93; break; case 95: + if (curChar == 98) + { jjAddStates(26, 27); } + break; + case 99: + if (curChar == 115 && kind > 28) + kind = 28; + break; + case 100: if (curChar == 101) - jjstateSet[jjnewStateCnt++] = 94; + jjstateSet[jjnewStateCnt++] = 99; break; - case 96: + case 101: if (curChar == 116) - jjstateSet[jjnewStateCnt++] = 95; + jjstateSet[jjnewStateCnt++] = 100; break; - case 97: - if (curChar == 121) - jjstateSet[jjnewStateCnt++] = 96; - break; - case 100: case 102: - jjCheckNAddStates(15, 17); + if (curChar == 121) + jjstateSet[jjnewStateCnt++] = 101; break; - case 108: - jjAddStates(41, 42); + case 105: + case 107: + { jjCheckNAddStates(20, 22); } break; - case 111: case 113: - jjCheckNAddStates(18, 20); + { jjAddStates(49, 50); } + break; + case 116: + case 118: + { jjCheckNAddStates(23, 25); } break; default : break; } @@ -1177,7 +1199,7 @@ else if (curChar == 100) } else { - int hiByte = (int)(curChar >> 8); + int hiByte = (curChar >> 8); int i1 = hiByte >> 6; long l1 = 1L << (hiByte & 077); int i2 = (curChar & 0xff) >> 6; @@ -1186,33 +1208,33 @@ else if (curChar == 100) { switch(jjstateSet[--i]) { - case 13: + case 18: if (jjCanMove_0(hiByte, i1, i2, l1, l2)) - jjAddStates(8, 10); + { jjAddStates(11, 13); } break; - case 20: + case 25: if (jjCanMove_0(hiByte, i1, i2, l1, l2)) - jjAddStates(5, 7); + { jjAddStates(8, 10); } break; - case 27: + case 32: if (jjCanMove_0(hiByte, i1, i2, l1, l2)) - jjAddStates(13, 14); + { jjAddStates(18, 19); } break; - case 100: - case 102: + case 105: + case 107: if (jjCanMove_0(hiByte, i1, i2, l1, l2)) - jjCheckNAddStates(15, 17); + { jjCheckNAddStates(20, 22); } break; - case 108: + case 113: if (jjCanMove_0(hiByte, i1, i2, l1, l2)) - jjAddStates(41, 42); + { jjAddStates(49, 50); } break; - case 111: - case 113: + case 116: + case 118: if (jjCanMove_0(hiByte, i1, i2, l1, l2)) - jjCheckNAddStates(18, 20); + { jjCheckNAddStates(23, 25); } break; - default : break; + default : if (i1 == 0 || l1 == 0 || i2 == 0 || l2 == 0) break; else break; } } while(i != startsAt); } @@ -1223,29 +1245,12 @@ else if (curChar == 100) kind = 0x7fffffff; } ++curPos; - if ((i = jjnewStateCnt) == (startsAt = 119 - (jjnewStateCnt = startsAt))) + if ((i = jjnewStateCnt) == (startsAt = 124 - (jjnewStateCnt = startsAt))) return curPos; try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { return curPos; } } } -static final int[] jjnextStates = { - 99, 106, 107, 116, 118, 20, 21, 22, 13, 14, 15, 7, 10, 27, 28, 100, - 101, 104, 111, 112, 115, 93, 97, 68, 74, 78, 84, 89, 59, 63, 51, 54, - 35, 41, 47, 16, 17, 18, 23, 24, 25, 108, 109, -}; -private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2) -{ - switch(hiByte) - { - case 0: - return ((jjbitVec2[i2] & l2) != 0L); - default : - if ((jjbitVec0[i1] & l1) != 0L) - return true; - return false; - } -} /** Token literal values. */ public static final String[] jjstrLiteralImages = { @@ -1254,72 +1259,9 @@ private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, lo "\157\156\145\157\146", "\162\145\160\145\141\164\145\144", "\164\162\141\156\163\151\145\156\164", "\157\160\164\151\157\156", "\145\170\164\145\156\144\163", "\141\142\163\164\162\141\143\164", "\162\145\163\145\162\166\145\144", "\164\157", "\155\141\170", "\164\162\165\145", "\146\141\154\163\145", -"\151\156\164", "\154\157\156\147", "\142\157\157\154\145\141\156", null, null, null, null, -null, null, "\75", "\73", "\173", "\175", "\100", "\50", "\51", "\133", "\54", -"\135", "\74", "\76", "\56", }; - -/** Lexer state names. */ -public static final String[] lexStateNames = { - "DEFAULT", -}; -static final long[] jjtoToken = { - 0x3fff7fffff01L, -}; -static final long[] jjtoSkip = { - 0xfeL, -}; -static final long[] jjtoSpecial = { - 0x80L, -}; -protected SimpleCharStream input_stream; -private final int[] jjrounds = new int[119]; -private final int[] jjstateSet = new int[238]; -protected char curChar; -/** Constructor. */ -public ProtobufParserTokenManager(SimpleCharStream stream){ - if (SimpleCharStream.staticFlag) - throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); - input_stream = stream; -} - -/** Constructor. */ -public ProtobufParserTokenManager(SimpleCharStream stream, int lexState){ - this(stream); - SwitchTo(lexState); -} - -/** Reinitialise parser. */ -public void ReInit(SimpleCharStream stream) -{ - jjmatchedPos = jjnewStateCnt = 0; - curLexState = defaultLexState; - input_stream = stream; - ReInitRounds(); -} -private void ReInitRounds() -{ - int i; - jjround = 0x80000001; - for (i = 119; i-- > 0;) - jjrounds[i] = 0x80000000; -} - -/** Reinitialise parser. */ -public void ReInit(SimpleCharStream stream, int lexState) -{ - ReInit(stream); - SwitchTo(lexState); -} - -/** Switch to specified lex state. */ -public void SwitchTo(int lexState) -{ - if (lexState >= 1 || lexState < 0) - throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); - else - curLexState = lexState; -} - +"\156\165\154\154", "\151\156\164", "\154\157\156\147", "\142\157\157\154\145\141\156", null, null, +null, null, null, null, null, "\75", "\73", "\173", "\175", "\100", "\50", "\51", +"\133", "\54", "\135", "\74", "\76", "\56", }; protected Token jjFillToken() { final Token t; @@ -1343,6 +1285,24 @@ protected Token jjFillToken() return t; } +static final int[] jjnextStates = { + 16, 8, 10, 104, 111, 112, 121, 123, 25, 26, 27, 18, 19, 20, 7, 15, + 12, 13, 32, 33, 105, 106, 109, 116, 117, 120, 98, 102, 73, 79, 83, 89, + 94, 64, 68, 56, 59, 40, 46, 52, 11, 12, 13, 21, 22, 23, 28, 29, + 30, 113, 114, +}; +private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2) +{ + switch(hiByte) + { + case 0: + return ((jjbitVec2[i2] & l2) != 0L); + default : + if ((jjbitVec0[i1] & l1) != 0L) + return true; + return false; + } +} int curLexState = 0; int defaultLexState = 0; @@ -1365,9 +1325,10 @@ public Token getNextToken() { curChar = input_stream.BeginToken(); } - catch(java.io.IOException e) + catch(Exception e) { jjmatchedKind = 0; + jjmatchedPos = -1; matchedToken = jjFillToken(); matchedToken.specialToken = specialToken; return matchedToken; @@ -1430,6 +1391,31 @@ public Token getNextToken() } } +void SkipLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +void MoreLexicalActions() +{ + jjimageLen += (lengthOfMatch = jjmatchedPos + 1); + switch(jjmatchedKind) + { + default : + break; + } +} +void TokenLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} private void jjCheckNAdd(int state) { if (jjrounds[state] != jjround) @@ -1457,4 +1443,90 @@ private void jjCheckNAddStates(int start, int end) } while (start++ != end); } + /** Constructor. */ + public ProtobufParserTokenManager(SimpleCharStream stream){ + + if (SimpleCharStream.staticFlag) + throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); + + input_stream = stream; + } + + /** Constructor. */ + public ProtobufParserTokenManager (SimpleCharStream stream, int lexState){ + ReInit(stream); + SwitchTo(lexState); + } + + /** Reinitialise parser. */ + + public void ReInit(SimpleCharStream stream) + { + + + jjmatchedPos = + jjnewStateCnt = + 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); + } + + private void ReInitRounds() + { + int i; + jjround = 0x80000001; + for (i = 124; i-- > 0;) + jjrounds[i] = 0x80000000; + } + + /** Reinitialise parser. */ + public void ReInit(SimpleCharStream stream, int lexState) + + { + ReInit(stream); + SwitchTo(lexState); + } + + /** Switch to specified lex state. */ + public void SwitchTo(int lexState) + { + if (lexState >= 1 || lexState < 0) + throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); + else + curLexState = lexState; + } + + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", +}; + +/** Lex State array. */ +public static final int[] jjnewLexState = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +}; +static final long[] jjtoToken = { + 0xfffddfffff01L, +}; +static final long[] jjtoSkip = { + 0xfeL, +}; +static final long[] jjtoSpecial = { + 0x80L, +}; +static final long[] jjtoMore = { + 0x0L, +}; + protected SimpleCharStream input_stream; + + private final int[] jjrounds = new int[124]; + private final int[] jjstateSet = new int[2 * 124]; + private final StringBuilder jjimage = new StringBuilder(); + private StringBuilder image = jjimage; + private int jjimageLen; + private int lengthOfMatch; + protected int curChar; } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/SimpleCharStream.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/SimpleCharStream.java index de86c161..9a90db51 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/SimpleCharStream.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/SimpleCharStream.java @@ -1,4 +1,4 @@ -/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 5.0 */ +/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 7.0 */ /* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ package de.haumacher.msgbuf.generator.parser; @@ -30,10 +30,12 @@ public class SimpleCharStream protected char[] buffer; protected int maxNextCharInd = 0; protected int inBuf = 0; - protected int tabSize = 8; + protected int tabSize = 1; + protected boolean trackLineColumn = true; + + public void setTabSize(int i) { tabSize = i; } + public int getTabSize() { return tabSize; } - protected void setTabSize(int i) { tabSize = i; } - protected int getTabSize(int i) { return tabSize; } protected void ExpandBuff(boolean wrapAround) @@ -201,22 +203,20 @@ public char readChar() throws java.io.IOException return c; } - @Deprecated /** * @deprecated * @see #getEndColumn */ - + @Deprecated public int getColumn() { return bufcolumn[bufpos]; } - @Deprecated /** * @deprecated * @see #getEndLine */ - + @Deprecated public int getLine() { return bufline[bufpos]; } @@ -466,6 +466,7 @@ public void adjustBeginLineColumn(int newLine, int newCol) line = bufline[j]; column = bufcolumn[j]; } - + boolean getTrackLineColumn() { return trackLineColumn; } + void setTrackLineColumn(boolean tlc) { trackLineColumn = tlc; } } -/* JavaCC - OriginalChecksum=20450f951b12894781ddaca18154f2a5 (do not edit this line) */ +/* JavaCC - OriginalChecksum=7719aed5156bff06c279316f3c0d5269 (do not edit this line) */ diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/Token.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/Token.java index d193d213..c481891a 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/Token.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/Token.java @@ -1,5 +1,5 @@ -/* Generated By:JavaCC: Do not edit this line. Token.java Version 5.0 */ -/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/* Generated By:JavaCC: Do not edit this line. Token.java Version 7.0 */ +/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COLUMN=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ package de.haumacher.msgbuf.generator.parser; /** @@ -129,4 +129,4 @@ public static Token newToken(int ofKind) } } -/* JavaCC - OriginalChecksum=a208cb97112a96f0d530f078c091d153 (do not edit this line) */ +/* JavaCC - OriginalChecksum=476326b3f9cd0dbecc94d1d9dbfcfb45 (do not edit this line) */ diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/TokenMgrError.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/TokenMgrError.java index c6b76370..dc490e67 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/TokenMgrError.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/TokenMgrError.java @@ -1,8 +1,9 @@ -/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */ +/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 7.0 */ /* JavaCCOptions: */ package de.haumacher.msgbuf.generator.parser; /** Token Manager Error. */ +@SuppressWarnings("all") public class TokenMgrError extends Error { @@ -20,22 +21,22 @@ public class TokenMgrError extends Error /** * Lexical error occurred. */ - static final int LEXICAL_ERROR = 0; + public static final int LEXICAL_ERROR = 0; /** * An attempt was made to create a second instance of a static token manager. */ - static final int STATIC_LEXER_ERROR = 1; + public static final int STATIC_LEXER_ERROR = 1; /** * Tried to change to an invalid lexical state. */ - static final int INVALID_LEXICAL_STATE = 2; + public static final int INVALID_LEXICAL_STATE = 2; /** * Detected (and bailed out of) an infinite loop in the token manager. */ - static final int LOOP_DETECTED = 3; + public static final int LOOP_DETECTED = 3; /** * Indicates the reason why the exception is thrown. It will have @@ -48,13 +49,11 @@ public class TokenMgrError extends Error * equivalents in the given string */ protected static final String addEscapes(String str) { - StringBuffer retval = new StringBuffer(); + StringBuilder retval = new StringBuilder(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { - case 0 : - continue; case '\b': retval.append("\\b"); continue; @@ -97,19 +96,20 @@ protected static final String addEscapes(String str) { * token manager to indicate a lexical error. * Parameters : * EOFSeen : indicates if EOF caused the lexical error - * curLexState : lexical state in which this error occurred + * lexState : lexical state in which this error occurred * errorLine : line number when the error occurred * errorColumn : column number when the error occurred * errorAfter : prefix that was seen before this error occurred * curchar : the offending character * Note: You can customize the lexical error message by modifying this method. */ - protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { - return("Lexical error at line " + - errorLine + ", column " + - errorColumn + ". Encountered: " + - (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + - "after : \"" + addEscapes(errorAfter) + "\""); + protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) { + return("Lexical error at line " + // + errorLine + ", column " + // + errorColumn + ". Encountered: " + // + (EOFSeen ? "" : ("'" + addEscapes(String.valueOf((char) curChar)) + "' (" + curChar + "),")) + // + (errorAfter == null || errorAfter.length() == 0 ? "" : " after prefix \"" + addEscapes(errorAfter) + "\"")) + // + (lexState == 0 ? "" : " (in lexical state " + lexState + ")"); } /** @@ -141,8 +141,8 @@ public TokenMgrError(String message, int reason) { } /** Full Constructor. */ - public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { - this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) { + this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); } } -/* JavaCC - OriginalChecksum=11f535bc78366d999591ad5d062f5010 (do not edit this line) */ +/* JavaCC - OriginalChecksum=c1e49e61881f69efa163e0b0f265a231 (do not edit this line) */ diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/protobuf.jj b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/protobuf.jj index c8830f16..e6c5f3ac 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/protobuf.jj +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/protobuf.jj @@ -12,7 +12,7 @@ options PARSER_BEGIN(ProtobufParser) package de.haumacher.msgbuf.generator.parser; -import de.haumacher.msgbuf.generator.Util; +import de.haumacher.msgbuf.generator.common.Util; import de.haumacher.msgbuf.generator.ast.*; /** @@ -60,6 +60,7 @@ TOKEN : | < MAX : "max" > | < TRUE : "true" > | < FALSE : "false" > +| < NULL : "null" > | < INT_TYPE : "int" > | < LONG_TYPE : "long" > | < BOOLEAN_TYPE : "boolean" > @@ -80,7 +81,8 @@ TOKEN : "string" | "bytes" > -| < NUMBER : ( "-" )? ("0" | ( [ "1"-"9" ] ([ "0"-"9" ])* )) ("." ([ "0"-"9" ])+)? > +| < #INT: ("0" | ( [ "1"-"9" ] ([ "0"-"9" ])* )) > +| < NUMBER : ( "-" )? < INT > ("." ([ "0"-"9" ])+)? (["e", "E"] ( [ "+", "-" ] )? < INT > )? > | < STRING : "'" (~[ "'", "\\" ] | < QUOTE > )* "'" | "\"" (~[ "\"", "\\" ] | < QUOTE > )* "\"" > | < XNAME : "`" (~[ "`" ] )+ "`" > | < #QUOTE : "\\\\" | "\\'" | "\\\"" > @@ -303,7 +305,7 @@ Field field() : Field result = Field.create(); Type type; String name; - Token index; + Token def; Token comment; Option option; Token optionName; @@ -330,9 +332,9 @@ Field field() : result.setName(name); } ( - "=" index=< NUMBER > + "=" (def=< NUMBER > | def=< TRUE > | def=< FALSE > | def=< STRING > | def=< NULL > ) { - result.setIndex(Integer.parseInt(index.image)); + result.setDefaultValue(def.image); } )? partOptions(result) diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/comments/comments.proto b/de.haumacher.msgbuf.generator/src/test/java/test/comments/comments.proto index 15bad00c..733c21c6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/comments/comments.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/comments/comments.proto @@ -6,7 +6,7 @@ package test.comments.data; */ message SearchRequest { /** The query string to interpret */ - string query = 1; + string query; /** * The page of results to return. @@ -17,12 +17,12 @@ message SearchRequest { * * @see #result_per_page */ - int32 page_number = 2; // Which page number do we want? + int32 page_number; // Which page number do we want? /** * The number of results to return at once. * * @see #page_number */ - int32 result_per_page = 3; // Number of results to return per page. + int32 result_per_page; // Number of results to return per page. } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/TestDefaultValue.java b/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/TestDefaultValue.java new file mode 100644 index 00000000..205cf396 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/TestDefaultValue.java @@ -0,0 +1,23 @@ +/* + * SPDX-FileCopyrightText: 2025 (c) Business Operation Systems GmbH + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-BOS-TopLogic-1.0 + */ +package test.defaultvalue; + +import junit.framework.TestCase; +import test.defaultvalue.data.A; + +/** + * Test for annotated default values. + */ +public class TestDefaultValue extends TestCase { + + public void testDefault() { + A a = A.create(); + assertEquals(true, a.isState()); + assertEquals("Hello world!", a.getS()); + assertEquals(13, a.getX()); + assertEquals(-42.13, a.getY()); + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/A.java new file mode 100644 index 00000000..2a43bb25 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/A.java @@ -0,0 +1,94 @@ +package test.defaultvalue.data; + +public interface A extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.defaultvalue.data.A} instance. + */ + static test.defaultvalue.data.A create() { + return new test.defaultvalue.data.impl.A_Impl(); + } + + /** Identifier for the {@link test.defaultvalue.data.A} type in JSON format. */ + String A__TYPE = "A"; + + /** @see #getS() */ + String S__PROP = "s"; + + /** @see #getX() */ + String X__PROP = "x"; + + /** @see #getY() */ + String Y__PROP = "y"; + + /** @see #isState() */ + String STATE__PROP = "state"; + + /** Identifier for the property {@link #getS()} in binary format. */ + static final int S__ID = 1; + + /** Identifier for the property {@link #getX()} in binary format. */ + static final int X__ID = 2; + + /** Identifier for the property {@link #getY()} in binary format. */ + static final int Y__ID = 3; + + /** Identifier for the property {@link #isState()} in binary format. */ + static final int STATE__ID = 4; + + String getS(); + + /** + * @see #getS() + */ + test.defaultvalue.data.A setS(String value); + + int getX(); + + /** + * @see #getX() + */ + test.defaultvalue.data.A setX(int value); + + double getY(); + + /** + * @see #getY() + */ + test.defaultvalue.data.A setY(double value); + + boolean isState(); + + /** + * @see #isState() + */ + test.defaultvalue.data.A setState(boolean value); + + @Override + public test.defaultvalue.data.A registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.defaultvalue.data.A unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.defaultvalue.data.A readA(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.defaultvalue.data.impl.A_Impl result = new test.defaultvalue.data.impl.A_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.defaultvalue.data.A readA(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.defaultvalue.data.A result = test.defaultvalue.data.impl.A_Impl.readA_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static A readA(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.defaultvalue.data.impl.A_Impl.readA_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/defaultvalue.proto b/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/defaultvalue.proto new file mode 100644 index 00000000..e11dbd39 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/defaultvalue.proto @@ -0,0 +1,10 @@ +package test.defaultvalue.data; + +message A { + + string s = "Hello world!"; + int x = 13; + double y = -4213e-2; + bool state = true; + +} \ No newline at end of file diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java new file mode 100644 index 00000000..f71b3841 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java @@ -0,0 +1,359 @@ +package test.defaultvalue.data.impl; + +/** + * Implementation of {@link test.defaultvalue.data.A}. + */ +public class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.defaultvalue.data.A { + + private String _s = "Hello world!"; + + private int _x = 13; + + private double _y = -4213e-2; + + private boolean _state = true; + + /** + * Creates a {@link A_Impl} instance. + * + * @see test.defaultvalue.data.A#create() + */ + public A_Impl() { + super(); + } + + @Override + public final String getS() { + return _s; + } + + @Override + public test.defaultvalue.data.A setS(String value) { + internalSetS(value); + return this; + } + + /** Internal setter for {@link #getS()} without chain call utility. */ + protected final void internalSetS(String value) { + _listener.beforeSet(this, S__PROP, value); + _s = value; + } + + @Override + public final int getX() { + return _x; + } + + @Override + public test.defaultvalue.data.A setX(int value) { + internalSetX(value); + return this; + } + + /** Internal setter for {@link #getX()} without chain call utility. */ + protected final void internalSetX(int value) { + _listener.beforeSet(this, X__PROP, value); + _x = value; + } + + @Override + public final double getY() { + return _y; + } + + @Override + public test.defaultvalue.data.A setY(double value) { + internalSetY(value); + return this; + } + + /** Internal setter for {@link #getY()} without chain call utility. */ + protected final void internalSetY(double value) { + _listener.beforeSet(this, Y__PROP, value); + _y = value; + } + + @Override + public final boolean isState() { + return _state; + } + + @Override + public test.defaultvalue.data.A setState(boolean value) { + internalSetState(value); + return this; + } + + /** Internal setter for {@link #isState()} without chain call utility. */ + protected final void internalSetState(boolean value) { + _listener.beforeSet(this, STATE__PROP, value); + _state = value; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.defaultvalue.data.A registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.defaultvalue.data.A unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return A__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + S__PROP, + X__PROP, + Y__PROP, + STATE__PROP)); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case S__PROP: return getS(); + case X__PROP: return getX(); + case Y__PROP: return getY(); + case STATE__PROP: return isState(); + default: return test.defaultvalue.data.A.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case S__PROP: internalSetS((String) value); break; + case X__PROP: internalSetX((int) value); break; + case Y__PROP: internalSetY((double) value); break; + case STATE__PROP: internalSetState((boolean) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(S__PROP); + out.value(getS()); + out.name(X__PROP); + out.value(getX()); + out.name(Y__PROP); + out.value(getY()); + out.name(STATE__PROP); + out.value(isState()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case S__PROP: setS(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case X__PROP: setX(in.nextInt()); break; + case Y__PROP: setY(in.nextDouble()); break; + case STATE__PROP: setState(in.nextBoolean()); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(S__ID); + out.value(getS()); + out.name(X__ID); + out.value(getX()); + out.name(Y__ID); + out.value(getY()); + out.name(STATE__ID); + out.value(isState()); + } + + /** Helper for creating an object of type {@link test.defaultvalue.data.A} from a polymorphic composition. */ + public static test.defaultvalue.data.A readA_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.defaultvalue.data.impl.A_Impl result = new A_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case S__ID: setS(in.nextString()); break; + case X__ID: setX(in.nextInt()); break; + case Y__ID: setY(in.nextDouble()); break; + case STATE__ID: setState(in.nextBoolean()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.defaultvalue.data.A} type. */ + public static final String A__XML_ELEMENT = "a"; + + /** XML attribute or element name of a {@link #getS} property. */ + private static final String S__XML_ATTR = "s"; + + /** XML attribute or element name of a {@link #getX} property. */ + private static final String X__XML_ATTR = "x"; + + /** XML attribute or element name of a {@link #getY} property. */ + private static final String Y__XML_ATTR = "y"; + + /** XML attribute or element name of a {@link #isState} property. */ + private static final String STATE__XML_ATTR = "state"; + + @Override + public String getXmlTagName() { + return A__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(S__XML_ATTR, getS()); + out.writeAttribute(X__XML_ATTR, Integer.toString(getX())); + out.writeAttribute(Y__XML_ATTR, Double.toString(getY())); + out.writeAttribute(STATE__XML_ATTR, Boolean.toString(isState())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.defaultvalue.data.A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static A_Impl readA_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + A_Impl result = new A_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case S__XML_ATTR: { + setS(value); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(value)); + break; + } + case Y__XML_ATTR: { + setY(Double.parseDouble(value)); + break; + } + case STATE__XML_ATTR: { + setState(Boolean.parseBoolean(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case S__XML_ATTR: { + setS(in.getElementText()); + break; + } + case X__XML_ATTR: { + setX(Integer.parseInt(in.getElementText())); + break; + } + case Y__XML_ATTR: { + setY(Double.parseDouble(in.getElementText())); + break; + } + case STATE__XML_ATTR: { + setState(Boolean.parseBoolean(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/enum.proto b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/enum.proto index 6caeaf5f..bb3e1667 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/enum.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/enum.proto @@ -1,9 +1,10 @@ package test.enumeration.data; message SearchRequest { - string query = 1; - int32 page_number = 2; - int32 result_per_page = 3; + string query; + int32 page_number; + int32 result_per_page; + enum Corpus { UNIVERSAL = 0; WEB = 1; @@ -13,5 +14,6 @@ message SearchRequest { PRODUCTS = 5; VIDEO = 6; } - Corpus corpus = 4; + + Corpus corpus; } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java index bf9db025..f1288a33 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/MyMessage.java @@ -19,10 +19,10 @@ static test.maptype.data.MyMessage create() { String RATING__PROP = "rating"; /** Identifier for the property {@link #getProjects()} in binary format. */ - static final int PROJECTS__ID = 3; + static final int PROJECTS__ID = 1; /** Identifier for the property {@link #getRating()} in binary format. */ - static final int RATING__ID = 4; + static final int RATING__ID = 2; java.util.Map getProjects(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/maptype.proto b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/maptype.proto index c7b4c5bb..b7da7726 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/maptype.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/maptype.proto @@ -6,6 +6,6 @@ message Project { } message MyMessage { - map projects = 3; - map rating = 4; + map projects; + map rating; } \ No newline at end of file diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/nested.proto b/de.haumacher.msgbuf.generator/src/test/java/test/nested/nested.proto index e236d15d..8bbc0ba7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/nested.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/nested.proto @@ -2,11 +2,11 @@ package test.nested.data; message SearchResponse { message Result { - string url = 1; - string title = 2; - repeated string snippets = 3; + string url; + string title; + repeated string snippets; } - repeated Result results = 1; + repeated Result results; } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/types/types.proto b/de.haumacher.msgbuf.generator/src/test/java/test/types/types.proto index 3a52a883..eba698b7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/types/types.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/types/types.proto @@ -3,7 +3,7 @@ syntax = "proto3"; package test.types.data; message SearchRequest { - string query = 1; - int32 page_number = 2; - int32 result_per_page = 3; + string query; + int32 page_number; + int32 result_per_page; } From 006df70268c730207ac13cb29a051efaa16c86d6 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 15 Apr 2025 15:27:51 +0200 Subject: [PATCH 089/207] Bugfix: Must not create overrides for internal derived field setters. --- .../haumacher/msgbuf/generator/MessageGenerator.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index a3945bd3..052aad1c 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -6,7 +6,7 @@ import static de.haumacher.msgbuf.generator.CodeConvention.*; import static de.haumacher.msgbuf.generator.DefaultValueGenerator.*; import static de.haumacher.msgbuf.generator.TypeGenerator.*; -import static de.haumacher.msgbuf.generator.util.CodeUtil.stringLiteral; +import static de.haumacher.msgbuf.generator.util.CodeUtil.*; import java.util.ArrayList; import java.util.List; @@ -650,17 +650,17 @@ private void accessorSetter(Field field, boolean override) { } line(myType() + " " + setterName(field) + "(" + mkTypeReadOnly(field) + " " + "value" + ");"); } - } else { + } else if (!(field.isDerived() && override)) { nl(); - if (!field.isDerived()) { + if (field.isDerived()) { + docComment("Internal setter for updating derived field."); + } else { if (!override && _noInterfaces) { setterDoc(field); } else { // Only in interface for non-derived fields, therefore no override necessary for derived fields. line("@Override"); } - } else { - docComment("Internal setter for updating derived field."); } line(setterModifier(field) + myType() + " " + setterName(field) + "(" + mkTypeReadOnly(field) + " " + "value" + ")" + " {"); { From fca93d98f207ffe8a2fb5d8d17a32f8006098e29 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 16 Apr 2025 16:09:52 +0200 Subject: [PATCH 090/207] Bugfix: Missing qualifier for this in inner class. --- .../java/de/haumacher/msgbuf/generator/MessageGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 052aad1c..30963f2f 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -506,7 +506,7 @@ private void generateFieldMembers() { if (hasContainer) { // Check early to not leave back inconsistent state upon error. line(mkType(container) + " oldContainer = added." + getterName(container) + "();"); - line("if (oldContainer != null && oldContainer != this) {"); + line("if (oldContainer != null && oldContainer != " + implName(_def) + ".this) {"); { line("throw new IllegalStateException(\"Object may not be part of two different containers.\");"); } From 1e0697e94356baca17a36fec0ecd2620dbd578bc Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 16 Apr 2025 16:11:46 +0200 Subject: [PATCH 091/207] Bugfix: Exported missing packages to GWT. --- .../src/main/resources/de/haumacher/msgbuf/MsgBuf.gwt.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/de.haumacher.msgbuf/src/main/resources/de/haumacher/msgbuf/MsgBuf.gwt.xml b/de.haumacher.msgbuf/src/main/resources/de/haumacher/msgbuf/MsgBuf.gwt.xml index 457ef89f..e9d4478e 100644 --- a/de.haumacher.msgbuf/src/main/resources/de/haumacher/msgbuf/MsgBuf.gwt.xml +++ b/de.haumacher.msgbuf/src/main/resources/de/haumacher/msgbuf/MsgBuf.gwt.xml @@ -9,8 +9,11 @@ + + + From 3174f2ad00aa176ed1f633b51fa11c2558b32227 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 16 Apr 2025 16:12:11 +0200 Subject: [PATCH 092/207] GWT compatibility: Dynamic type test is not supported. --- .../java/de/haumacher/msgbuf/util/Conversions.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/Conversions.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/Conversions.java index 4e998abf..7a430816 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/Conversions.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/Conversions.java @@ -24,11 +24,13 @@ public class Conversions { public static List asList(Class type, Object value) { @SuppressWarnings("unchecked") List result = (List) value; - for (T element : result) { - if (element != null && !type.isInstance(element)) { - throw new ClassCastException("Not an instance of '" + type + "': " + element); - } - } + // Note: type.isInstance() is not compatible with GWT. + // +// for (T element : result) { +// if (element != null && !type.isInstance(element)) { +// throw new ClassCastException("Not an instance of '" + type + "': " + element); +// } +// } return result; } From 52c9050db1b614f884076cbdab98bef934967892 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 16 Apr 2025 16:12:53 +0200 Subject: [PATCH 093/207] GWT compatibility: Must not omit type parameters in instantiations. --- .../java/de/haumacher/msgbuf/generator/MessageGenerator.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 30963f2f..51f54b7a 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -491,9 +491,10 @@ private void generateFieldMembers() { "int" : mkTypeWrapped(((MapType) type).getKeyType()); + // Note: Anonymous type construction with omitted type arguments (<>) is not compatible with GWT. String collectionType = isList ? - "de.haumacher.msgbuf.util.ReferenceList" + "<>" : - "de.haumacher.msgbuf.util.ReferenceMap" + "<>"; + "de.haumacher.msgbuf.util.ReferenceList" + "<" + mkTypeWrapped(type) + ">" : + "de.haumacher.msgbuf.util.ReferenceMap" + "<" + mkTypeWrapped(((MapType) field.getType()).getKeyType()) + ", " + mkTypeWrapped(((MapType) type).getValueType()) + ">"; line("private" + mkTransient(field) + mkFinal(field) + " " + mkType(field) + " " + fieldMemberName(field) + " = " + "new " + collectionType + "() {"); { line("@Override"); From 02eb8a5a7b8a5d0170a76a4725e24a26f487fc9d Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 16 Apr 2025 16:13:02 +0200 Subject: [PATCH 094/207] Updated tests. --- .../test/container/model/impl/MyContainer_Impl.java | 8 ++++---- .../java/test/embedded/data/impl/Container_Impl.java | 2 +- .../embedded/data/impl/EmbeddingContainer_Impl.java | 2 +- .../src/test/java/test/graph/data/impl/Group_Impl.java | 2 +- .../test/java/test/hierarchy/data/impl/Group_Impl.java | 2 +- .../java/test/maptype/data/impl/MyMessage_Impl.java | 4 ++-- .../test/nested/data/impl/SearchResponse_Impl.java | 4 ++-- .../src/test/java/test/nointerfaces/Group.java | 2 +- .../src/test/java/test/nojson/impl/Group_Impl.java | 2 +- .../src/test/java/test/notypekind/impl/Group_Impl.java | 2 +- .../src/test/java/test/novisit/impl/Group_Impl.java | 2 +- .../java/test/novisitexceptions/impl/Group_Impl.java | 2 +- .../test/java/test/references/data/impl/A_Impl.java | 10 +++++----- .../test/java/test/references/data/impl/B_Impl.java | 4 ++-- 14 files changed, 24 insertions(+), 24 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java index 5ca4e47e..dcccda44 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java @@ -11,12 +11,12 @@ public class MyContainer_Impl extends de.haumacher.msgbuf.data.AbstractDataObjec private test.container.model.MyContent _content2 = null; - private final java.util.List _contentList = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _contentList = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.container.model.MyContent element) { test.container.model.impl.MyContent_Impl added = (test.container.model.impl.MyContent_Impl) element; test.container.model.MyContainer oldContainer = added.getContainer(); - if (oldContainer != null && oldContainer != this) { + if (oldContainer != null && oldContainer != MyContainer_Impl.this) { throw new IllegalStateException("Object may not be part of two different containers."); } _listener.beforeAdd(MyContainer_Impl.this, CONTENT_LIST__PROP, index, element); @@ -31,12 +31,12 @@ protected void afterRemove(int index, test.container.model.MyContent element) { } }; - private final java.util.Map _contentMap = new de.haumacher.msgbuf.util.ReferenceMap<>() { + private final java.util.Map _contentMap = new de.haumacher.msgbuf.util.ReferenceMap() { @Override protected void beforeAdd(String index, test.container.model.MyContent element) { test.container.model.impl.MyContent_Impl added = (test.container.model.impl.MyContent_Impl) element; test.container.model.MyContainer oldContainer = added.getContainer(); - if (oldContainer != null && oldContainer != this) { + if (oldContainer != null && oldContainer != MyContainer_Impl.this) { throw new IllegalStateException("Object may not be part of two different containers."); } _listener.beforeAdd(MyContainer_Impl.this, CONTENT_MAP__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java index 4f27c6be..81df58cd 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java @@ -7,7 +7,7 @@ public class Container_Impl extends de.haumacher.msgbuf.data.AbstractDataObject private String _name = ""; - private final java.util.List _contents = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _contents = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.embedded.data.Base element) { _listener.beforeAdd(Container_Impl.this, CONTENTS__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java index e17aeff0..c58810a9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java @@ -7,7 +7,7 @@ public class EmbeddingContainer_Impl extends de.haumacher.msgbuf.data.AbstractDa private String _name = ""; - private final java.util.List _contents = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _contents = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.embedded.data.Base element) { _listener.beforeAdd(EmbeddingContainer_Impl.this, CONTENTS__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java index e26a4902..f527814a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java @@ -5,7 +5,7 @@ */ public class Group_Impl extends test.graph.data.impl.Shape_Impl implements test.graph.data.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.graph.data.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java index 2ca07d4a..57ea547f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java @@ -5,7 +5,7 @@ */ public class Group_Impl extends test.hierarchy.data.impl.Shape_Impl implements test.hierarchy.data.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.hierarchy.data.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java index 0c7b1db0..70072be7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java @@ -5,7 +5,7 @@ */ public class MyMessage_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.maptype.data.MyMessage { - private final java.util.Map _projects = new de.haumacher.msgbuf.util.ReferenceMap<>() { + private final java.util.Map _projects = new de.haumacher.msgbuf.util.ReferenceMap() { @Override protected void beforeAdd(String index, test.maptype.data.Project element) { _listener.beforeAdd(MyMessage_Impl.this, PROJECTS__PROP, index, element); @@ -17,7 +17,7 @@ protected void afterRemove(String index, test.maptype.data.Project element) { } }; - private final java.util.Map _rating = new de.haumacher.msgbuf.util.ReferenceMap<>() { + private final java.util.Map _rating = new de.haumacher.msgbuf.util.ReferenceMap() { @Override protected void beforeAdd(Integer index, String element) { _listener.beforeAdd(MyMessage_Impl.this, RATING__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java index 58ef8bfd..c1780688 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java @@ -13,7 +13,7 @@ public static class Result_Impl extends de.haumacher.msgbuf.data.AbstractDataObj private String _title = ""; - private final java.util.List _snippets = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _snippets = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, String element) { _listener.beforeAdd(Result_Impl.this, SNIPPETS__PROP, index, element); @@ -375,7 +375,7 @@ protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream } - private final java.util.List _results = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _results = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.nested.data.SearchResponse.Result element) { _listener.beforeAdd(SearchResponse_Impl.this, RESULTS__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java index 4345e64f..ee469386 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java @@ -24,7 +24,7 @@ public static test.nointerfaces.Group create() { /** Identifier for the property {@link #getShapes()} in binary format. */ static final int SHAPES__ID = 3; - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.nointerfaces.Shape element) { _listener.beforeAdd(Group.this, SHAPES__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java index 9d2c6445..bfc1d551 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java @@ -5,7 +5,7 @@ */ public class Group_Impl extends test.nojson.impl.Shape_Impl implements test.nojson.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.nojson.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java index c0d473b7..b43ceeb8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java @@ -5,7 +5,7 @@ */ public class Group_Impl extends test.notypekind.impl.Shape_Impl implements test.notypekind.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.notypekind.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java index 40a5c421..0e3b7678 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java @@ -5,7 +5,7 @@ */ public class Group_Impl extends test.novisit.impl.Shape_Impl implements test.novisit.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.novisit.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java index 27c2d9a0..20942939 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java @@ -5,7 +5,7 @@ */ public class Group_Impl extends test.novisitexceptions.impl.Shape_Impl implements test.novisitexceptions.Group { - private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.novisitexceptions.Shape element) { _listener.beforeAdd(Group_Impl.this, SHAPES__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java index 5c991081..3e27eba9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java @@ -9,7 +9,7 @@ public class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implemen private test.references.data.A _contents = null; - private final java.util.List _children = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _children = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(A_Impl.this, CHILDREN__PROP, index, element); @@ -21,7 +21,7 @@ protected void afterRemove(int index, test.references.data.A element) { } }; - private final java.util.List _bs = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _bs = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.references.data.B element) { test.references.data.impl.B_Impl added = (test.references.data.impl.B_Impl) element; @@ -41,7 +41,7 @@ protected void afterRemove(int index, test.references.data.B element) { private test.references.data.A _other = null; - private final java.util.List _others = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _others = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.references.data.A element) { test.references.data.impl.A_Impl added = (test.references.data.impl.A_Impl) element; @@ -57,7 +57,7 @@ protected void afterRemove(int index, test.references.data.A element) { } }; - private final java.util.List _inOther = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _inOther = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(A_Impl.this, IN_OTHER__PROP, index, element); @@ -69,7 +69,7 @@ protected void afterRemove(int index, test.references.data.A element) { } }; - private final java.util.List _inOthers = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _inOthers = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(A_Impl.this, IN_OTHERS__PROP, index, element); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java index 23105251..aa86ecd5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java @@ -7,7 +7,7 @@ public class B_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implemen private String _name = ""; - private final java.util.List _inBs = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _inBs = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(B_Impl.this, IN_BS__PROP, index, element); @@ -19,7 +19,7 @@ protected void afterRemove(int index, test.references.data.A element) { } }; - private final java.util.List _inB = new de.haumacher.msgbuf.util.ReferenceList<>() { + private final java.util.List _inB = new de.haumacher.msgbuf.util.ReferenceList() { @Override protected void beforeAdd(int index, test.references.data.A element) { _listener.beforeAdd(B_Impl.this, IN_B__PROP, index, element); From aa9b70fc162d6fcfba42b6db43256cb8d00b8d09 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 22 Apr 2025 12:15:20 +0200 Subject: [PATCH 095/207] Allow to access dirty nodes and allow to be informed about first change. --- .../haumacher/msgbuf/graph/DefaultScope.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java index baee84c8..89cf8732 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java @@ -4,10 +4,12 @@ package de.haumacher.msgbuf.graph; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.function.Function; import de.haumacher.msgbuf.graph.cmd.Command; @@ -162,6 +164,13 @@ public boolean hasChanges() { public void dropChanges() { _changes.clear(); } + + /** + * The set of nodes updated after the last sync. + */ + public Set getDirty() { + return Collections.unmodifiableSet(_changes.keySet()); + } /** * Exports recorded changes to the given {@link JsonWriter}. @@ -323,9 +332,23 @@ private void foreachCommand(Transmission fun) throws IOException { } private Map changes(SharedGraphNode obj) { + if (!_changes.isEmpty()) { + beforeChange(); + } return _changes.computeIfAbsent(obj, NEW_MAP); } + /** + * Hook called before the first change is recorded. + * + *

+ * The method is only called once during two synchronization cycles. + *

+ */ + protected void beforeChange() { + // Hook for subclasses. + } + @Override public int id(SharedGraphNode node) { return ((AbstractSharedGraphNode) node).id(); From 89b77087281e25642a3abe244583fafa12cfd562 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 22 Apr 2025 16:32:11 +0200 Subject: [PATCH 096/207] Fixed endless reading from StringR. --- .../src/main/java/de/haumacher/msgbuf/io/StringR.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/io/StringR.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/io/StringR.java index 913bbf19..7d5cf1dc 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/io/StringR.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/io/StringR.java @@ -23,11 +23,19 @@ public StringR(String in) { @Override public int read() throws IOException { + if (_in.length() == _pos) { + // Finished. + return -1; + } return _in.charAt(_pos++); } @Override public int read(char[] cbuf, int off, int len) throws IOException { + if (_in.length() == _pos) { + // Finished. + return -1; + } int count = Math.min(len, _in.length() - _pos); int end = _pos + count; _in.getChars(_pos, end, cbuf, off); From cb2a95b038fced489d111aea61444bbf480e31f1 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 22 Apr 2025 17:05:16 +0200 Subject: [PATCH 097/207] Bugfix: Do not create updates for transient object in graph sync. --- .../msgbuf/generator/MessageGenerator.java | 34 +++++++++++++++++++ .../data/impl/SearchRequest_Impl.java | 9 +++++ .../model/impl/MyContainer_Impl.java | 9 +++++ .../container/model/impl/MyContent_Impl.java | 9 +++++ .../test/defaultvalue/data/impl/A_Impl.java | 9 +++++ .../embedded/data/impl/Container_Impl.java | 9 +++++ .../data/impl/EmbeddingContainer_Impl.java | 9 +++++ .../impl/EmbeddingSingleContainer_Impl.java | 9 +++++ .../data/impl/SingleContainer_Impl.java | 9 +++++ .../data/impl/SearchRequest_Impl.java | 9 +++++ .../java/test/graph/data/impl/Car_Impl.java | 9 +++++ .../test/graph/data/impl/Circle_Impl.java | 9 +++++ .../java/test/graph/data/impl/Group_Impl.java | 9 +++++ .../test/graph/data/impl/Rectangle_Impl.java | 9 +++++ .../java/test/graph/data/impl/Shape_Impl.java | 9 +++++ .../test/graph/data/impl/SimpleType_Impl.java | 9 +++++ .../test/hierarchy/data/impl/Car_Impl.java | 9 +++++ .../test/hierarchy/data/impl/Circle_Impl.java | 9 +++++ .../test/hierarchy/data/impl/Group_Impl.java | 9 +++++ .../hierarchy/data/impl/Optional_Impl.java | 9 +++++ .../hierarchy/data/impl/Rectangle_Impl.java | 9 +++++ .../test/hierarchy/data/impl/Shape_Impl.java | 9 +++++ .../hierarchy/data/impl/SimpleType_Impl.java | 9 +++++ .../java/test/innertypeclash/impl/A_Impl.java | 9 +++++ .../java/test/innertypeclash/impl/B_Impl.java | 9 +++++ .../test/lowercasemessage/impl/A_Impl.java | 18 ++++++++++ .../maptype/data/impl/MyMessage_Impl.java | 9 +++++ .../test/maptype/data/impl/Project_Impl.java | 9 +++++ .../nested/data/impl/SearchResponse_Impl.java | 18 ++++++++++ .../src/test/java/test/nointerfaces/Car.java | 9 +++++ .../test/java/test/nointerfaces/Circle.java | 9 +++++ .../test/java/test/nointerfaces/Group.java | 9 +++++ .../java/test/nointerfaces/Rectangle.java | 9 +++++ .../test/java/test/nointerfaces/Shape.java | 9 +++++ .../java/test/nointerfaces/SimpleType.java | 9 +++++ .../test/java/test/nojson/impl/Car_Impl.java | 9 +++++ .../java/test/nojson/impl/Circle_Impl.java | 9 +++++ .../java/test/nojson/impl/Group_Impl.java | 9 +++++ .../java/test/nojson/impl/Rectangle_Impl.java | 9 +++++ .../java/test/nojson/impl/Shape_Impl.java | 9 +++++ .../test/nojson/impl/SimpleType_Impl.java | 9 +++++ .../java/test/nolistener/impl/Car_Impl.java | 9 +++++ .../test/nolistener/impl/Circle_Impl.java | 9 +++++ .../java/test/nolistener/impl/Group_Impl.java | 9 +++++ .../test/nolistener/impl/Rectangle_Impl.java | 9 +++++ .../java/test/nolistener/impl/Shape_Impl.java | 9 +++++ .../test/nolistener/impl/SimpleType_Impl.java | 9 +++++ .../java/test/notypekind/impl/Car_Impl.java | 9 +++++ .../test/notypekind/impl/Circle_Impl.java | 9 +++++ .../java/test/notypekind/impl/Group_Impl.java | 9 +++++ .../test/notypekind/impl/Rectangle_Impl.java | 9 +++++ .../java/test/notypekind/impl/Shape_Impl.java | 9 +++++ .../test/notypekind/impl/SimpleType_Impl.java | 9 +++++ .../test/java/test/novisit/impl/Car_Impl.java | 9 +++++ .../java/test/novisit/impl/Circle_Impl.java | 9 +++++ .../java/test/novisit/impl/Group_Impl.java | 9 +++++ .../test/novisit/impl/Rectangle_Impl.java | 9 +++++ .../java/test/novisit/impl/Shape_Impl.java | 9 +++++ .../test/novisit/impl/SimpleType_Impl.java | 9 +++++ .../test/novisitexceptions/impl/Car_Impl.java | 9 +++++ .../novisitexceptions/impl/Circle_Impl.java | 9 +++++ .../novisitexceptions/impl/Group_Impl.java | 9 +++++ .../impl/Rectangle_Impl.java | 9 +++++ .../novisitexceptions/impl/Shape_Impl.java | 9 +++++ .../impl/SimpleType_Impl.java | 9 +++++ .../data/impl/NullableValues_Impl.java | 9 +++++ .../test/references/data/impl/A_Impl.java | 9 +++++ .../test/references/data/impl/B_Impl.java | 9 +++++ .../types/data/impl/SearchRequest_Impl.java | 9 +++++ .../impl/AnnotatedMessage_Impl.java | 9 +++++ .../underscorename/impl/SomeName_Impl.java | 9 +++++ .../msgbuf/data/ReflectiveDataObject.java | 8 +++++ .../haumacher/msgbuf/graph/DefaultScope.java | 6 ++-- 73 files changed, 693 insertions(+), 3 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 51f54b7a..43f0ef4a 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -1113,6 +1113,32 @@ private void reflectionPropertiesConstant() { nl(); } } + + nl(); + line("private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>("); + { + line("java.util.Arrays.asList("); + { + boolean first = true; + for (Field field : getFields()) { + if (!field.isTransient()) { + continue; + } + if (first) { + first = false; + } else { + append(", "); + nl(); + } + lineStart(constant(field)); + } + if (first) { + lineStart(""); + } + append(")));"); + nl(); + } + } } private void reflectionProperties() { @@ -1123,6 +1149,14 @@ private void reflectionProperties() { line("return PROPERTIES;"); } line("}"); + + nl(); + line("@Override"); + line("public java.util.Set transientProperties() {"); + { + line("return TRANSIENT_PROPERTIES;"); + } + line("}"); } private void reflectionGet() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java index 8ff30fde..9fda2385 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java @@ -104,11 +104,20 @@ public String jsonType() { PAGE_NUMBER__PROP, RESULT_PER_PAGE__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java index dcccda44..615405b6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java @@ -255,11 +255,20 @@ public String jsonType() { CONTENT_LIST__PROP, CONTENT_MAP__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java index 7c55a4ca..4df6adb3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java @@ -94,11 +94,20 @@ public String jsonType() { CONTAINER__PROP, NAME__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java index f71b3841..375d1b5b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java @@ -124,11 +124,20 @@ public String jsonType() { Y__PROP, STATE__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java index 81df58cd..d2acddb9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java @@ -111,11 +111,20 @@ public String jsonType() { NAME__PROP, CONTENTS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java index c58810a9..ad6d1893 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java @@ -111,11 +111,20 @@ public String jsonType() { NAME__PROP, CONTENTS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java index 355e5597..d6802f8d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java @@ -89,11 +89,20 @@ public String jsonType() { NAME__PROP, CONTENTS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java index 5653c518..3dc3ea13 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java @@ -89,11 +89,20 @@ public String jsonType() { NAME__PROP, CONTENTS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java index 01cb4fdf..86034f28 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java @@ -125,11 +125,20 @@ public String jsonType() { RESULT_PER_PAGE__PROP, CORPUS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java index 258da6e5..df76f87f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java @@ -114,11 +114,20 @@ public String jsonType() { WHEEL_2__PROP, BODY__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java index 6918ec51..b4c20f19 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java @@ -59,11 +59,20 @@ public String jsonType() { java.util.Arrays.asList( RADIUS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java index f527814a..f08f4649 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java @@ -86,11 +86,20 @@ public String jsonType() { java.util.Arrays.asList( SHAPES__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java index 1d99f42c..2010f704 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java @@ -79,11 +79,20 @@ public String jsonType() { WIDTH__PROP, HEIGHT__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java index e935d6bc..136ccab7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java @@ -55,11 +55,20 @@ protected final void internalSetYCoordinate(int value) { X_COORDINATE__PROP, Y_COORDINATE__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java index 951a448b..615d71a7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java @@ -62,11 +62,20 @@ public String jsonType() { STR__PROP, X__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java index 060dd5ea..74c25c2c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java @@ -120,11 +120,20 @@ public String jsonType() { WHEEL_2__PROP, BODY__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java index e41d7173..da67ba84 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java @@ -65,11 +65,20 @@ public String jsonType() { java.util.Arrays.asList( RADIUS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java index 57ea547f..e31460cd 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java @@ -92,11 +92,20 @@ public String jsonType() { java.util.Arrays.asList( SHAPES__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java index 7e76fd18..d0bc549f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java @@ -90,11 +90,20 @@ public String jsonType() { HIDDEN__PROP, SHAPE__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java index b303d09f..5a366ff4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java @@ -85,11 +85,20 @@ public String jsonType() { WIDTH__PROP, HEIGHT__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java index 9537b535..b5504434 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java @@ -98,11 +98,20 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis Y_COORDINATE__PROP, COLOR__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java index e59706a0..91e75555 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java @@ -84,11 +84,20 @@ public String jsonType() { STR__PROP, X__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java index c9c5977d..80734f48 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java @@ -284,11 +284,20 @@ public String jsonType() { BC__PROP, C__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java index f5f1d80b..ffa2d4d5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java @@ -284,11 +284,20 @@ public String jsonType() { BC__PROP, C__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java index 5b3c981e..bb788e97 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java @@ -98,11 +98,20 @@ public String jsonType() { A_1__PROP, B_1__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { @@ -388,11 +397,20 @@ public String jsonType() { A_1__PROP, B_1__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java index 70072be7..9ff46ae6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java @@ -144,11 +144,20 @@ public String jsonType() { PROJECTS__PROP, RATING__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java index c8030451..35cbe943 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java @@ -84,11 +84,20 @@ public String jsonType() { NAME__PROP, COST__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java index c1780688..c6ec715f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java @@ -134,11 +134,20 @@ public String jsonType() { TITLE__PROP, SNIPPETS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { @@ -461,11 +470,20 @@ public String jsonType() { java.util.Arrays.asList( RESULTS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java index dd7d592d..58fba6d9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java @@ -163,11 +163,20 @@ public String jsonType() { WHEEL_2__PROP, BODY__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java index bbe02d5d..6e221c6d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java @@ -82,11 +82,20 @@ public String jsonType() { java.util.Arrays.asList( RADIUS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java index ee469386..f56b90ec 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java @@ -117,11 +117,20 @@ public String jsonType() { java.util.Arrays.asList( SHAPES__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java index 39586643..bdb69f94 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java @@ -120,11 +120,20 @@ public String jsonType() { WIDTH__PROP, HEIGHT__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java index 512a6abc..aca9e971 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java @@ -129,11 +129,20 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis X_COORDINATE__PROP, Y_COORDINATE__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java index 00014c9e..30fa9f04 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java @@ -114,11 +114,20 @@ public String jsonType() { STR__PROP, X__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java index bb0cdb5a..484a4ca2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java @@ -114,11 +114,20 @@ public String jsonType() { WHEEL_2__PROP, BODY__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java index c25d63e1..97ced9b2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java @@ -59,11 +59,20 @@ public String jsonType() { java.util.Arrays.asList( RADIUS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java index bfc1d551..9cb81526 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java @@ -86,11 +86,20 @@ public String jsonType() { java.util.Arrays.asList( SHAPES__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java index 6e36f515..51c03ae5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java @@ -79,11 +79,20 @@ public String jsonType() { WIDTH__PROP, HEIGHT__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java index 4e92eef9..bc999dd4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java @@ -77,11 +77,20 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis X_COORDINATE__PROP, Y_COORDINATE__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java index b2a8596c..413ce01b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java @@ -84,11 +84,20 @@ public String jsonType() { STR__PROP, X__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Car_Impl.java index 82bf9712..fe4ececb 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Car_Impl.java @@ -111,11 +111,20 @@ public String jsonType() { WHEEL_2__PROP, BODY__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Circle_Impl.java index 4edad803..de2957f3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Circle_Impl.java @@ -58,11 +58,20 @@ public String jsonType() { java.util.Arrays.asList( RADIUS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java index 6f93b8d5..08b8ead4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java @@ -76,11 +76,20 @@ public String jsonType() { java.util.Arrays.asList( SHAPES__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Rectangle_Impl.java index e4218684..69314f90 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Rectangle_Impl.java @@ -77,11 +77,20 @@ public String jsonType() { WIDTH__PROP, HEIGHT__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java index 96fba590..35904cad 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java @@ -53,11 +53,20 @@ protected final void internalSetYCoordinate(int value) { X_COORDINATE__PROP, Y_COORDINATE__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/SimpleType_Impl.java index 2d0c67ae..6e3201d5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/SimpleType_Impl.java @@ -60,11 +60,20 @@ public String jsonType() { STR__PROP, X__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java index 5c724d94..f76a304e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java @@ -109,11 +109,20 @@ public String jsonType() { WHEEL_2__PROP, BODY__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java index d94b638e..d4960c65 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java @@ -54,11 +54,20 @@ public String jsonType() { java.util.Arrays.asList( RADIUS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java index b43ceeb8..37f3ef66 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java @@ -81,11 +81,20 @@ public String jsonType() { java.util.Arrays.asList( SHAPES__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java index b91e1f53..822b11f4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java @@ -74,11 +74,20 @@ public String jsonType() { WIDTH__PROP, HEIGHT__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java index 6d7017eb..0d7500ed 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java @@ -77,11 +77,20 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis X_COORDINATE__PROP, Y_COORDINATE__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java index 0b17e2d3..b1c3d7ae 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java @@ -84,11 +84,20 @@ public String jsonType() { STR__PROP, X__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java index a75dde94..ecedb3d5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java @@ -114,11 +114,20 @@ public String jsonType() { WHEEL_2__PROP, BODY__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java index 561e4718..78303126 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java @@ -59,11 +59,20 @@ public String jsonType() { java.util.Arrays.asList( RADIUS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java index 0e3b7678..4fbc0ca4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java @@ -86,11 +86,20 @@ public String jsonType() { java.util.Arrays.asList( SHAPES__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java index 740ddbcc..6b12557b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java @@ -79,11 +79,20 @@ public String jsonType() { WIDTH__PROP, HEIGHT__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java index fcc69830..003dc0ab 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java @@ -77,11 +77,20 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis X_COORDINATE__PROP, Y_COORDINATE__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java index 9c9c2e3f..34c0b454 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java @@ -84,11 +84,20 @@ public String jsonType() { STR__PROP, X__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java index add66c47..6f74ff1e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java @@ -114,11 +114,20 @@ public String jsonType() { WHEEL_2__PROP, BODY__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java index a2dd570d..5fe6fe37 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java @@ -59,11 +59,20 @@ public String jsonType() { java.util.Arrays.asList( RADIUS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java index 20942939..083b2d86 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java @@ -86,11 +86,20 @@ public String jsonType() { java.util.Arrays.asList( SHAPES__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java index f6563794..b4cd7e30 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java @@ -79,11 +79,20 @@ public String jsonType() { WIDTH__PROP, HEIGHT__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java index d87d179e..a551318a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java @@ -77,11 +77,20 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis X_COORDINATE__PROP, Y_COORDINATE__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java index a564adb2..32a25617 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java @@ -84,11 +84,20 @@ public String jsonType() { STR__PROP, X__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java index 134d30c2..4579e16c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java @@ -277,11 +277,20 @@ public String jsonType() { STRING_INT_MAP__PROP, OPTIONAL_DECISION__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java index 3e27eba9..dbdd9ca2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java @@ -398,11 +398,20 @@ public String jsonType() { IN_OTHER__PROP, IN_OTHERS__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java index aa86ecd5..8fb21331 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java @@ -158,11 +158,20 @@ public String jsonType() { IN_BS__PROP, IN_B__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java index fb01178a..8577ff30 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java @@ -104,11 +104,20 @@ public String jsonType() { PAGE_NUMBER__PROP, RESULT_PER_PAGE__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java index 9fe37b1a..b6fa745a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java @@ -47,11 +47,20 @@ public String jsonType() { java.util.Arrays.asList( ANNOTATED_FIELD__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java index 55091833..c9b4aeea 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java @@ -47,11 +47,20 @@ public String jsonType() { java.util.Arrays.asList( MY_FIELD__PROP)); + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + @Override public java.util.List properties() { return PROPERTIES; } + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + @Override public Object get(String field) { switch (field) { diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/data/ReflectiveDataObject.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/data/ReflectiveDataObject.java index 76885fde..58af56b8 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/data/ReflectiveDataObject.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/data/ReflectiveDataObject.java @@ -5,6 +5,7 @@ import java.util.Collections; import java.util.List; +import java.util.Set; /** * An object with generically accessible properties. @@ -25,6 +26,13 @@ default List properties() { return Collections.emptyList(); } + /** + * All {@link #properties()} that are marked transient. + */ + default Set transientProperties() { + return Collections.emptySet(); + } + /** * Retrieves value of the field with the given name. * diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java index 89cf8732..b5645b73 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java @@ -84,7 +84,7 @@ public static DefaultScope newClientInstance() { @Override public void beforeSet(Observable obj, String property, Object value) { - if (_applying) { + if (_applying || obj.transientProperties().contains(property)) { return; } AbstractSharedGraphNode node = (AbstractSharedGraphNode) obj; @@ -93,7 +93,7 @@ public void beforeSet(Observable obj, String property, Object value) { @Override public void beforeAdd(Observable obj, String property, int index, Object element) { - if (_applying) { + if (_applying || obj.transientProperties().contains(property)) { return; } AbstractSharedGraphNode node = (AbstractSharedGraphNode) obj; @@ -106,7 +106,7 @@ public void beforeAdd(Observable obj, String property, int index, Object element @Override public void afterRemove(Observable obj, String property, int index, Object element) { - if (_applying) { + if (_applying || obj.transientProperties().contains(property)) { return; } AbstractSharedGraphNode node = (AbstractSharedGraphNode) obj; From 10b83bfc5650ed52bbb9595324a0db5a0bac4d3e Mon Sep 17 00:00:00 2001 From: Daniel Busche Date: Wed, 23 Apr 2025 10:47:08 +0200 Subject: [PATCH 098/207] Use impl type only when interfaces are used. --- .../msgbuf/generator/MessageGenerator.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 43f0ef4a..3b10d768 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -501,7 +501,11 @@ private void generateFieldMembers() { line("protected void beforeAdd(" + keyType + " " + "index" + ", " + contentTypeWrapped + " element) {"); { if (hasContainer || hasReverseEnd) { - line(contentTypeImpl + " added = (" + contentTypeImpl + ") element;"); + if (_noInterfaces) { + line(contentTypeWrapped + " added = element;"); + } else { + line(contentTypeImpl + " added = (" + contentTypeImpl + ") element;"); + } } if (hasContainer) { @@ -533,7 +537,11 @@ private void generateFieldMembers() { line("protected void afterRemove(" + keyType + " " + "index" + ", " + contentTypeWrapped + " element) {"); { if (hasContainer || hasReverseEnd) { - line(contentTypeImpl + " removed = (" + contentTypeImpl + ") element;"); + if (_noInterfaces) { + line(contentTypeWrapped + " removed = element;"); + } else { + line(contentTypeImpl + " removed = (" + contentTypeImpl + ") element;"); + } } if (hasReverseEnd) { @@ -703,8 +711,13 @@ private void accessorSetterImpl(Field field) { boolean hasContainer = container != null; if (hasContainer || hasReverseEnd) { - line(mkTypeWrappedImpl(type) + " before = (" + mkTypeWrappedImpl(type) + ") " + fieldMemberName(field) +";"); - line(mkTypeWrappedImpl(type) + " after = (" + mkTypeWrappedImpl(type) + ") value;"); + if (_noInterfaces) { + line(mkTypeWrapped(type) + " before = " + fieldMemberName(field) +";"); + line(mkTypeWrapped(type) + " after = value;"); + } else { + line(mkTypeWrappedImpl(type) + " before = (" + mkTypeWrappedImpl(type) + ") " + fieldMemberName(field) +";"); + line(mkTypeWrappedImpl(type) + " after = (" + mkTypeWrappedImpl(type) + ") value;"); + } } if (hasContainer) { From 56699a7741dc86b092be5be8060103f1410d4826 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 23 Apr 2025 13:30:09 +0200 Subject: [PATCH 099/207] Added test case for @Ref. --- .../java/test/container/TestContainer.java | 11 ++ .../test/container/model/MyContainer.java | 41 +++++ .../java/test/container/model/container.proto | 6 + .../model/impl/MyContainer_Impl.java | 156 +++++++++++++++++- 4 files changed, 213 insertions(+), 1 deletion(-) diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java index e83c6c50..b2b122b1 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java @@ -177,5 +177,16 @@ public void testUpdateIdentical() { assertEquals(container, c.getContainer()); assertEquals(c, container.getContent1()); } + + public void testUpdateRef() { + MyContent c = MyContent.create().setName("c"); + MyContainer container = MyContainer.create().setOther(c).addOthers(c); + + assertEquals(c, container.getOther()); + assertNull(c.getContainer()); + + container.setContent1(c); + assertEquals(container, c.getContainer()); + } } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContainer.java index d08efca4..9f637dfb 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContainer.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/MyContainer.java @@ -27,6 +27,12 @@ static test.container.model.MyContainer create() { /** @see #getContentMap() */ String CONTENT_MAP__PROP = "contentMap"; + /** @see #getOther() */ + String OTHER__PROP = "other"; + + /** @see #getOthers() */ + String OTHERS__PROP = "others"; + /** Identifier for the property {@link #getName()} in binary format. */ static final int NAME__ID = 1; @@ -42,6 +48,12 @@ static test.container.model.MyContainer create() { /** Identifier for the property {@link #getContentMap()} in binary format. */ static final int CONTENT_MAP__ID = 5; + /** Identifier for the property {@link #getOther()} in binary format. */ + static final int OTHER__ID = 6; + + /** Identifier for the property {@link #getOthers()} in binary format. */ + static final int OTHERS__ID = 7; + String getName(); /** @@ -107,6 +119,35 @@ static test.container.model.MyContainer create() { */ void removeContentMap(String key); + test.container.model.MyContent getOther(); + + /** + * @see #getOther() + */ + test.container.model.MyContainer setOther(test.container.model.MyContent value); + + /** + * Checks, whether {@link #getOther()} has a value. + */ + boolean hasOther(); + + java.util.List getOthers(); + + /** + * @see #getOthers() + */ + test.container.model.MyContainer setOthers(java.util.List value); + + /** + * Adds a value to the {@link #getOthers()} list. + */ + test.container.model.MyContainer addOthers(test.container.model.MyContent value); + + /** + * Removes a value from the {@link #getOthers()} list. + */ + void removeOthers(test.container.model.MyContent value); + @Override public test.container.model.MyContainer registerListener(de.haumacher.msgbuf.observer.Listener l); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/container.proto b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/container.proto index bace4cee..75a2e069 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/container.proto +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/container.proto @@ -8,6 +8,12 @@ message MyContainer { repeated MyContent contentList; map contentMap; + + @Ref + MyContent other; + + @Ref + repeated MyContent others; } message MyContent { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java index 615405b6..9a33d645 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java @@ -51,6 +51,20 @@ protected void afterRemove(String index, test.container.model.MyContent element) } }; + private test.container.model.MyContent _other = null; + + private final java.util.List _others = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.container.model.MyContent element) { + _listener.beforeAdd(MyContainer_Impl.this, OTHERS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.container.model.MyContent element) { + _listener.afterRemove(MyContainer_Impl.this, OTHERS__PROP, index, element); + } + }; + /** * Creates a {@link MyContainer_Impl} instance. * @@ -220,6 +234,62 @@ public final void removeContentMap(String key) { _contentMap.remove(key); } + @Override + public final test.container.model.MyContent getOther() { + return _other; + } + + @Override + public test.container.model.MyContainer setOther(test.container.model.MyContent value) { + internalSetOther(value); + return this; + } + + /** Internal setter for {@link #getOther()} without chain call utility. */ + protected final void internalSetOther(test.container.model.MyContent value) { + _listener.beforeSet(this, OTHER__PROP, value); + _other = value; + } + + @Override + public final boolean hasOther() { + return _other != null; + } + + @Override + public final java.util.List getOthers() { + return _others; + } + + @Override + public test.container.model.MyContainer setOthers(java.util.List value) { + internalSetOthers(value); + return this; + } + + /** Internal setter for {@link #getOthers()} without chain call utility. */ + protected final void internalSetOthers(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'others' cannot be null."); + _others.clear(); + _others.addAll(value); + } + + @Override + public test.container.model.MyContainer addOthers(test.container.model.MyContent value) { + internalAddOthers(value); + return this; + } + + /** Implementation of {@link #addOthers(test.container.model.MyContent)} without chain call utility. */ + protected final void internalAddOthers(test.container.model.MyContent value) { + _others.add(value); + } + + @Override + public final void removeOthers(test.container.model.MyContent value) { + _others.remove(value); + } + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; @Override @@ -253,7 +323,9 @@ public String jsonType() { CONTENT_1__PROP, CONTENT_2__PROP, CONTENT_LIST__PROP, - CONTENT_MAP__PROP)); + CONTENT_MAP__PROP, + OTHER__PROP, + OTHERS__PROP)); private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( java.util.Arrays.asList( @@ -277,6 +349,8 @@ public Object get(String field) { case CONTENT_2__PROP: return getContent2(); case CONTENT_LIST__PROP: return getContentList(); case CONTENT_MAP__PROP: return getContentMap(); + case OTHER__PROP: return getOther(); + case OTHERS__PROP: return getOthers(); default: return test.container.model.MyContainer.super.get(field); } } @@ -289,6 +363,8 @@ public void set(String field, Object value) { case CONTENT_2__PROP: internalSetContent2((test.container.model.MyContent) value); break; case CONTENT_LIST__PROP: internalSetContentList(de.haumacher.msgbuf.util.Conversions.asList(test.container.model.MyContent.class, value)); break; case CONTENT_MAP__PROP: internalSetContentMap((java.util.Map) value); break; + case OTHER__PROP: internalSetOther((test.container.model.MyContent) value); break; + case OTHERS__PROP: internalSetOthers(de.haumacher.msgbuf.util.Conversions.asList(test.container.model.MyContent.class, value)); break; } } @@ -323,6 +399,16 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. entry.getValue().writeTo(out); } out.endObject(); + if (hasOther()) { + out.name(OTHER__PROP); + getOther().writeTo(out); + } + out.name(OTHERS__PROP); + out.beginArray(); + for (test.container.model.MyContent x : getOthers()) { + x.writeTo(out); + } + out.endArray(); } @Override @@ -351,6 +437,17 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t setContentMap(newValue); break; } + case OTHER__PROP: setOther(test.container.model.MyContent.readMyContent(in)); break; + case OTHERS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.container.model.MyContent.readMyContent(in)); + } + in.endArray(); + setOthers(newValue); + } + break; default: super.readField(in, field); } } @@ -390,6 +487,19 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.endArray(); } out.name(CONTENT_MAP__ID); + if (hasOther()) { + out.name(OTHER__ID); + getOther().writeTo(out); + } + out.name(OTHERS__ID); + { + java.util.List values = getOthers(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.container.model.MyContent x : values) { + x.writeTo(out); + } + out.endArray(); + } } /** Helper for creating an object of type {@link test.container.model.MyContainer} from a polymorphic composition. */ @@ -440,6 +550,15 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th in.endArray(); break; } + case OTHER__ID: setOther(test.container.model.MyContent.readMyContent(in)); break; + case OTHERS__ID: { + in.beginArray(); + while (in.hasNext()) { + addOthers(test.container.model.MyContent.readMyContent(in)); + } + in.endArray(); + } + break; default: in.skipValue(); } } @@ -462,6 +581,12 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getContentMap} property. */ private static final String CONTENT_MAP__XML_ATTR = "content-map"; + /** XML attribute or element name of a {@link #getOther} property. */ + private static final String OTHER__XML_ATTR = "other"; + + /** XML attribute or element name of a {@link #getOthers} property. */ + private static final String OTHERS__XML_ATTR = "others"; + @Override public String getXmlTagName() { return MY_CONTAINER__XML_ELEMENT; @@ -495,6 +620,16 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. element.writeTo(out); } out.writeEndElement(); + if (hasOther()) { + out.writeStartElement(OTHER__XML_ATTR); + getOther().writeContent(out); + out.writeEndElement(); + } + out.writeStartElement(OTHERS__XML_ATTR); + for (test.container.model.MyContent element : getOthers()) { + element.writeTo(out); + } + out.writeEndElement(); } /** Creates a new {@link test.container.model.MyContainer} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ @@ -556,6 +691,14 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l internalReadContentListListXml(in); break; } + case OTHER__XML_ATTR: { + setOther(test.container.model.impl.MyContent_Impl.readMyContent_XmlContent(in)); + break; + } + case OTHERS__XML_ATTR: { + internalReadOthersListXml(in); + break; + } default: { internalSkipUntilMatchingEndElement(in); } @@ -583,4 +726,15 @@ private void internalReadContentListListXml(javax.xml.stream.XMLStreamReader in) } } + private void internalReadOthersListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addOthers(test.container.model.impl.MyContent_Impl.readMyContent_XmlContent(in)); + } + } + } From f6f8f92fe07e79859cdfe2f27210b44cec5ac99a Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 23 Apr 2025 15:03:00 +0200 Subject: [PATCH 100/207] Added test case for container without interfaces. --- .../container/nointerfaces/TestContainer.java | 192 ++++ .../nointerfaces/model/MyContainer.java | 835 ++++++++++++++++++ .../nointerfaces/model/MyContent.java | 329 +++++++ .../model/container-nointerfaces.proto | 28 + 4 files changed, 1384 insertions(+) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/TestContainer.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/container-nointerfaces.proto diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/TestContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/TestContainer.java new file mode 100644 index 00000000..8076499c --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/TestContainer.java @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2023 Bernhard Haumacher et al. All Rights Reserved. + */ +package test.container.nointerfaces; + +import java.util.Arrays; +import java.util.Collections; + +import junit.framework.TestCase; +import test.container.nointerfaces.model.MyContainer; +import test.container.nointerfaces.model.MyContent; + +/** + * Test case for @Container annotations. + * + * @author
Bernhard Haumacher + */ +@SuppressWarnings("javadoc") +public class TestContainer extends TestCase { + + public void testUpdateSingle() { + MyContainer container = MyContainer.create().setName("container"); + MyContainer otherContainer = MyContainer.create().setName("other"); + + MyContent c1 = MyContent.create().setName("content 1"); + + container.setContent1(c1); + assertEquals(container, c1.getContainer()); + + MyContent c2 = MyContent.create().setName("content 2"); + container.setContent1(c2); + assertNull(c1.getContainer()); + assertEquals(container, c2.getContainer()); + + container.setContent2(c1); + assertEquals(container, c1.getContainer()); + assertEquals(container, c2.getContainer()); + + try { + otherContainer.setContent1(c1); + fail("Must not make object part of two different containers."); + } catch (IllegalStateException ex) { + assertEquals("Object may not be part of two different containers.", ex.getMessage()); + } + + // Check that nothing has changed. + assertNull(otherContainer.getContent1()); + assertEquals(container, c1.getContainer()); + assertEquals(container, c2.getContainer()); + } + + public void testUpdateMulti() { + MyContainer container = MyContainer.create().setName("container"); + MyContainer otherContainer = MyContainer.create().setName("other"); + + MyContent c1 = MyContent.create().setName("content 1"); + + container.addContentList(c1); + assertEquals(container, c1.getContainer()); + + MyContent c2 = MyContent.create().setName("content 2"); + container.addContentList(c2); + assertEquals(container, c1.getContainer()); + assertEquals(container, c2.getContainer()); + + container.setContentList(Arrays.asList(c1)); + assertEquals(container, c1.getContainer()); + assertNull(c2.getContainer()); + + container.removeContentList(c1); + assertNull(c1.getContainer()); + + container.setContentList(Arrays.asList(c1, c2)); + assertEquals(container, c1.getContainer()); + assertEquals(container, c2.getContainer()); + + container.getContentList().clear(); + assertNull(c1.getContainer()); + assertNull(c2.getContainer()); + + container.addContentList(c1); + try { + container.addContentList(c1); + fail("Must not make object part of two different containers."); + } catch (IllegalStateException ex) { + assertEquals("Object may not be part of two different containers.", ex.getMessage()); + } + + // Check that nothing has changed. + assertEquals(container, c1.getContainer()); + assertEquals(Arrays.asList(c1), container.getContentList()); + + try { + otherContainer.addContentList(c1); + fail("Must not make object part of two different containers."); + } catch (IllegalStateException ex) { + assertEquals("Object may not be part of two different containers.", ex.getMessage()); + } + + assertEquals(container, c1.getContainer()); + assertEquals(Arrays.asList(c1), container.getContentList()); + assertEquals(0, otherContainer.getContentList().size()); + } + + public void testUpdateMap() { + MyContainer container = MyContainer.create().setName("container"); + MyContainer otherContainer = MyContainer.create().setName("other"); + + MyContent c1 = MyContent.create().setName("content 1"); + + container.putContentMap("c1", c1); + assertEquals(container, c1.getContainer()); + + MyContent c2 = MyContent.create().setName("content 2"); + container.putContentMap("c2", c2); + assertEquals(container, c1.getContainer()); + assertEquals(container, c2.getContainer()); + + container.setContentMap(Collections.singletonMap("c1", c1)); + assertEquals(container, c1.getContainer()); + assertNull(c2.getContainer()); + + container.removeContentMap("c1"); + assertNull(c1.getContainer()); + + container.getContentMap().putAll(Collections.singletonMap("c1", c1)); + container.getContentMap().putAll(Collections.singletonMap("c2", c2)); + assertEquals(container, c1.getContainer()); + assertEquals(container, c2.getContainer()); + + container.getContentMap().clear(); + assertNull(c1.getContainer()); + assertNull(c2.getContainer()); + + container.getContentMap().put("c1", c2); + assertEquals(container, c2.getContainer()); + + container.getContentMap().put("c1", c2); + assertEquals(container, c2.getContainer()); + + container.getContentMap().put("c1", c1); + assertEquals(container, c1.getContainer()); + assertNull(c2.getContainer()); + + try { + container.getContentMap().put("c2", c1); + fail("Must not make object part of two different containers."); + } catch (IllegalStateException ex) { + assertEquals("Object may not be part of two different containers.", ex.getMessage()); + } + + // Check that nothing has changed. + assertEquals(container, c1.getContainer()); + assertEquals(Collections.singletonMap("c1", c1), container.getContentMap()); + + try { + otherContainer.putContentMap("c1", c1); + fail("Must not make object part of two different containers."); + } catch (IllegalStateException ex) { + assertEquals("Object may not be part of two different containers.", ex.getMessage()); + } + + assertEquals(container, c1.getContainer()); + assertEquals(Collections.singletonMap("c1", c1), container.getContentMap()); + assertEquals(0, otherContainer.getContentMap().size()); + } + + public void testUpdateIdentical() { + MyContent c = MyContent.create().setName("c"); + MyContainer container = MyContainer.create().setContent1(c); + + assertEquals(container, c.getContainer()); + assertEquals(c, container.getContent1()); + + container.setContent1(c); + + assertEquals(container, c.getContainer()); + assertEquals(c, container.getContent1()); + } + + public void testUpdateRef() { + MyContent c = MyContent.create().setName("c"); + MyContainer container = MyContainer.create().setOther(c).addOthers(c); + + assertEquals(c, container.getOther()); + assertNull(c.getContainer()); + + container.setContent1(c); + assertEquals(container, c.getContainer()); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java new file mode 100644 index 00000000..b9aceb6a --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java @@ -0,0 +1,835 @@ +package test.container.nointerfaces.model; + +public class MyContainer extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.container.nointerfaces.model.MyContainer} instance. + */ + public static test.container.nointerfaces.model.MyContainer create() { + return new test.container.nointerfaces.model.MyContainer(); + } + + /** Identifier for the {@link test.container.nointerfaces.model.MyContainer} type in JSON format. */ + public static final String MY_CONTAINER__TYPE = "MyContainer"; + + /** @see #getName() */ + public static final String NAME__PROP = "name"; + + /** @see #getContent1() */ + public static final String CONTENT_1__PROP = "content1"; + + /** @see #getContent2() */ + public static final String CONTENT_2__PROP = "content2"; + + /** @see #getContentList() */ + public static final String CONTENT_LIST__PROP = "contentList"; + + /** @see #getContentMap() */ + public static final String CONTENT_MAP__PROP = "contentMap"; + + /** @see #getOther() */ + public static final String OTHER__PROP = "other"; + + /** @see #getOthers() */ + public static final String OTHERS__PROP = "others"; + + /** Identifier for the property {@link #getName()} in binary format. */ + static final int NAME__ID = 1; + + /** Identifier for the property {@link #getContent1()} in binary format. */ + static final int CONTENT_1__ID = 2; + + /** Identifier for the property {@link #getContent2()} in binary format. */ + static final int CONTENT_2__ID = 3; + + /** Identifier for the property {@link #getContentList()} in binary format. */ + static final int CONTENT_LIST__ID = 4; + + /** Identifier for the property {@link #getContentMap()} in binary format. */ + static final int CONTENT_MAP__ID = 5; + + /** Identifier for the property {@link #getOther()} in binary format. */ + static final int OTHER__ID = 6; + + /** Identifier for the property {@link #getOthers()} in binary format. */ + static final int OTHERS__ID = 7; + + private String _name = ""; + + private test.container.nointerfaces.model.MyContent _content1 = null; + + private test.container.nointerfaces.model.MyContent _content2 = null; + + private final java.util.List _contentList = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.container.nointerfaces.model.MyContent element) { + test.container.nointerfaces.model.MyContent added = element; + test.container.nointerfaces.model.MyContainer oldContainer = added.getContainer(); + if (oldContainer != null && oldContainer != MyContainer.this) { + throw new IllegalStateException("Object may not be part of two different containers."); + } + _listener.beforeAdd(MyContainer.this, CONTENT_LIST__PROP, index, element); + added.internalSetContainer(MyContainer.this); + } + + @Override + protected void afterRemove(int index, test.container.nointerfaces.model.MyContent element) { + test.container.nointerfaces.model.MyContent removed = element; + removed.internalSetContainer(null); + _listener.afterRemove(MyContainer.this, CONTENT_LIST__PROP, index, element); + } + }; + + private final java.util.Map _contentMap = new de.haumacher.msgbuf.util.ReferenceMap() { + @Override + protected void beforeAdd(String index, test.container.nointerfaces.model.MyContent element) { + test.container.nointerfaces.model.MyContent added = element; + test.container.nointerfaces.model.MyContainer oldContainer = added.getContainer(); + if (oldContainer != null && oldContainer != MyContainer.this) { + throw new IllegalStateException("Object may not be part of two different containers."); + } + _listener.beforeAdd(MyContainer.this, CONTENT_MAP__PROP, index, element); + added.internalSetContainer(MyContainer.this); + } + + @Override + protected void afterRemove(String index, test.container.nointerfaces.model.MyContent element) { + test.container.nointerfaces.model.MyContent removed = element; + removed.internalSetContainer(null); + _listener.afterRemove(MyContainer.this, CONTENT_MAP__PROP, index, element); + } + }; + + private test.container.nointerfaces.model.MyContent _other = null; + + private final java.util.List _others = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.container.nointerfaces.model.MyContent element) { + _listener.beforeAdd(MyContainer.this, OTHERS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.container.nointerfaces.model.MyContent element) { + _listener.afterRemove(MyContainer.this, OTHERS__PROP, index, element); + } + }; + + /** + * Creates a {@link MyContainer} instance. + * + * @see test.container.nointerfaces.model.MyContainer#create() + */ + protected MyContainer() { + super(); + } + + public final String getName() { + return _name; + } + + /** + * @see #getName() + */ + public test.container.nointerfaces.model.MyContainer setName(String value) { + internalSetName(value); + return this; + } + + /** Internal setter for {@link #getName()} without chain call utility. */ + protected final void internalSetName(String value) { + _listener.beforeSet(this, NAME__PROP, value); + _name = value; + } + + public final test.container.nointerfaces.model.MyContent getContent1() { + return _content1; + } + + /** + * @see #getContent1() + */ + public test.container.nointerfaces.model.MyContainer setContent1(test.container.nointerfaces.model.MyContent value) { + internalSetContent1(value); + return this; + } + + /** Internal setter for {@link #getContent1()} without chain call utility. */ + protected final void internalSetContent1(test.container.nointerfaces.model.MyContent value) { + test.container.nointerfaces.model.MyContent before = _content1; + test.container.nointerfaces.model.MyContent after = value; + if (after != null) { + test.container.nointerfaces.model.MyContainer oldContainer = after.getContainer(); + if (oldContainer != null && oldContainer != this) { + throw new IllegalStateException("Object may not be part of two different containers."); + } + } + _listener.beforeSet(this, CONTENT_1__PROP, value); + if (before != null) { + before.internalSetContainer(null); + } + _content1 = value; + if (after != null) { + after.internalSetContainer(this); + } + } + + /** + * Checks, whether {@link #getContent1()} has a value. + */ + public final boolean hasContent1() { + return _content1 != null; + } + + public final test.container.nointerfaces.model.MyContent getContent2() { + return _content2; + } + + /** + * @see #getContent2() + */ + public test.container.nointerfaces.model.MyContainer setContent2(test.container.nointerfaces.model.MyContent value) { + internalSetContent2(value); + return this; + } + + /** Internal setter for {@link #getContent2()} without chain call utility. */ + protected final void internalSetContent2(test.container.nointerfaces.model.MyContent value) { + test.container.nointerfaces.model.MyContent before = _content2; + test.container.nointerfaces.model.MyContent after = value; + if (after != null) { + test.container.nointerfaces.model.MyContainer oldContainer = after.getContainer(); + if (oldContainer != null && oldContainer != this) { + throw new IllegalStateException("Object may not be part of two different containers."); + } + } + _listener.beforeSet(this, CONTENT_2__PROP, value); + if (before != null) { + before.internalSetContainer(null); + } + _content2 = value; + if (after != null) { + after.internalSetContainer(this); + } + } + + /** + * Checks, whether {@link #getContent2()} has a value. + */ + public final boolean hasContent2() { + return _content2 != null; + } + + public final java.util.List getContentList() { + return _contentList; + } + + /** + * @see #getContentList() + */ + public test.container.nointerfaces.model.MyContainer setContentList(java.util.List value) { + internalSetContentList(value); + return this; + } + + /** Internal setter for {@link #getContentList()} without chain call utility. */ + protected final void internalSetContentList(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'contentList' cannot be null."); + _contentList.clear(); + _contentList.addAll(value); + } + + /** + * Adds a value to the {@link #getContentList()} list. + */ + public test.container.nointerfaces.model.MyContainer addContentList(test.container.nointerfaces.model.MyContent value) { + internalAddContentList(value); + return this; + } + + /** Implementation of {@link #addContentList(test.container.nointerfaces.model.MyContent)} without chain call utility. */ + protected final void internalAddContentList(test.container.nointerfaces.model.MyContent value) { + _contentList.add(value); + } + + /** + * Removes a value from the {@link #getContentList()} list. + */ + public final void removeContentList(test.container.nointerfaces.model.MyContent value) { + _contentList.remove(value); + } + + public final java.util.Map getContentMap() { + return _contentMap; + } + + /** + * @see #getContentMap() + */ + public test.container.nointerfaces.model.MyContainer setContentMap(java.util.Map value) { + internalSetContentMap(value); + return this; + } + + /** Internal setter for {@link #getContentMap()} without chain call utility. */ + protected final void internalSetContentMap(java.util.Map value) { + if (value == null) throw new IllegalArgumentException("Property 'contentMap' cannot be null."); + _contentMap.clear(); + _contentMap.putAll(value); + } + + /** + * Adds a key value pair to the {@link #getContentMap()} map. + */ + public test.container.nointerfaces.model.MyContainer putContentMap(String key, test.container.nointerfaces.model.MyContent value) { + internalPutContentMap(key, value); + return this; + } + + /** Implementation of {@link #putContentMap(String, test.container.nointerfaces.model.MyContent)} without chain call utility. */ + protected final void internalPutContentMap(String key, test.container.nointerfaces.model.MyContent value) { + if (_contentMap.containsKey(key)) { + throw new IllegalArgumentException("Property 'contentMap' already contains a value for key '" + key + "'."); + } + _contentMap.put(key, value); + } + + /** + * Removes a key from the {@link #getContentMap()} map. + */ + public final void removeContentMap(String key) { + _contentMap.remove(key); + } + + public final test.container.nointerfaces.model.MyContent getOther() { + return _other; + } + + /** + * @see #getOther() + */ + public test.container.nointerfaces.model.MyContainer setOther(test.container.nointerfaces.model.MyContent value) { + internalSetOther(value); + return this; + } + + /** Internal setter for {@link #getOther()} without chain call utility. */ + protected final void internalSetOther(test.container.nointerfaces.model.MyContent value) { + _listener.beforeSet(this, OTHER__PROP, value); + _other = value; + } + + /** + * Checks, whether {@link #getOther()} has a value. + */ + public final boolean hasOther() { + return _other != null; + } + + public final java.util.List getOthers() { + return _others; + } + + /** + * @see #getOthers() + */ + public test.container.nointerfaces.model.MyContainer setOthers(java.util.List value) { + internalSetOthers(value); + return this; + } + + /** Internal setter for {@link #getOthers()} without chain call utility. */ + protected final void internalSetOthers(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'others' cannot be null."); + _others.clear(); + _others.addAll(value); + } + + /** + * Adds a value to the {@link #getOthers()} list. + */ + public test.container.nointerfaces.model.MyContainer addOthers(test.container.nointerfaces.model.MyContent value) { + internalAddOthers(value); + return this; + } + + /** Implementation of {@link #addOthers(test.container.nointerfaces.model.MyContent)} without chain call utility. */ + protected final void internalAddOthers(test.container.nointerfaces.model.MyContent value) { + _others.add(value); + } + + /** + * Removes a value from the {@link #getOthers()} list. + */ + public final void removeOthers(test.container.nointerfaces.model.MyContent value) { + _others.remove(value); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.container.nointerfaces.model.MyContainer registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.container.nointerfaces.model.MyContainer unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return MY_CONTAINER__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + NAME__PROP, + CONTENT_1__PROP, + CONTENT_2__PROP, + CONTENT_LIST__PROP, + CONTENT_MAP__PROP, + OTHER__PROP, + OTHERS__PROP)); + + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NAME__PROP: return getName(); + case CONTENT_1__PROP: return getContent1(); + case CONTENT_2__PROP: return getContent2(); + case CONTENT_LIST__PROP: return getContentList(); + case CONTENT_MAP__PROP: return getContentMap(); + case OTHER__PROP: return getOther(); + case OTHERS__PROP: return getOthers(); + default: return null; + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NAME__PROP: internalSetName((String) value); break; + case CONTENT_1__PROP: internalSetContent1((test.container.nointerfaces.model.MyContent) value); break; + case CONTENT_2__PROP: internalSetContent2((test.container.nointerfaces.model.MyContent) value); break; + case CONTENT_LIST__PROP: internalSetContentList(de.haumacher.msgbuf.util.Conversions.asList(test.container.nointerfaces.model.MyContent.class, value)); break; + case CONTENT_MAP__PROP: internalSetContentMap((java.util.Map) value); break; + case OTHER__PROP: internalSetOther((test.container.nointerfaces.model.MyContent) value); break; + case OTHERS__PROP: internalSetOthers(de.haumacher.msgbuf.util.Conversions.asList(test.container.nointerfaces.model.MyContent.class, value)); break; + } + } + + /** Reads a new instance from the given reader. */ + public static test.container.nointerfaces.model.MyContainer readMyContainer(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.container.nointerfaces.model.MyContainer result = new test.container.nointerfaces.model.MyContainer(); + result.readContent(in); + return result; + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NAME__PROP); + out.value(getName()); + if (hasContent1()) { + out.name(CONTENT_1__PROP); + getContent1().writeTo(out); + } + if (hasContent2()) { + out.name(CONTENT_2__PROP); + getContent2().writeTo(out); + } + out.name(CONTENT_LIST__PROP); + out.beginArray(); + for (test.container.nointerfaces.model.MyContent x : getContentList()) { + x.writeTo(out); + } + out.endArray(); + out.name(CONTENT_MAP__PROP); + out.beginObject(); + for (java.util.Map.Entry entry : getContentMap().entrySet()) { + out.name(entry.getKey()); + entry.getValue().writeTo(out); + } + out.endObject(); + if (hasOther()) { + out.name(OTHER__PROP); + getOther().writeTo(out); + } + out.name(OTHERS__PROP); + out.beginArray(); + for (test.container.nointerfaces.model.MyContent x : getOthers()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case CONTENT_1__PROP: setContent1(test.container.nointerfaces.model.MyContent.readMyContent(in)); break; + case CONTENT_2__PROP: setContent2(test.container.nointerfaces.model.MyContent.readMyContent(in)); break; + case CONTENT_LIST__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.container.nointerfaces.model.MyContent.readMyContent(in)); + } + in.endArray(); + setContentList(newValue); + } + break; + case CONTENT_MAP__PROP: { + java.util.Map newValue = new java.util.LinkedHashMap<>(); + in.beginObject(); + while (in.hasNext()) { + newValue.put(in.nextName(), test.container.nointerfaces.model.MyContent.readMyContent(in)); + } + in.endObject(); + setContentMap(newValue); + break; + } + case OTHER__PROP: setOther(test.container.nointerfaces.model.MyContent.readMyContent(in)); break; + case OTHERS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.container.nointerfaces.model.MyContent.readMyContent(in)); + } + in.endArray(); + setOthers(newValue); + } + break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(NAME__ID); + out.value(getName()); + if (hasContent1()) { + out.name(CONTENT_1__ID); + getContent1().writeTo(out); + } + if (hasContent2()) { + out.name(CONTENT_2__ID); + getContent2().writeTo(out); + } + out.name(CONTENT_LIST__ID); + { + java.util.List values = getContentList(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.container.nointerfaces.model.MyContent x : values) { + x.writeTo(out); + } + out.endArray(); + } + out.name(CONTENT_MAP__ID); + if (hasOther()) { + out.name(OTHER__ID); + getOther().writeTo(out); + } + out.name(OTHERS__ID); + { + java.util.List values = getOthers(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.container.nointerfaces.model.MyContent x : values) { + x.writeTo(out); + } + out.endArray(); + } + } + + /** Reads a new instance from the given reader. */ + public static test.container.nointerfaces.model.MyContainer readMyContainer(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.container.nointerfaces.model.MyContainer result = test.container.nointerfaces.model.MyContainer.readMyContainer_Content(in); + in.endObject(); + return result; + } + + /** Helper for creating an object of type {@link test.container.nointerfaces.model.MyContainer} from a polymorphic composition. */ + public static test.container.nointerfaces.model.MyContainer readMyContainer_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.container.nointerfaces.model.MyContainer result = new MyContainer(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case NAME__ID: setName(in.nextString()); break; + case CONTENT_1__ID: setContent1(test.container.nointerfaces.model.MyContent.readMyContent(in)); break; + case CONTENT_2__ID: setContent2(test.container.nointerfaces.model.MyContent.readMyContent(in)); break; + case CONTENT_LIST__ID: { + in.beginArray(); + while (in.hasNext()) { + addContentList(test.container.nointerfaces.model.MyContent.readMyContent(in)); + } + in.endArray(); + } + break; + case CONTENT_MAP__ID: { + in.beginArray(); + while (in.hasNext()) { + in.beginObject(); + String key = ""; + test.container.nointerfaces.model.MyContent value = null; + while (in.hasNext()) { + switch (in.nextName()) { + case 1: key = in.nextString(); break; + case 2: value = test.container.nointerfaces.model.MyContent.readMyContent(in); break; + default: in.skipValue(); break; + } + } + putContentMap(key, value); + in.endObject(); + } + in.endArray(); + break; + } + case OTHER__ID: setOther(test.container.nointerfaces.model.MyContent.readMyContent(in)); break; + case OTHERS__ID: { + in.beginArray(); + while (in.hasNext()) { + addOthers(test.container.nointerfaces.model.MyContent.readMyContent(in)); + } + in.endArray(); + } + break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.container.nointerfaces.model.MyContainer} type. */ + public static final String MY_CONTAINER__XML_ELEMENT = "my-container"; + + /** XML attribute or element name of a {@link #getName} property. */ + private static final String NAME__XML_ATTR = "name"; + + /** XML attribute or element name of a {@link #getContent1} property. */ + private static final String CONTENT_1__XML_ATTR = "content-1"; + + /** XML attribute or element name of a {@link #getContent2} property. */ + private static final String CONTENT_2__XML_ATTR = "content-2"; + + /** XML attribute or element name of a {@link #getContentList} property. */ + private static final String CONTENT_LIST__XML_ATTR = "content-list"; + + /** XML attribute or element name of a {@link #getContentMap} property. */ + private static final String CONTENT_MAP__XML_ATTR = "content-map"; + + /** XML attribute or element name of a {@link #getOther} property. */ + private static final String OTHER__XML_ATTR = "other"; + + /** XML attribute or element name of a {@link #getOthers} property. */ + private static final String OTHERS__XML_ATTR = "others"; + + @Override + public String getXmlTagName() { + return MY_CONTAINER__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasContent1()) { + out.writeStartElement(CONTENT_1__XML_ATTR); + getContent1().writeContent(out); + out.writeEndElement(); + } + if (hasContent2()) { + out.writeStartElement(CONTENT_2__XML_ATTR); + getContent2().writeContent(out); + out.writeEndElement(); + } + out.writeStartElement(CONTENT_LIST__XML_ATTR); + for (test.container.nointerfaces.model.MyContent element : getContentList()) { + element.writeTo(out); + } + out.writeEndElement(); + if (hasOther()) { + out.writeStartElement(OTHER__XML_ATTR); + getOther().writeContent(out); + out.writeEndElement(); + } + out.writeStartElement(OTHERS__XML_ATTR); + for (test.container.nointerfaces.model.MyContent element : getOthers()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.container.nointerfaces.model.MyContainer} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static MyContainer readMyContainer_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + MyContainer result = new MyContainer(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NAME__XML_ATTR: { + setName(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NAME__XML_ATTR: { + setName(in.getElementText()); + break; + } + case CONTENT_1__XML_ATTR: { + setContent1(test.container.nointerfaces.model.MyContent.readMyContent_XmlContent(in)); + break; + } + case CONTENT_2__XML_ATTR: { + setContent2(test.container.nointerfaces.model.MyContent.readMyContent_XmlContent(in)); + break; + } + case CONTENT_LIST__XML_ATTR: { + internalReadContentListListXml(in); + break; + } + case OTHER__XML_ATTR: { + setOther(test.container.nointerfaces.model.MyContent.readMyContent_XmlContent(in)); + break; + } + case OTHERS__XML_ATTR: { + internalReadOthersListXml(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadContentListListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addContentList(test.container.nointerfaces.model.MyContent.readMyContent_XmlContent(in)); + } + } + + private void internalReadOthersListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addOthers(test.container.nointerfaces.model.MyContent.readMyContent_XmlContent(in)); + } + } + + /** Creates a new {@link MyContainer} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static MyContainer readMyContainer(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.container.nointerfaces.model.MyContainer.readMyContainer_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java new file mode 100644 index 00000000..07d41154 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java @@ -0,0 +1,329 @@ +package test.container.nointerfaces.model; + +public class MyContent extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.container.nointerfaces.model.MyContent} instance. + */ + public static test.container.nointerfaces.model.MyContent create() { + return new test.container.nointerfaces.model.MyContent(); + } + + /** Identifier for the {@link test.container.nointerfaces.model.MyContent} type in JSON format. */ + public static final String MY_CONTENT__TYPE = "MyContent"; + + /** @see #getContainer() */ + public static final String CONTAINER__PROP = "container"; + + /** @see #getName() */ + public static final String NAME__PROP = "name"; + + /** Identifier for the property {@link #getName()} in binary format. */ + static final int NAME__ID = 2; + + private test.container.nointerfaces.model.MyContainer _container = null; + + private String _name = ""; + + /** + * Creates a {@link MyContent} instance. + * + * @see test.container.nointerfaces.model.MyContent#create() + */ + protected MyContent() { + super(); + } + + public final test.container.nointerfaces.model.MyContainer getContainer() { + return _container; + } + + /** + * Internal setter for updating derived field. + */ + test.container.nointerfaces.model.MyContent setContainer(test.container.nointerfaces.model.MyContainer value) { + internalSetContainer(value); + return this; + } + + /** Internal setter for {@link #getContainer()} without chain call utility. */ + protected final void internalSetContainer(test.container.nointerfaces.model.MyContainer value) { + _listener.beforeSet(this, CONTAINER__PROP, value); + if (value != null && _container != null) { + throw new IllegalStateException("Object may not be part of two different containers."); + } + _container = value; + } + + /** + * Checks, whether {@link #getContainer()} has a value. + */ + public final boolean hasContainer() { + return _container != null; + } + + public final String getName() { + return _name; + } + + /** + * @see #getName() + */ + public test.container.nointerfaces.model.MyContent setName(String value) { + internalSetName(value); + return this; + } + + /** Internal setter for {@link #getName()} without chain call utility. */ + protected final void internalSetName(String value) { + _listener.beforeSet(this, NAME__PROP, value); + _name = value; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.container.nointerfaces.model.MyContent registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.container.nointerfaces.model.MyContent unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return MY_CONTENT__TYPE; + } + + private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( + java.util.Arrays.asList( + CONTAINER__PROP, + NAME__PROP)); + + private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( + java.util.Arrays.asList( + ))); + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case CONTAINER__PROP: return getContainer(); + case NAME__PROP: return getName(); + default: return null; + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NAME__PROP: internalSetName((String) value); break; + } + } + + /** Reads a new instance from the given reader. */ + public static test.container.nointerfaces.model.MyContent readMyContent(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.container.nointerfaces.model.MyContent result = new test.container.nointerfaces.model.MyContent(); + result.readContent(in); + return result; + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NAME__PROP); + out.value(getName()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(NAME__ID); + out.value(getName()); + } + + /** Reads a new instance from the given reader. */ + public static test.container.nointerfaces.model.MyContent readMyContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.container.nointerfaces.model.MyContent result = test.container.nointerfaces.model.MyContent.readMyContent_Content(in); + in.endObject(); + return result; + } + + /** Helper for creating an object of type {@link test.container.nointerfaces.model.MyContent} from a polymorphic composition. */ + public static test.container.nointerfaces.model.MyContent readMyContent_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.container.nointerfaces.model.MyContent result = new MyContent(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case NAME__ID: setName(in.nextString()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.container.nointerfaces.model.MyContent} type. */ + public static final String MY_CONTENT__XML_ELEMENT = "my-content"; + + /** XML attribute or element name of a {@link #getContainer} property. */ + private static final String CONTAINER__XML_ATTR = "container"; + + /** XML attribute or element name of a {@link #getName} property. */ + private static final String NAME__XML_ATTR = "name"; + + @Override + public String getXmlTagName() { + return MY_CONTENT__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasContainer()) { + out.writeStartElement(CONTAINER__XML_ATTR); + getContainer().writeContent(out); + out.writeEndElement(); + } + } + + /** Creates a new {@link test.container.nointerfaces.model.MyContent} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static MyContent readMyContent_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + MyContent result = new MyContent(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NAME__XML_ATTR: { + setName(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case CONTAINER__XML_ATTR: { + setContainer(test.container.nointerfaces.model.MyContainer.readMyContainer_XmlContent(in)); + break; + } + case NAME__XML_ATTR: { + setName(in.getElementText()); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + /** Creates a new {@link MyContent} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static MyContent readMyContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.container.nointerfaces.model.MyContent.readMyContent_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/container-nointerfaces.proto b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/container-nointerfaces.proto new file mode 100644 index 00000000..f0da5bdf --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/container-nointerfaces.proto @@ -0,0 +1,28 @@ +package test.container.nointerfaces.model; + +option NoInterfaces; + +message MyContainer { + string name; + + MyContent content1; + MyContent content2; + + repeated MyContent contentList; + map contentMap; + + @Ref + MyContent other; + + @Ref + repeated MyContent others; +} + +message MyContent { + + @Container + MyContainer container; + + string name; + +} \ No newline at end of file From 7dbad715197610b3cba5ae5e2258ade8517d6a61 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Thu, 24 Apr 2025 10:36:55 +0200 Subject: [PATCH 101/207] Fixed missing ID in sync command, when multiple commands are merged. --- .../src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java index b5645b73..b5bed272 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java @@ -142,7 +142,9 @@ private static Command append(final ListUpdate clash, ListUpdate update) { cnt++; if (cnt > 10) { // Too many changes, create complete update. - return SetProperty.create().setNode(update.getNode()) + return SetProperty.create() + .setId(update.getId()) + .setNode(update.getNode()) .setProperty(update.getProperty()); } current = next; From f2e2814dbc78803df6f4738b4397d812fe086db5 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Thu, 24 Apr 2025 10:37:28 +0200 Subject: [PATCH 102/207] Updated command messages, removed listeners. --- .../haumacher/msgbuf/graph/cmd/Command.java | 143 +++++++----------- .../msgbuf/graph/cmd/InsertElement.java | 93 ++++++------ .../msgbuf/graph/cmd/ListUpdate.java | 96 ++++++------ .../msgbuf/graph/cmd/RemoveElement.java | 71 ++++++--- .../msgbuf/graph/cmd/SetProperty.java | 59 +++++--- .../haumacher/msgbuf/graph/cmd/update.proto | 5 + 6 files changed, 245 insertions(+), 222 deletions(-) diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/Command.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/Command.java index e9a87e66..c290cd2c 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/Command.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/Command.java @@ -3,45 +3,42 @@ /** * Base class of commands that encode changes to data objects. */ -public abstract class Command extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable { +public abstract class Command extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.binary.BinaryDataObject { - /** Type codes for the {@link Command} hierarchy. */ + /** Type codes for the {@link de.haumacher.msgbuf.graph.cmd.Command} hierarchy. */ public enum TypeKind { - /** Type literal for {@link SetProperty}. */ + /** Type literal for {@link de.haumacher.msgbuf.graph.cmd.SetProperty}. */ SET_PROPERTY, - /** Type literal for {@link InsertElement}. */ + /** Type literal for {@link de.haumacher.msgbuf.graph.cmd.InsertElement}. */ INSERT_ELEMENT, - /** Type literal for {@link RemoveElement}. */ + /** Type literal for {@link de.haumacher.msgbuf.graph.cmd.RemoveElement}. */ REMOVE_ELEMENT, ; } - /** Visitor interface for the {@link Command} hierarchy.*/ - public interface Visitor extends ListUpdate.Visitor { + /** Visitor interface for the {@link de.haumacher.msgbuf.graph.cmd.Command} hierarchy.*/ + public interface Visitor extends de.haumacher.msgbuf.graph.cmd.ListUpdate.Visitor { - /** Visit case for {@link SetProperty}.*/ - R visit(SetProperty self, A arg) throws E; + /** Visit case for {@link de.haumacher.msgbuf.graph.cmd.SetProperty}.*/ + R visit(de.haumacher.msgbuf.graph.cmd.SetProperty self, A arg) throws E; } /** @see #getId() */ - public static final String ID = "id"; + private static final String ID__PROP = "id"; /** @see #getProperty() */ - public static final String PROPERTY = "p"; - - /** @see #getNode() */ - public static final String NODE = "node"; + private static final String PROPERTY__PROP = "p"; /** Identifier for the property {@link #getId()} in binary format. */ - public static final int ID__ID = 1; + static final int ID__ID = 1; /** Identifier for the property {@link #getProperty()} in binary format. */ - public static final int PROPERTY__ID = 2; + static final int PROPERTY__ID = 2; private int _id = 0; @@ -69,12 +66,16 @@ public final int getId() { /** * @see #getId() */ - public final Command setId(int value) { - _listener.beforeSet(this, ID, value); - _id = value; + public de.haumacher.msgbuf.graph.cmd.Command setId(int value) { + internalSetId(value); return this; } + /** Internal setter for {@link #getId()} without chain call utility. */ + protected final void internalSetId(int value) { + _id = value; + } + /** * The name of the changed property of the object with the given {@link #getId()}. */ @@ -85,12 +86,16 @@ public final String getProperty() { /** * @see #getProperty() */ - public final Command setProperty(String value) { - _listener.beforeSet(this, PROPERTY, value); - _property = value; + public de.haumacher.msgbuf.graph.cmd.Command setProperty(String value) { + internalSetProperty(value); return this; } + /** Internal setter for {@link #getProperty()} without chain call utility. */ + protected final void internalSetProperty(String value) { + _property = value; + } + /** * Cache for the reference to the changed graph node itself. */ @@ -101,12 +106,16 @@ public final de.haumacher.msgbuf.graph.SharedGraphNode getNode() { /** * @see #getNode() */ - public final Command setNode(de.haumacher.msgbuf.graph.SharedGraphNode value) { - _listener.beforeSet(this, NODE, value); - _node = value; + public de.haumacher.msgbuf.graph.cmd.Command setNode(de.haumacher.msgbuf.graph.SharedGraphNode value) { + internalSetNode(value); return this; } + /** Internal setter for {@link #getNode()} without chain call utility. */ + protected final void internalSetNode(de.haumacher.msgbuf.graph.SharedGraphNode value) { + _node = value; + } + /** * Checks, whether {@link #getNode()} has a value. */ @@ -114,53 +123,12 @@ public final boolean hasNode() { return _node != null; } - protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; - - @Override - public Command registerListener(de.haumacher.msgbuf.observer.Listener l) { - _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); - return this; - } - - @Override - public Command unregisterListener(de.haumacher.msgbuf.observer.Listener l) { - _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); - return this; - } - - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - ID, - PROPERTY, - NODE)); - - @Override - public java.util.List properties() { - return PROPERTIES; - } - - @Override - public Object get(String field) { - switch (field) { - case ID: return getId(); - case PROPERTY: return getProperty(); - case NODE: return getNode(); - default: return de.haumacher.msgbuf.observer.Observable.super.get(field); - } - } - - @Override - public void set(String field, Object value) { - switch (field) { - case ID: setId((int) value); break; - case PROPERTY: setProperty((String) value); break; - case NODE: setNode((de.haumacher.msgbuf.graph.SharedGraphNode) value); break; - } - } + /** The type identifier for this concrete subtype. */ + public abstract String jsonType(); /** Reads a new instance from the given reader. */ - public static Command readCommand(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - Command result; + public static de.haumacher.msgbuf.graph.cmd.Command readCommand(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.graph.cmd.Command result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -184,23 +152,23 @@ public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.i @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(ID); + out.name(ID__PROP); out.value(getId()); - out.name(PROPERTY); + out.name(PROPERTY__PROP); out.value(getProperty()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case ID: setId(in.nextInt()); break; - case PROPERTY: setProperty(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case ID__PROP: setId(in.nextInt()); break; + case PROPERTY__PROP: setProperty(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; default: super.readField(in, field); } } - /** The binary identifier for this concrete type in the polymorphic {@link Command} hierarchy. */ - public abstract int typeId(); + /** The binary identifier for this concrete type in the polymorphic {@link de.haumacher.msgbuf.graph.cmd.Command} hierarchy. */ + abstract int typeId(); @Override public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { @@ -226,24 +194,28 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } /** Reads a new instance from the given reader. */ - public static Command readCommand(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.graph.cmd.Command readCommand(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - Command result; int typeField = in.nextName(); assert typeField == 0; int type = in.nextInt(); + de.haumacher.msgbuf.graph.cmd.Command result; switch (type) { - case SetProperty.SET_PROPERTY__TYPE_ID: result = de.haumacher.msgbuf.graph.cmd.SetProperty.create(); break; - case InsertElement.INSERT_ELEMENT__TYPE_ID: result = de.haumacher.msgbuf.graph.cmd.InsertElement.create(); break; - case RemoveElement.REMOVE_ELEMENT__TYPE_ID: result = de.haumacher.msgbuf.graph.cmd.RemoveElement.create(); break; - default: while (in.hasNext()) {in.skipValue(); } in.endObject(); return null; + case de.haumacher.msgbuf.graph.cmd.SetProperty.SET_PROPERTY__TYPE_ID: result = de.haumacher.msgbuf.graph.cmd.SetProperty.readSetProperty_Content(in); break; + case de.haumacher.msgbuf.graph.cmd.InsertElement.INSERT_ELEMENT__TYPE_ID: result = de.haumacher.msgbuf.graph.cmd.InsertElement.readInsertElement_Content(in); break; + case de.haumacher.msgbuf.graph.cmd.RemoveElement.REMOVE_ELEMENT__TYPE_ID: result = de.haumacher.msgbuf.graph.cmd.RemoveElement.readRemoveElement_Content(in); break; + default: result = null; while (in.hasNext()) {in.skipValue(); } } + in.endObject(); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { while (in.hasNext()) { int field = in.nextName(); - result.readField(in, field); + readField(in, field); } - in.endObject(); - return result; } /** Consumes the value for the field with the given ID and assigns its value. */ @@ -258,5 +230,4 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** Accepts the given visitor. */ public abstract R visit(Visitor v, A arg) throws E; - } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/InsertElement.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/InsertElement.java index 9f548770..614ce96e 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/InsertElement.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/InsertElement.java @@ -6,27 +6,24 @@ public class InsertElement extends ListUpdate { /** - * Creates a {@link InsertElement} instance. + * Creates a {@link de.haumacher.msgbuf.graph.cmd.InsertElement} instance. */ - public static InsertElement create() { - return new InsertElement(); + public static de.haumacher.msgbuf.graph.cmd.InsertElement create() { + return new de.haumacher.msgbuf.graph.cmd.InsertElement(); } - /** Identifier for the {@link InsertElement} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.graph.cmd.InsertElement} type in JSON format. */ public static final String INSERT_ELEMENT__TYPE = "I"; - /** @see #getElement() */ - public static final String ELEMENT = "element"; - - /** Identifier for the {@link InsertElement} type in binary format. */ - public static final int INSERT_ELEMENT__TYPE_ID = 2; + /** Identifier for the {@link de.haumacher.msgbuf.graph.cmd.InsertElement} type in binary format. */ + static final int INSERT_ELEMENT__TYPE_ID = 2; private transient java.lang.Object _element = null; /** * Creates a {@link InsertElement} instance. * - * @see #create() + * @see de.haumacher.msgbuf.graph.cmd.InsertElement#create() */ protected InsertElement() { super(); @@ -47,12 +44,16 @@ public final java.lang.Object getElement() { /** * @see #getElement() */ - public final InsertElement setElement(java.lang.Object value) { - _listener.beforeSet(this, ELEMENT, value); - _element = value; + public de.haumacher.msgbuf.graph.cmd.InsertElement setElement(java.lang.Object value) { + internalSetElement(value); return this; } + /** Internal setter for {@link #getElement()} without chain call utility. */ + protected final void internalSetElement(java.lang.Object value) { + _element = value; + } + /** * Checks, whether {@link #getElement()} has a value. */ @@ -61,41 +62,44 @@ public final boolean hasElement() { } @Override - public String jsonType() { - return INSERT_ELEMENT__TYPE; + public de.haumacher.msgbuf.graph.cmd.InsertElement setIndex(int value) { + internalSetIndex(value); + return this; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - ELEMENT)); + @Override + public de.haumacher.msgbuf.graph.cmd.InsertElement setNext(de.haumacher.msgbuf.graph.cmd.ListUpdate value) { + internalSetNext(value); + return this; + } @Override - public java.util.List properties() { - return PROPERTIES; + public de.haumacher.msgbuf.graph.cmd.InsertElement setId(int value) { + internalSetId(value); + return this; } @Override - public Object get(String field) { - switch (field) { - case ELEMENT: return getElement(); - default: return super.get(field); - } + public de.haumacher.msgbuf.graph.cmd.InsertElement setProperty(String value) { + internalSetProperty(value); + return this; } @Override - public void set(String field, Object value) { - switch (field) { - case ELEMENT: setElement((java.lang.Object) value); break; - default: super.set(field, value); break; - } + public de.haumacher.msgbuf.graph.cmd.InsertElement setNode(de.haumacher.msgbuf.graph.SharedGraphNode value) { + internalSetNode(value); + return this; + } + + @Override + public String jsonType() { + return INSERT_ELEMENT__TYPE; } /** Reads a new instance from the given reader. */ - public static InsertElement readInsertElement(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - InsertElement result = new InsertElement(); - in.beginObject(); - result.readFields(in); - in.endObject(); + public static de.haumacher.msgbuf.graph.cmd.InsertElement readInsertElement(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.graph.cmd.InsertElement result = new de.haumacher.msgbuf.graph.cmd.InsertElement(); + result.readContent(in); return result; } @@ -111,7 +115,7 @@ protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) t } } - @Override + /** The binary identifier for this concrete type in the polymorphic {@link de.haumacher.msgbuf.graph.cmd.InsertElement} hierarchy. */ public int typeId() { return INSERT_ELEMENT__TYPE_ID; } @@ -122,17 +126,20 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } /** Reads a new instance from the given reader. */ - public static InsertElement readInsertElement(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.graph.cmd.InsertElement readInsertElement(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - InsertElement result = new InsertElement(); - while (in.hasNext()) { - int field = in.nextName(); - result.readField(in, field); - } + de.haumacher.msgbuf.graph.cmd.InsertElement result = de.haumacher.msgbuf.graph.cmd.InsertElement.readInsertElement_Content(in); in.endObject(); return result; } + /** Helper for creating an object of type {@link de.haumacher.msgbuf.graph.cmd.InsertElement} from a polymorphic composition. */ + public static de.haumacher.msgbuf.graph.cmd.InsertElement readInsertElement_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + de.haumacher.msgbuf.graph.cmd.InsertElement result = new InsertElement(); + result.readContent(in); + return result; + } + @Override protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { switch (field) { @@ -141,7 +148,7 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } @Override - public R visit(ListUpdate.Visitor v, A arg) throws E { + public R visit(de.haumacher.msgbuf.graph.cmd.ListUpdate.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/ListUpdate.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/ListUpdate.java index bc9dcf7a..d81796f2 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/ListUpdate.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/ListUpdate.java @@ -5,29 +5,26 @@ */ public abstract class ListUpdate extends Command { - /** Visitor interface for the {@link ListUpdate} hierarchy.*/ + /** Visitor interface for the {@link de.haumacher.msgbuf.graph.cmd.ListUpdate} hierarchy.*/ public interface Visitor { - /** Visit case for {@link InsertElement}.*/ - R visit(InsertElement self, A arg) throws E; + /** Visit case for {@link de.haumacher.msgbuf.graph.cmd.InsertElement}.*/ + R visit(de.haumacher.msgbuf.graph.cmd.InsertElement self, A arg) throws E; - /** Visit case for {@link RemoveElement}.*/ - R visit(RemoveElement self, A arg) throws E; + /** Visit case for {@link de.haumacher.msgbuf.graph.cmd.RemoveElement}.*/ + R visit(de.haumacher.msgbuf.graph.cmd.RemoveElement self, A arg) throws E; } /** @see #getIndex() */ - public static final String INDEX = "i"; - - /** @see #getNext() */ - public static final String NEXT = "next"; + private static final String INDEX__PROP = "i"; /** Identifier for the property {@link #getIndex()} in binary format. */ - public static final int INDEX__ID = 4; + static final int INDEX__ID = 4; private int _index = 0; - private transient ListUpdate _next = null; + private transient de.haumacher.msgbuf.graph.cmd.ListUpdate _next = null; /** * Creates a {@link ListUpdate} instance. @@ -46,28 +43,36 @@ public final int getIndex() { /** * @see #getIndex() */ - public final ListUpdate setIndex(int value) { - _listener.beforeSet(this, INDEX, value); - _index = value; + public de.haumacher.msgbuf.graph.cmd.ListUpdate setIndex(int value) { + internalSetIndex(value); return this; } + /** Internal setter for {@link #getIndex()} without chain call utility. */ + protected final void internalSetIndex(int value) { + _index = value; + } + /** * Pointer to chain updates for the same property. */ - public final ListUpdate getNext() { + public final de.haumacher.msgbuf.graph.cmd.ListUpdate getNext() { return _next; } /** * @see #getNext() */ - public final ListUpdate setNext(ListUpdate value) { - _listener.beforeSet(this, NEXT, value); - _next = value; + public de.haumacher.msgbuf.graph.cmd.ListUpdate setNext(de.haumacher.msgbuf.graph.cmd.ListUpdate value) { + internalSetNext(value); return this; } + /** Internal setter for {@link #getNext()} without chain call utility. */ + protected final void internalSetNext(de.haumacher.msgbuf.graph.cmd.ListUpdate value) { + _next = value; + } + /** * Checks, whether {@link #getNext()} has a value. */ @@ -75,37 +80,27 @@ public final boolean hasNext() { return _next != null; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - INDEX, - NEXT)); - @Override - public java.util.List properties() { - return PROPERTIES; + public de.haumacher.msgbuf.graph.cmd.ListUpdate setId(int value) { + internalSetId(value); + return this; } @Override - public Object get(String field) { - switch (field) { - case INDEX: return getIndex(); - case NEXT: return getNext(); - default: return super.get(field); - } + public de.haumacher.msgbuf.graph.cmd.ListUpdate setProperty(String value) { + internalSetProperty(value); + return this; } @Override - public void set(String field, Object value) { - switch (field) { - case INDEX: setIndex((int) value); break; - case NEXT: setNext((ListUpdate) value); break; - default: super.set(field, value); break; - } + public de.haumacher.msgbuf.graph.cmd.ListUpdate setNode(de.haumacher.msgbuf.graph.SharedGraphNode value) { + internalSetNode(value); + return this; } /** Reads a new instance from the given reader. */ - public static ListUpdate readListUpdate(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - ListUpdate result; + public static de.haumacher.msgbuf.graph.cmd.ListUpdate readListUpdate(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.graph.cmd.ListUpdate result; in.beginArray(); String type = in.nextString(); switch (type) { @@ -120,14 +115,14 @@ public static ListUpdate readListUpdate(de.haumacher.msgbuf.json.JsonReader in) @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); - out.name(INDEX); + out.name(INDEX__PROP); out.value(getIndex()); } @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { - case INDEX: setIndex(in.nextInt()); break; + case INDEX__PROP: setIndex(in.nextInt()); break; default: super.readField(in, field); } } @@ -140,20 +135,16 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } /** Reads a new instance from the given reader. */ - public static ListUpdate readListUpdate(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.graph.cmd.ListUpdate readListUpdate(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - ListUpdate result; int typeField = in.nextName(); assert typeField == 0; int type = in.nextInt(); + de.haumacher.msgbuf.graph.cmd.ListUpdate result; switch (type) { - case InsertElement.INSERT_ELEMENT__TYPE_ID: result = de.haumacher.msgbuf.graph.cmd.InsertElement.create(); break; - case RemoveElement.REMOVE_ELEMENT__TYPE_ID: result = de.haumacher.msgbuf.graph.cmd.RemoveElement.create(); break; - default: while (in.hasNext()) {in.skipValue(); } in.endObject(); return null; - } - while (in.hasNext()) { - int field = in.nextName(); - result.readField(in, field); + case de.haumacher.msgbuf.graph.cmd.InsertElement.INSERT_ELEMENT__TYPE_ID: result = de.haumacher.msgbuf.graph.cmd.InsertElement.readInsertElement_Content(in); break; + case de.haumacher.msgbuf.graph.cmd.RemoveElement.REMOVE_ELEMENT__TYPE_ID: result = de.haumacher.msgbuf.graph.cmd.RemoveElement.readRemoveElement_Content(in); break; + default: result = null; while (in.hasNext()) {in.skipValue(); } } in.endObject(); return result; @@ -170,10 +161,9 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** Accepts the given visitor. */ public abstract R visit(Visitor v, A arg) throws E; - @Override - public final R visit(Command.Visitor v, A arg) throws E { - return visit((Visitor) v, arg); + public final R visit(de.haumacher.msgbuf.graph.cmd.Command.Visitor v, A arg) throws E { + return visit((de.haumacher.msgbuf.graph.cmd.ListUpdate.Visitor) v, arg); } } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/RemoveElement.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/RemoveElement.java index e2df09e9..6968a8d0 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/RemoveElement.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/RemoveElement.java @@ -6,22 +6,22 @@ public class RemoveElement extends ListUpdate { /** - * Creates a {@link RemoveElement} instance. + * Creates a {@link de.haumacher.msgbuf.graph.cmd.RemoveElement} instance. */ - public static RemoveElement create() { - return new RemoveElement(); + public static de.haumacher.msgbuf.graph.cmd.RemoveElement create() { + return new de.haumacher.msgbuf.graph.cmd.RemoveElement(); } - /** Identifier for the {@link RemoveElement} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.graph.cmd.RemoveElement} type in JSON format. */ public static final String REMOVE_ELEMENT__TYPE = "R"; - /** Identifier for the {@link RemoveElement} type in binary format. */ - public static final int REMOVE_ELEMENT__TYPE_ID = 3; + /** Identifier for the {@link de.haumacher.msgbuf.graph.cmd.RemoveElement} type in binary format. */ + static final int REMOVE_ELEMENT__TYPE_ID = 3; /** * Creates a {@link RemoveElement} instance. * - * @see #create() + * @see de.haumacher.msgbuf.graph.cmd.RemoveElement#create() */ protected RemoveElement() { super(); @@ -32,39 +32,70 @@ public TypeKind kind() { return TypeKind.REMOVE_ELEMENT; } + @Override + public de.haumacher.msgbuf.graph.cmd.RemoveElement setIndex(int value) { + internalSetIndex(value); + return this; + } + + @Override + public de.haumacher.msgbuf.graph.cmd.RemoveElement setNext(de.haumacher.msgbuf.graph.cmd.ListUpdate value) { + internalSetNext(value); + return this; + } + + @Override + public de.haumacher.msgbuf.graph.cmd.RemoveElement setId(int value) { + internalSetId(value); + return this; + } + + @Override + public de.haumacher.msgbuf.graph.cmd.RemoveElement setProperty(String value) { + internalSetProperty(value); + return this; + } + + @Override + public de.haumacher.msgbuf.graph.cmd.RemoveElement setNode(de.haumacher.msgbuf.graph.SharedGraphNode value) { + internalSetNode(value); + return this; + } + @Override public String jsonType() { return REMOVE_ELEMENT__TYPE; } /** Reads a new instance from the given reader. */ - public static RemoveElement readRemoveElement(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - RemoveElement result = new RemoveElement(); - in.beginObject(); - result.readFields(in); - in.endObject(); + public static de.haumacher.msgbuf.graph.cmd.RemoveElement readRemoveElement(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.graph.cmd.RemoveElement result = new de.haumacher.msgbuf.graph.cmd.RemoveElement(); + result.readContent(in); return result; } - @Override + /** The binary identifier for this concrete type in the polymorphic {@link de.haumacher.msgbuf.graph.cmd.RemoveElement} hierarchy. */ public int typeId() { return REMOVE_ELEMENT__TYPE_ID; } /** Reads a new instance from the given reader. */ - public static RemoveElement readRemoveElement(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.graph.cmd.RemoveElement readRemoveElement(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - RemoveElement result = new RemoveElement(); - while (in.hasNext()) { - int field = in.nextName(); - result.readField(in, field); - } + de.haumacher.msgbuf.graph.cmd.RemoveElement result = de.haumacher.msgbuf.graph.cmd.RemoveElement.readRemoveElement_Content(in); in.endObject(); return result; } + /** Helper for creating an object of type {@link de.haumacher.msgbuf.graph.cmd.RemoveElement} from a polymorphic composition. */ + public static de.haumacher.msgbuf.graph.cmd.RemoveElement readRemoveElement_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + de.haumacher.msgbuf.graph.cmd.RemoveElement result = new RemoveElement(); + result.readContent(in); + return result; + } + @Override - public R visit(ListUpdate.Visitor v, A arg) throws E { + public R visit(de.haumacher.msgbuf.graph.cmd.ListUpdate.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/SetProperty.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/SetProperty.java index 08fcc337..128503ef 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/SetProperty.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/SetProperty.java @@ -6,22 +6,22 @@ public class SetProperty extends Command { /** - * Creates a {@link SetProperty} instance. + * Creates a {@link de.haumacher.msgbuf.graph.cmd.SetProperty} instance. */ - public static SetProperty create() { - return new SetProperty(); + public static de.haumacher.msgbuf.graph.cmd.SetProperty create() { + return new de.haumacher.msgbuf.graph.cmd.SetProperty(); } - /** Identifier for the {@link SetProperty} type in JSON format. */ + /** Identifier for the {@link de.haumacher.msgbuf.graph.cmd.SetProperty} type in JSON format. */ public static final String SET_PROPERTY__TYPE = "S"; - /** Identifier for the {@link SetProperty} type in binary format. */ - public static final int SET_PROPERTY__TYPE_ID = 1; + /** Identifier for the {@link de.haumacher.msgbuf.graph.cmd.SetProperty} type in binary format. */ + static final int SET_PROPERTY__TYPE_ID = 1; /** * Creates a {@link SetProperty} instance. * - * @see #create() + * @see de.haumacher.msgbuf.graph.cmd.SetProperty#create() */ protected SetProperty() { super(); @@ -32,39 +32,58 @@ public TypeKind kind() { return TypeKind.SET_PROPERTY; } + @Override + public de.haumacher.msgbuf.graph.cmd.SetProperty setId(int value) { + internalSetId(value); + return this; + } + + @Override + public de.haumacher.msgbuf.graph.cmd.SetProperty setProperty(String value) { + internalSetProperty(value); + return this; + } + + @Override + public de.haumacher.msgbuf.graph.cmd.SetProperty setNode(de.haumacher.msgbuf.graph.SharedGraphNode value) { + internalSetNode(value); + return this; + } + @Override public String jsonType() { return SET_PROPERTY__TYPE; } /** Reads a new instance from the given reader. */ - public static SetProperty readSetProperty(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { - SetProperty result = new SetProperty(); - in.beginObject(); - result.readFields(in); - in.endObject(); + public static de.haumacher.msgbuf.graph.cmd.SetProperty readSetProperty(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.graph.cmd.SetProperty result = new de.haumacher.msgbuf.graph.cmd.SetProperty(); + result.readContent(in); return result; } - @Override + /** The binary identifier for this concrete type in the polymorphic {@link de.haumacher.msgbuf.graph.cmd.SetProperty} hierarchy. */ public int typeId() { return SET_PROPERTY__TYPE_ID; } /** Reads a new instance from the given reader. */ - public static SetProperty readSetProperty(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + public static de.haumacher.msgbuf.graph.cmd.SetProperty readSetProperty(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { in.beginObject(); - SetProperty result = new SetProperty(); - while (in.hasNext()) { - int field = in.nextName(); - result.readField(in, field); - } + de.haumacher.msgbuf.graph.cmd.SetProperty result = de.haumacher.msgbuf.graph.cmd.SetProperty.readSetProperty_Content(in); in.endObject(); return result; } + /** Helper for creating an object of type {@link de.haumacher.msgbuf.graph.cmd.SetProperty} from a polymorphic composition. */ + public static de.haumacher.msgbuf.graph.cmd.SetProperty readSetProperty_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + de.haumacher.msgbuf.graph.cmd.SetProperty result = new SetProperty(); + result.readContent(in); + return result; + } + @Override - public R visit(Command.Visitor v, A arg) throws E { + public R visit(de.haumacher.msgbuf.graph.cmd.Command.Visitor v, A arg) throws E { return v.visit(this, arg); } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/update.proto b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/update.proto index 55e4d6bd..963dd247 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/update.proto +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/update.proto @@ -1,5 +1,10 @@ package de.haumacher.msgbuf.graph.cmd; +option NoListener; +option NoInterfaces; +option NoReflection; +option NoXml; + /** * Base class of commands that encode changes to data objects. */ From 58b24cac54e438edaafd1c2f257b2f5079b1e4d1 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Thu, 24 Apr 2025 10:38:53 +0200 Subject: [PATCH 103/207] Removed no longer supported parameter from generator launch config. --- de.haumacher.msgbuf.generator/bin/Generate MsgBuf.launch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/de.haumacher.msgbuf.generator/bin/Generate MsgBuf.launch b/de.haumacher.msgbuf.generator/bin/Generate MsgBuf.launch index 13967097..32ea7641 100644 --- a/de.haumacher.msgbuf.generator/bin/Generate MsgBuf.launch +++ b/de.haumacher.msgbuf.generator/bin/Generate MsgBuf.launch @@ -14,7 +14,7 @@ - + From e133f91d54d980668bf7270d3c28d81d0822f55d Mon Sep 17 00:00:00 2001 From: Daniel Busche Date: Tue, 29 Apr 2025 10:22:43 +0200 Subject: [PATCH 104/207] Use correct index in beforeAddAll. --- .../main/java/de/haumacher/msgbuf/util/ReferenceList.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java index 785db83b..7e0f54f7 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java @@ -33,18 +33,17 @@ public boolean add(T element) { @Override public boolean addAll(Collection collection) { - beforeAddAll(collection); + beforeAddAll(size(), collection); return super.addAll(collection); } @Override public boolean addAll(int index, Collection collection) { - beforeAddAll(collection); + beforeAddAll(index, collection); return super.addAll(index, collection); } - private void beforeAddAll(Collection collection) { - int index = size(); + private void beforeAddAll(int index, Collection collection) { for (T element : collection) { beforeAdd(index++, element); } From 53ae59e55ac842b66ea1c8555560f4e38dfa8cf9 Mon Sep 17 00:00:00 2001 From: Daniel Busche Date: Tue, 29 Apr 2025 11:10:24 +0200 Subject: [PATCH 105/207] Ensure that the old value is returned. --- .../src/main/java/de/haumacher/msgbuf/util/ReferenceMap.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceMap.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceMap.java index 15221739..5131bb64 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceMap.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceMap.java @@ -19,10 +19,11 @@ public abstract class ReferenceMap extends HashMap { @Override public V put(K key, V value) { - remove(key); + V oldValue = remove(key); beforeAdd(key, value); - return super.put(key, value); + super.put(key, value); + return oldValue; } @Override From 001bc3317f13d775216a3f786bdc263f2f42e37e Mon Sep 17 00:00:00 2001 From: Daniel Busche Date: Tue, 29 Apr 2025 11:36:13 +0200 Subject: [PATCH 106/207] Added optional listener method "afterChanged". The method "afterChanged" informs about the change of a property, regardless of whether the property is list valued, map valued, or atomic. --- .../msgbuf/generator/MessageGenerator.java | 15 +++++- .../haumacher/msgbuf/observer/Listener.java | 26 ++++++++++ .../haumacher/msgbuf/util/ReferenceList.java | 47 +++++++++++++++---- .../haumacher/msgbuf/util/ReferenceMap.java | 25 +++++++++- 4 files changed, 102 insertions(+), 11 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 3b10d768..97b3700c 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -6,7 +6,7 @@ import static de.haumacher.msgbuf.generator.CodeConvention.*; import static de.haumacher.msgbuf.generator.DefaultValueGenerator.*; import static de.haumacher.msgbuf.generator.TypeGenerator.*; -import static de.haumacher.msgbuf.generator.util.CodeUtil.*; +import static de.haumacher.msgbuf.generator.util.CodeUtil.stringLiteral; import java.util.ArrayList; import java.util.List; @@ -557,6 +557,15 @@ private void generateFieldMembers() { } } line("}"); + + if (_listener) { + nl(); + + line("@Override"); + line("protected void afterChanged() {"); + line("_listener.afterChanged(" + implName(_def) + ".this, " + constant(field) + ");"); + line("}"); + } } line("};"); continue; @@ -775,6 +784,10 @@ private void accessorSetterImpl(Field field) { } line("}"); } + + if (_listener) { + line("_listener.afterChanged(this, " + constant(field) + ");"); + } } } line("}"); diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/observer/Listener.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/observer/Listener.java index fe995ce3..50d8b671 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/observer/Listener.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/observer/Listener.java @@ -96,6 +96,25 @@ default void afterRemove(Observable obj, String property, Object index, Object e // Ignore. } + /** + * Informs this {@link Listener} that the property of an element was changed. + * + *

+ * This method is also called after all other methods to indicate that a property has been changed. It is not + * called more than once for bulk operations (e.g. adding several objects to a list) + *

+ * + * @param obj + * The {@link Observable} object. + * @param property + * The name of the property to be modified. + */ + default void afterChanged(Observable obj, String property) { + // Ignore. + } + + + /** * {@link Listener} that multiplexes events to a list of potentially multiple target {@link Listener}s. */ @@ -130,6 +149,13 @@ public void afterRemove(Observable obj, String property, int index, Object eleme l.afterRemove(obj, property, index, element); } } + + @Override + public void afterChanged(Observable obj, String property) { + for (Listener l : current()) { + l.afterChanged(obj, property); + } + } private Listener[] current() { return toArray(new Listener[0]); diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java index 7e0f54f7..c1974e5f 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceList.java @@ -23,24 +23,37 @@ public abstract class ReferenceList extends ArrayList { public void add(int index, T element) { beforeAdd(index, element); super.add(index, element); + afterChanged(); } @Override public boolean add(T element) { beforeAdd(size(), element); - return super.add(element); + boolean changed = super.add(element); + if (changed) { + afterChanged(); + } + return changed; } @Override public boolean addAll(Collection collection) { beforeAddAll(size(), collection); - return super.addAll(collection); + boolean changed = super.addAll(collection); + if (changed) { + afterChanged(); + } + return changed; } @Override public boolean addAll(int index, Collection collection) { beforeAddAll(index, collection); - return super.addAll(index, collection); + boolean changed = super.addAll(index, collection); + if (changed) { + afterChanged(); + } + return changed; } private void beforeAddAll(int index, Collection collection) { @@ -53,6 +66,12 @@ private void beforeAddAll(int index, Collection collection) { @Override public T remove(int index) { + T removed = internalRemove(index); + afterChanged(); + return removed; + } + + private T internalRemove(int index) { T removed = super.remove(index); afterRemove(index, removed); return removed; @@ -63,8 +82,8 @@ public boolean remove(Object element) { int index = super.indexOf(element); boolean success = index >= 0; if (success) { - final T removed = super.remove(index); - afterRemove(index, removed); + internalRemove(index); + afterChanged(); } return success; } @@ -81,9 +100,14 @@ public boolean retainAll(Collection c) { @Override public void clear() { - for (int index = size() - 1; index >= 0; index--) { - remove(index); + int size = size(); + if (size == 0) { + return; } + for (int index = size - 1; index >= 0; index--) { + internalRemove(index); + } + afterChanged(); } /** @@ -98,10 +122,13 @@ private boolean doRemoveAll(Collection c, boolean removePresent) { for (int index = size() - 1; index >= 0; index--) { T element = get(index); if (test.contains(element) == removePresent) { - remove(index); + internalRemove(index); changed = true; } } + if (changed) { + afterChanged(); + } return changed; } @@ -112,7 +139,11 @@ public T set(int index, T element) { beforeAdd(index, element); T oldValue = super.set(index, element); afterRemove(index + 1, oldValue); + afterChanged(); return oldValue; } + protected void afterChanged() { + // empty for compatibility. + } } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceMap.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceMap.java index 5131bb64..67a6cda0 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceMap.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/util/ReferenceMap.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import java.util.Set; /** * {@link Map} implementing a map-valued property of a data object that has a reverse end. @@ -23,6 +24,7 @@ public V put(K key, V value) { beforeAdd(key, value); super.put(key, value); + afterChanged(); return oldValue; } @@ -30,6 +32,7 @@ public V put(K key, V value) { public void putAll(Map collection) { beforeAddAll(collection); super.putAll(collection); + afterChanged(); } private void beforeAddAll(Map collection) { @@ -42,6 +45,14 @@ private void beforeAddAll(Map collection) { @Override public V remove(Object key) { + final V removed = internalRemove(key); + if (removed != null) { + afterChanged(); + } + return removed; + } + + private V internalRemove(Object key) { final V removed = super.remove(key); if (removed != null) { @SuppressWarnings("unchecked") @@ -60,17 +71,27 @@ public boolean remove(Object key, Object value) { @SuppressWarnings("unchecked") V removed = (V) value; afterRemove(removedKey, removed); + afterChanged(); } return success; } @Override public void clear() { - for (K key : new ArrayList<>(keySet())) { - remove(key); + Set keys = keySet(); + if (keys.isEmpty()) { + return; + } + for (K key : new ArrayList<>(keys)) { + internalRemove(key); } + afterChanged(); } protected abstract void afterRemove(K key, V value); + protected void afterChanged() { + // empty for compatibility. + } + } From 96a60d9dee7bdd4e331df89f690ff6e5d731ee76 Mon Sep 17 00:00:00 2001 From: Daniel Busche Date: Tue, 29 Apr 2025 11:36:31 +0200 Subject: [PATCH 107/207] Re-generated classes. --- .../data/impl/SearchRequest_Impl.java | 3 ++ .../model/impl/MyContainer_Impl.java | 19 ++++++++++++ .../container/model/impl/MyContent_Impl.java | 2 ++ .../nointerfaces/model/MyContainer.java | 19 ++++++++++++ .../nointerfaces/model/MyContent.java | 2 ++ .../test/defaultvalue/data/impl/A_Impl.java | 4 +++ .../embedded/data/impl/Container_Impl.java | 6 ++++ .../data/impl/EmbeddingContainer_Impl.java | 6 ++++ .../impl/EmbeddingSingleContainer_Impl.java | 2 ++ .../data/impl/SingleContainer_Impl.java | 2 ++ .../data/impl/SearchRequest_Impl.java | 4 +++ .../java/test/graph/data/impl/Car_Impl.java | 3 ++ .../test/graph/data/impl/Circle_Impl.java | 1 + .../java/test/graph/data/impl/Group_Impl.java | 5 ++++ .../test/graph/data/impl/Rectangle_Impl.java | 2 ++ .../java/test/graph/data/impl/Shape_Impl.java | 2 ++ .../test/graph/data/impl/SimpleType_Impl.java | 2 ++ .../test/hierarchy/data/impl/Car_Impl.java | 3 ++ .../test/hierarchy/data/impl/Circle_Impl.java | 1 + .../test/hierarchy/data/impl/Group_Impl.java | 5 ++++ .../hierarchy/data/impl/Optional_Impl.java | 2 ++ .../hierarchy/data/impl/Rectangle_Impl.java | 2 ++ .../test/hierarchy/data/impl/Shape_Impl.java | 3 ++ .../hierarchy/data/impl/SimpleType_Impl.java | 2 ++ .../java/test/innertypeclash/impl/A_Impl.java | 3 ++ .../java/test/innertypeclash/impl/B_Impl.java | 3 ++ .../test/lowercasemessage/impl/A_Impl.java | 4 +++ .../maptype/data/impl/MyMessage_Impl.java | 10 +++++++ .../test/maptype/data/impl/Project_Impl.java | 2 ++ .../nested/data/impl/SearchResponse_Impl.java | 12 ++++++++ .../src/test/java/test/nointerfaces/Car.java | 3 ++ .../test/java/test/nointerfaces/Circle.java | 1 + .../test/java/test/nointerfaces/Group.java | 5 ++++ .../java/test/nointerfaces/Rectangle.java | 2 ++ .../test/java/test/nointerfaces/Shape.java | 2 ++ .../java/test/nointerfaces/SimpleType.java | 2 ++ .../test/java/test/nojson/impl/Car_Impl.java | 3 ++ .../java/test/nojson/impl/Circle_Impl.java | 1 + .../java/test/nojson/impl/Group_Impl.java | 5 ++++ .../java/test/nojson/impl/Rectangle_Impl.java | 2 ++ .../java/test/nojson/impl/Shape_Impl.java | 2 ++ .../test/nojson/impl/SimpleType_Impl.java | 2 ++ .../java/test/notypekind/impl/Car_Impl.java | 3 ++ .../test/notypekind/impl/Circle_Impl.java | 1 + .../java/test/notypekind/impl/Group_Impl.java | 5 ++++ .../test/notypekind/impl/Rectangle_Impl.java | 2 ++ .../java/test/notypekind/impl/Shape_Impl.java | 2 ++ .../test/notypekind/impl/SimpleType_Impl.java | 2 ++ .../test/java/test/novisit/impl/Car_Impl.java | 3 ++ .../java/test/novisit/impl/Circle_Impl.java | 1 + .../java/test/novisit/impl/Group_Impl.java | 5 ++++ .../test/novisit/impl/Rectangle_Impl.java | 2 ++ .../java/test/novisit/impl/Shape_Impl.java | 2 ++ .../test/novisit/impl/SimpleType_Impl.java | 2 ++ .../test/novisitexceptions/impl/Car_Impl.java | 3 ++ .../novisitexceptions/impl/Circle_Impl.java | 1 + .../novisitexceptions/impl/Group_Impl.java | 5 ++++ .../impl/Rectangle_Impl.java | 2 ++ .../novisitexceptions/impl/Shape_Impl.java | 2 ++ .../impl/SimpleType_Impl.java | 2 ++ .../test/references/data/impl/A_Impl.java | 29 +++++++++++++++++++ .../test/references/data/impl/B_Impl.java | 11 +++++++ .../types/data/impl/SearchRequest_Impl.java | 3 ++ .../impl/AnnotatedMessage_Impl.java | 1 + .../underscorename/impl/SomeName_Impl.java | 1 + 65 files changed, 256 insertions(+) diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java index 9fda2385..8b4b6698 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java @@ -35,6 +35,7 @@ public test.comments.data.SearchRequest setQuery(String value) { protected final void internalSetQuery(String value) { _listener.beforeSet(this, QUERY__PROP, value); _query = value; + _listener.afterChanged(this, QUERY__PROP); } @Override @@ -52,6 +53,7 @@ public test.comments.data.SearchRequest setPageNumber(int value) { protected final void internalSetPageNumber(int value) { _listener.beforeSet(this, PAGE_NUMBER__PROP, value); _pageNumber = value; + _listener.afterChanged(this, PAGE_NUMBER__PROP); } @Override @@ -69,6 +71,7 @@ public test.comments.data.SearchRequest setResultPerPage(int value) { protected final void internalSetResultPerPage(int value) { _listener.beforeSet(this, RESULT_PER_PAGE__PROP, value); _resultPerPage = value; + _listener.afterChanged(this, RESULT_PER_PAGE__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java index 9a33d645..a38e7f36 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java @@ -29,6 +29,11 @@ protected void afterRemove(int index, test.container.model.MyContent element) { removed.internalSetContainer(null); _listener.afterRemove(MyContainer_Impl.this, CONTENT_LIST__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(MyContainer_Impl.this, CONTENT_LIST__PROP); + } }; private final java.util.Map _contentMap = new de.haumacher.msgbuf.util.ReferenceMap() { @@ -49,6 +54,11 @@ protected void afterRemove(String index, test.container.model.MyContent element) removed.internalSetContainer(null); _listener.afterRemove(MyContainer_Impl.this, CONTENT_MAP__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(MyContainer_Impl.this, CONTENT_MAP__PROP); + } }; private test.container.model.MyContent _other = null; @@ -63,6 +73,11 @@ protected void beforeAdd(int index, test.container.model.MyContent element) { protected void afterRemove(int index, test.container.model.MyContent element) { _listener.afterRemove(MyContainer_Impl.this, OTHERS__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(MyContainer_Impl.this, OTHERS__PROP); + } }; /** @@ -89,6 +104,7 @@ public test.container.model.MyContainer setName(String value) { protected final void internalSetName(String value) { _listener.beforeSet(this, NAME__PROP, value); _name = value; + _listener.afterChanged(this, NAME__PROP); } @Override @@ -120,6 +136,7 @@ protected final void internalSetContent1(test.container.model.MyContent value) { if (after != null) { after.internalSetContainer(this); } + _listener.afterChanged(this, CONTENT_1__PROP); } @Override @@ -156,6 +173,7 @@ protected final void internalSetContent2(test.container.model.MyContent value) { if (after != null) { after.internalSetContainer(this); } + _listener.afterChanged(this, CONTENT_2__PROP); } @Override @@ -249,6 +267,7 @@ public test.container.model.MyContainer setOther(test.container.model.MyContent protected final void internalSetOther(test.container.model.MyContent value) { _listener.beforeSet(this, OTHER__PROP, value); _other = value; + _listener.afterChanged(this, OTHER__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java index 4df6adb3..f789d5e5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java @@ -38,6 +38,7 @@ protected final void internalSetContainer(test.container.model.MyContainer value throw new IllegalStateException("Object may not be part of two different containers."); } _container = value; + _listener.afterChanged(this, CONTAINER__PROP); } @Override @@ -60,6 +61,7 @@ public test.container.model.MyContent setName(String value) { protected final void internalSetName(String value) { _listener.beforeSet(this, NAME__PROP, value); _name = value; + _listener.afterChanged(this, NAME__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java index b9aceb6a..c196b9ba 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java @@ -78,6 +78,11 @@ protected void afterRemove(int index, test.container.nointerfaces.model.MyConten removed.internalSetContainer(null); _listener.afterRemove(MyContainer.this, CONTENT_LIST__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(MyContainer.this, CONTENT_LIST__PROP); + } }; private final java.util.Map _contentMap = new de.haumacher.msgbuf.util.ReferenceMap() { @@ -98,6 +103,11 @@ protected void afterRemove(String index, test.container.nointerfaces.model.MyCon removed.internalSetContainer(null); _listener.afterRemove(MyContainer.this, CONTENT_MAP__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(MyContainer.this, CONTENT_MAP__PROP); + } }; private test.container.nointerfaces.model.MyContent _other = null; @@ -112,6 +122,11 @@ protected void beforeAdd(int index, test.container.nointerfaces.model.MyContent protected void afterRemove(int index, test.container.nointerfaces.model.MyContent element) { _listener.afterRemove(MyContainer.this, OTHERS__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(MyContainer.this, OTHERS__PROP); + } }; /** @@ -139,6 +154,7 @@ public test.container.nointerfaces.model.MyContainer setName(String value) { protected final void internalSetName(String value) { _listener.beforeSet(this, NAME__PROP, value); _name = value; + _listener.afterChanged(this, NAME__PROP); } public final test.container.nointerfaces.model.MyContent getContent1() { @@ -171,6 +187,7 @@ protected final void internalSetContent1(test.container.nointerfaces.model.MyCon if (after != null) { after.internalSetContainer(this); } + _listener.afterChanged(this, CONTENT_1__PROP); } /** @@ -210,6 +227,7 @@ protected final void internalSetContent2(test.container.nointerfaces.model.MyCon if (after != null) { after.internalSetContainer(this); } + _listener.afterChanged(this, CONTENT_2__PROP); } /** @@ -316,6 +334,7 @@ public test.container.nointerfaces.model.MyContainer setOther(test.container.noi protected final void internalSetOther(test.container.nointerfaces.model.MyContent value) { _listener.beforeSet(this, OTHER__PROP, value); _other = value; + _listener.afterChanged(this, OTHER__PROP); } /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java index 07d41154..4dfafd72 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java @@ -53,6 +53,7 @@ protected final void internalSetContainer(test.container.nointerfaces.model.MyCo throw new IllegalStateException("Object may not be part of two different containers."); } _container = value; + _listener.afterChanged(this, CONTAINER__PROP); } /** @@ -78,6 +79,7 @@ public test.container.nointerfaces.model.MyContent setName(String value) { protected final void internalSetName(String value) { _listener.beforeSet(this, NAME__PROP, value); _name = value; + _listener.afterChanged(this, NAME__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java index 375d1b5b..b4eb81bf 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java @@ -37,6 +37,7 @@ public test.defaultvalue.data.A setS(String value) { protected final void internalSetS(String value) { _listener.beforeSet(this, S__PROP, value); _s = value; + _listener.afterChanged(this, S__PROP); } @Override @@ -54,6 +55,7 @@ public test.defaultvalue.data.A setX(int value) { protected final void internalSetX(int value) { _listener.beforeSet(this, X__PROP, value); _x = value; + _listener.afterChanged(this, X__PROP); } @Override @@ -71,6 +73,7 @@ public test.defaultvalue.data.A setY(double value) { protected final void internalSetY(double value) { _listener.beforeSet(this, Y__PROP, value); _y = value; + _listener.afterChanged(this, Y__PROP); } @Override @@ -88,6 +91,7 @@ public test.defaultvalue.data.A setState(boolean value) { protected final void internalSetState(boolean value) { _listener.beforeSet(this, STATE__PROP, value); _state = value; + _listener.afterChanged(this, STATE__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java index d2acddb9..b27e3150 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java @@ -17,6 +17,11 @@ protected void beforeAdd(int index, test.embedded.data.Base element) { protected void afterRemove(int index, test.embedded.data.Base element) { _listener.afterRemove(Container_Impl.this, CONTENTS__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(Container_Impl.this, CONTENTS__PROP); + } }; /** @@ -43,6 +48,7 @@ public test.embedded.data.Container setName(String value) { protected final void internalSetName(String value) { _listener.beforeSet(this, NAME__PROP, value); _name = value; + _listener.afterChanged(this, NAME__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java index ad6d1893..70e2ed38 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java @@ -17,6 +17,11 @@ protected void beforeAdd(int index, test.embedded.data.Base element) { protected void afterRemove(int index, test.embedded.data.Base element) { _listener.afterRemove(EmbeddingContainer_Impl.this, CONTENTS__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(EmbeddingContainer_Impl.this, CONTENTS__PROP); + } }; /** @@ -43,6 +48,7 @@ public test.embedded.data.EmbeddingContainer setName(String value) { protected final void internalSetName(String value) { _listener.beforeSet(this, NAME__PROP, value); _name = value; + _listener.afterChanged(this, NAME__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java index d6802f8d..fb5c2fc0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java @@ -33,6 +33,7 @@ public test.embedded.data.EmbeddingSingleContainer setName(String value) { protected final void internalSetName(String value) { _listener.beforeSet(this, NAME__PROP, value); _name = value; + _listener.afterChanged(this, NAME__PROP); } @Override @@ -50,6 +51,7 @@ public test.embedded.data.EmbeddingSingleContainer setContents(test.embedded.dat protected final void internalSetContents(test.embedded.data.Base value) { _listener.beforeSet(this, CONTENTS__PROP, value); _contents = value; + _listener.afterChanged(this, CONTENTS__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java index 3dc3ea13..7d0b32b0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java @@ -33,6 +33,7 @@ public test.embedded.data.SingleContainer setName(String value) { protected final void internalSetName(String value) { _listener.beforeSet(this, NAME__PROP, value); _name = value; + _listener.afterChanged(this, NAME__PROP); } @Override @@ -50,6 +51,7 @@ public test.embedded.data.SingleContainer setContents(test.embedded.data.Base va protected final void internalSetContents(test.embedded.data.Base value) { _listener.beforeSet(this, CONTENTS__PROP, value); _contents = value; + _listener.afterChanged(this, CONTENTS__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java index 86034f28..f39eb727 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java @@ -37,6 +37,7 @@ public test.enumeration.data.SearchRequest setQuery(String value) { protected final void internalSetQuery(String value) { _listener.beforeSet(this, QUERY__PROP, value); _query = value; + _listener.afterChanged(this, QUERY__PROP); } @Override @@ -54,6 +55,7 @@ public test.enumeration.data.SearchRequest setPageNumber(int value) { protected final void internalSetPageNumber(int value) { _listener.beforeSet(this, PAGE_NUMBER__PROP, value); _pageNumber = value; + _listener.afterChanged(this, PAGE_NUMBER__PROP); } @Override @@ -71,6 +73,7 @@ public test.enumeration.data.SearchRequest setResultPerPage(int value) { protected final void internalSetResultPerPage(int value) { _listener.beforeSet(this, RESULT_PER_PAGE__PROP, value); _resultPerPage = value; + _listener.afterChanged(this, RESULT_PER_PAGE__PROP); } @Override @@ -89,6 +92,7 @@ protected final void internalSetCorpus(test.enumeration.data.SearchRequest.Corpu if (value == null) throw new IllegalArgumentException("Property 'corpus' cannot be null."); _listener.beforeSet(this, CORPUS__PROP, value); _corpus = value; + _listener.afterChanged(this, CORPUS__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java index df76f87f..c34890fc 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java @@ -40,6 +40,7 @@ public test.graph.data.Car setWheel1(test.graph.data.Circle value) { protected final void internalSetWheel1(test.graph.data.Circle value) { _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; + _listener.afterChanged(this, WHEEL_1__PROP); } @Override @@ -62,6 +63,7 @@ public test.graph.data.Car setWheel2(test.graph.data.Circle value) { protected final void internalSetWheel2(test.graph.data.Circle value) { _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; + _listener.afterChanged(this, WHEEL_2__PROP); } @Override @@ -84,6 +86,7 @@ public test.graph.data.Car setBody(test.graph.data.Rectangle value) { protected final void internalSetBody(test.graph.data.Rectangle value) { _listener.beforeSet(this, BODY__PROP, value); _body = value; + _listener.afterChanged(this, BODY__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java index b4c20f19..62d7241f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java @@ -36,6 +36,7 @@ public test.graph.data.Circle setRadius(int value) { protected final void internalSetRadius(int value) { _listener.beforeSet(this, RADIUS__PROP, value); _radius = value; + _listener.afterChanged(this, RADIUS__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java index f08f4649..e7ef44a8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java @@ -15,6 +15,11 @@ protected void beforeAdd(int index, test.graph.data.Shape element) { protected void afterRemove(int index, test.graph.data.Shape element) { _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(Group_Impl.this, SHAPES__PROP); + } }; /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java index 2010f704..66e990df 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java @@ -38,6 +38,7 @@ public test.graph.data.Rectangle setWidth(int value) { protected final void internalSetWidth(int value) { _listener.beforeSet(this, WIDTH__PROP, value); _width = value; + _listener.afterChanged(this, WIDTH__PROP); } @Override @@ -55,6 +56,7 @@ public test.graph.data.Rectangle setHeight(int value) { protected final void internalSetHeight(int value) { _listener.beforeSet(this, HEIGHT__PROP, value); _height = value; + _listener.afterChanged(this, HEIGHT__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java index 136ccab7..b6949acf 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java @@ -31,6 +31,7 @@ public test.graph.data.Shape setXCoordinate(int value) { protected final void internalSetXCoordinate(int value) { _listener.beforeSet(this, X_COORDINATE__PROP, value); _xCoordinate = value; + _listener.afterChanged(this, X_COORDINATE__PROP); } @Override @@ -48,6 +49,7 @@ public test.graph.data.Shape setYCoordinate(int value) { protected final void internalSetYCoordinate(int value) { _listener.beforeSet(this, Y_COORDINATE__PROP, value); _yCoordinate = value; + _listener.afterChanged(this, Y_COORDINATE__PROP); } private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java index 615d71a7..a1eee0e8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java @@ -33,6 +33,7 @@ public test.graph.data.SimpleType setStr(String value) { protected final void internalSetStr(String value) { _listener.beforeSet(this, STR__PROP, value); _str = value; + _listener.afterChanged(this, STR__PROP); } @Override @@ -50,6 +51,7 @@ public test.graph.data.SimpleType setX(int value) { protected final void internalSetX(int value) { _listener.beforeSet(this, X__PROP, value); _x = value; + _listener.afterChanged(this, X__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java index 74c25c2c..0d99b561 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java @@ -40,6 +40,7 @@ public test.hierarchy.data.Car setWheel1(test.hierarchy.data.Circle value) { protected final void internalSetWheel1(test.hierarchy.data.Circle value) { _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; + _listener.afterChanged(this, WHEEL_1__PROP); } @Override @@ -62,6 +63,7 @@ public test.hierarchy.data.Car setWheel2(test.hierarchy.data.Circle value) { protected final void internalSetWheel2(test.hierarchy.data.Circle value) { _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; + _listener.afterChanged(this, WHEEL_2__PROP); } @Override @@ -84,6 +86,7 @@ public test.hierarchy.data.Car setBody(test.hierarchy.data.Rectangle value) { protected final void internalSetBody(test.hierarchy.data.Rectangle value) { _listener.beforeSet(this, BODY__PROP, value); _body = value; + _listener.afterChanged(this, BODY__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java index da67ba84..bec3fb66 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java @@ -36,6 +36,7 @@ public test.hierarchy.data.Circle setRadius(int value) { protected final void internalSetRadius(int value) { _listener.beforeSet(this, RADIUS__PROP, value); _radius = value; + _listener.afterChanged(this, RADIUS__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java index e31460cd..c0741db3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java @@ -15,6 +15,11 @@ protected void beforeAdd(int index, test.hierarchy.data.Shape element) { protected void afterRemove(int index, test.hierarchy.data.Shape element) { _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(Group_Impl.this, SHAPES__PROP); + } }; /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java index d0bc549f..ec1d3eeb 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java @@ -38,6 +38,7 @@ public test.hierarchy.data.Optional setHidden(boolean value) { protected final void internalSetHidden(boolean value) { _listener.beforeSet(this, HIDDEN__PROP, value); _hidden = value; + _listener.afterChanged(this, HIDDEN__PROP); } @Override @@ -55,6 +56,7 @@ public test.hierarchy.data.Optional setShape(test.hierarchy.data.Shape value) { protected final void internalSetShape(test.hierarchy.data.Shape value) { _listener.beforeSet(this, SHAPE__PROP, value); _shape = value; + _listener.afterChanged(this, SHAPE__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java index 5a366ff4..ed534fb7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java @@ -38,6 +38,7 @@ public test.hierarchy.data.Rectangle setWidth(int value) { protected final void internalSetWidth(int value) { _listener.beforeSet(this, WIDTH__PROP, value); _width = value; + _listener.afterChanged(this, WIDTH__PROP); } @Override @@ -55,6 +56,7 @@ public test.hierarchy.data.Rectangle setHeight(int value) { protected final void internalSetHeight(int value) { _listener.beforeSet(this, HEIGHT__PROP, value); _height = value; + _listener.afterChanged(this, HEIGHT__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java index b5504434..34c479bc 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java @@ -33,6 +33,7 @@ public test.hierarchy.data.Shape setXCoordinate(int value) { protected final void internalSetXCoordinate(int value) { _listener.beforeSet(this, X_COORDINATE__PROP, value); _xCoordinate = value; + _listener.afterChanged(this, X_COORDINATE__PROP); } @Override @@ -50,6 +51,7 @@ public test.hierarchy.data.Shape setYCoordinate(int value) { protected final void internalSetYCoordinate(int value) { _listener.beforeSet(this, Y_COORDINATE__PROP, value); _yCoordinate = value; + _listener.afterChanged(this, Y_COORDINATE__PROP); } @Override @@ -68,6 +70,7 @@ protected final void internalSetColor(test.hierarchy.data.Color value) { if (value == null) throw new IllegalArgumentException("Property 'color' cannot be null."); _listener.beforeSet(this, COLOR__PROP, value); _color = value; + _listener.afterChanged(this, COLOR__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java index 91e75555..fd50ef72 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java @@ -33,6 +33,7 @@ public test.hierarchy.data.SimpleType setStr(String value) { protected final void internalSetStr(String value) { _listener.beforeSet(this, STR__PROP, value); _str = value; + _listener.afterChanged(this, STR__PROP); } @Override @@ -50,6 +51,7 @@ public test.hierarchy.data.SimpleType setX(int value) { protected final void internalSetX(int value) { _listener.beforeSet(this, X__PROP, value); _x = value; + _listener.afterChanged(this, X__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java index 80734f48..45e2fd3f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java @@ -200,6 +200,7 @@ public test.innertypeclash.A setAc(test.innertypeclash.A.C value) { protected final void internalSetAc(test.innertypeclash.A.C value) { _listener.beforeSet(this, AC__PROP, value); _ac = value; + _listener.afterChanged(this, AC__PROP); } @Override @@ -222,6 +223,7 @@ public test.innertypeclash.A setBc(test.innertypeclash.B.C value) { protected final void internalSetBc(test.innertypeclash.B.C value) { _listener.beforeSet(this, BC__PROP, value); _bc = value; + _listener.afterChanged(this, BC__PROP); } @Override @@ -244,6 +246,7 @@ public test.innertypeclash.A setC(test.innertypeclash.A.C value) { protected final void internalSetC(test.innertypeclash.A.C value) { _listener.beforeSet(this, C__PROP, value); _c = value; + _listener.afterChanged(this, C__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java index ffa2d4d5..828270c3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java @@ -200,6 +200,7 @@ public test.innertypeclash.B setAc(test.innertypeclash.A.C value) { protected final void internalSetAc(test.innertypeclash.A.C value) { _listener.beforeSet(this, AC__PROP, value); _ac = value; + _listener.afterChanged(this, AC__PROP); } @Override @@ -222,6 +223,7 @@ public test.innertypeclash.B setBc(test.innertypeclash.B.C value) { protected final void internalSetBc(test.innertypeclash.B.C value) { _listener.beforeSet(this, BC__PROP, value); _bc = value; + _listener.afterChanged(this, BC__PROP); } @Override @@ -244,6 +246,7 @@ public test.innertypeclash.B setC(test.innertypeclash.B.C value) { protected final void internalSetC(test.innertypeclash.B.C value) { _listener.beforeSet(this, C__PROP, value); _c = value; + _listener.afterChanged(this, C__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java index bb788e97..ed09389d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java @@ -37,6 +37,7 @@ public test.lowercasemessage.A.B setA1(test.lowercasemessage.A value) { protected final void internalSetA1(test.lowercasemessage.A value) { _listener.beforeSet(this, A_1__PROP, value); _a1 = value; + _listener.afterChanged(this, A_1__PROP); } @Override @@ -59,6 +60,7 @@ public test.lowercasemessage.A.B setB1(test.lowercasemessage.A.B value) { protected final void internalSetB1(test.lowercasemessage.A.B value) { _listener.beforeSet(this, B_1__PROP, value); _b1 = value; + _listener.afterChanged(this, B_1__PROP); } @Override @@ -336,6 +338,7 @@ public test.lowercasemessage.A setA1(test.lowercasemessage.A value) { protected final void internalSetA1(test.lowercasemessage.A value) { _listener.beforeSet(this, A_1__PROP, value); _a1 = value; + _listener.afterChanged(this, A_1__PROP); } @Override @@ -358,6 +361,7 @@ public test.lowercasemessage.A setB1(test.lowercasemessage.A.B value) { protected final void internalSetB1(test.lowercasemessage.A.B value) { _listener.beforeSet(this, B_1__PROP, value); _b1 = value; + _listener.afterChanged(this, B_1__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java index 9ff46ae6..1c49fba3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java @@ -15,6 +15,11 @@ protected void beforeAdd(String index, test.maptype.data.Project element) { protected void afterRemove(String index, test.maptype.data.Project element) { _listener.afterRemove(MyMessage_Impl.this, PROJECTS__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(MyMessage_Impl.this, PROJECTS__PROP); + } }; private final java.util.Map _rating = new de.haumacher.msgbuf.util.ReferenceMap() { @@ -27,6 +32,11 @@ protected void beforeAdd(Integer index, String element) { protected void afterRemove(Integer index, String element) { _listener.afterRemove(MyMessage_Impl.this, RATING__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(MyMessage_Impl.this, RATING__PROP); + } }; /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java index 35cbe943..9a10186f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java @@ -33,6 +33,7 @@ public test.maptype.data.Project setName(String value) { protected final void internalSetName(String value) { _listener.beforeSet(this, NAME__PROP, value); _name = value; + _listener.afterChanged(this, NAME__PROP); } @Override @@ -50,6 +51,7 @@ public test.maptype.data.Project setCost(double value) { protected final void internalSetCost(double value) { _listener.beforeSet(this, COST__PROP, value); _cost = value; + _listener.afterChanged(this, COST__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java index c6ec715f..c7b40a7c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java @@ -23,6 +23,11 @@ protected void beforeAdd(int index, String element) { protected void afterRemove(int index, String element) { _listener.afterRemove(Result_Impl.this, SNIPPETS__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(Result_Impl.this, SNIPPETS__PROP); + } }; /** @@ -49,6 +54,7 @@ public test.nested.data.SearchResponse.Result setUrl(String value) { protected final void internalSetUrl(String value) { _listener.beforeSet(this, URL__PROP, value); _url = value; + _listener.afterChanged(this, URL__PROP); } @Override @@ -66,6 +72,7 @@ public test.nested.data.SearchResponse.Result setTitle(String value) { protected final void internalSetTitle(String value) { _listener.beforeSet(this, TITLE__PROP, value); _title = value; + _listener.afterChanged(this, TITLE__PROP); } @Override @@ -394,6 +401,11 @@ protected void beforeAdd(int index, test.nested.data.SearchResponse.Result eleme protected void afterRemove(int index, test.nested.data.SearchResponse.Result element) { _listener.afterRemove(SearchResponse_Impl.this, RESULTS__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(SearchResponse_Impl.this, RESULTS__PROP); + } }; /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java index 58fba6d9..4d5dc6d9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java @@ -75,6 +75,7 @@ public test.nointerfaces.Car setWheel1(test.nointerfaces.Circle value) { protected final void internalSetWheel1(test.nointerfaces.Circle value) { _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; + _listener.afterChanged(this, WHEEL_1__PROP); } /** @@ -103,6 +104,7 @@ public test.nointerfaces.Car setWheel2(test.nointerfaces.Circle value) { protected final void internalSetWheel2(test.nointerfaces.Circle value) { _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; + _listener.afterChanged(this, WHEEL_2__PROP); } /** @@ -131,6 +133,7 @@ public test.nointerfaces.Car setBody(test.nointerfaces.Rectangle value) { protected final void internalSetBody(test.nointerfaces.Rectangle value) { _listener.beforeSet(this, BODY__PROP, value); _body = value; + _listener.afterChanged(this, BODY__PROP); } /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java index 6e221c6d..1eefb6cb 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java @@ -59,6 +59,7 @@ public test.nointerfaces.Circle setRadius(int value) { protected final void internalSetRadius(int value) { _listener.beforeSet(this, RADIUS__PROP, value); _radius = value; + _listener.afterChanged(this, RADIUS__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java index f56b90ec..44a5a681 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java @@ -34,6 +34,11 @@ protected void beforeAdd(int index, test.nointerfaces.Shape element) { protected void afterRemove(int index, test.nointerfaces.Shape element) { _listener.afterRemove(Group.this, SHAPES__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(Group.this, SHAPES__PROP); + } }; /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java index bdb69f94..cbe8cfad 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java @@ -73,6 +73,7 @@ public test.nointerfaces.Rectangle setWidth(int value) { protected final void internalSetWidth(int value) { _listener.beforeSet(this, WIDTH__PROP, value); _width = value; + _listener.afterChanged(this, WIDTH__PROP); } /** @@ -96,6 +97,7 @@ public test.nointerfaces.Rectangle setHeight(int value) { protected final void internalSetHeight(int value) { _listener.beforeSet(this, HEIGHT__PROP, value); _height = value; + _listener.afterChanged(this, HEIGHT__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java index aca9e971..b4ab54e0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java @@ -79,6 +79,7 @@ public test.nointerfaces.Shape setXCoordinate(int value) { protected final void internalSetXCoordinate(int value) { _listener.beforeSet(this, X_COORDINATE__PROP, value); _xCoordinate = value; + _listener.afterChanged(this, X_COORDINATE__PROP); } /** @@ -100,6 +101,7 @@ public test.nointerfaces.Shape setYCoordinate(int value) { protected final void internalSetYCoordinate(int value) { _listener.beforeSet(this, Y_COORDINATE__PROP, value); _yCoordinate = value; + _listener.afterChanged(this, Y_COORDINATE__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java index 30fa9f04..d6dab94f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java @@ -59,6 +59,7 @@ public test.nointerfaces.SimpleType setStr(String value) { protected final void internalSetStr(String value) { _listener.beforeSet(this, STR__PROP, value); _str = value; + _listener.afterChanged(this, STR__PROP); } /** @@ -80,6 +81,7 @@ public test.nointerfaces.SimpleType setX(int value) { protected final void internalSetX(int value) { _listener.beforeSet(this, X__PROP, value); _x = value; + _listener.afterChanged(this, X__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java index 484a4ca2..4658c329 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java @@ -40,6 +40,7 @@ public test.nojson.Car setWheel1(test.nojson.Circle value) { protected final void internalSetWheel1(test.nojson.Circle value) { _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; + _listener.afterChanged(this, WHEEL_1__PROP); } @Override @@ -62,6 +63,7 @@ public test.nojson.Car setWheel2(test.nojson.Circle value) { protected final void internalSetWheel2(test.nojson.Circle value) { _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; + _listener.afterChanged(this, WHEEL_2__PROP); } @Override @@ -84,6 +86,7 @@ public test.nojson.Car setBody(test.nojson.Rectangle value) { protected final void internalSetBody(test.nojson.Rectangle value) { _listener.beforeSet(this, BODY__PROP, value); _body = value; + _listener.afterChanged(this, BODY__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java index 97ced9b2..4fa75538 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java @@ -36,6 +36,7 @@ public test.nojson.Circle setRadius(int value) { protected final void internalSetRadius(int value) { _listener.beforeSet(this, RADIUS__PROP, value); _radius = value; + _listener.afterChanged(this, RADIUS__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java index 9cb81526..f69809ca 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java @@ -15,6 +15,11 @@ protected void beforeAdd(int index, test.nojson.Shape element) { protected void afterRemove(int index, test.nojson.Shape element) { _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(Group_Impl.this, SHAPES__PROP); + } }; /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java index 51c03ae5..5f5dcd37 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java @@ -38,6 +38,7 @@ public test.nojson.Rectangle setWidth(int value) { protected final void internalSetWidth(int value) { _listener.beforeSet(this, WIDTH__PROP, value); _width = value; + _listener.afterChanged(this, WIDTH__PROP); } @Override @@ -55,6 +56,7 @@ public test.nojson.Rectangle setHeight(int value) { protected final void internalSetHeight(int value) { _listener.beforeSet(this, HEIGHT__PROP, value); _height = value; + _listener.afterChanged(this, HEIGHT__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java index bc999dd4..3af9178c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java @@ -31,6 +31,7 @@ public test.nojson.Shape setXCoordinate(int value) { protected final void internalSetXCoordinate(int value) { _listener.beforeSet(this, X_COORDINATE__PROP, value); _xCoordinate = value; + _listener.afterChanged(this, X_COORDINATE__PROP); } @Override @@ -48,6 +49,7 @@ public test.nojson.Shape setYCoordinate(int value) { protected final void internalSetYCoordinate(int value) { _listener.beforeSet(this, Y_COORDINATE__PROP, value); _yCoordinate = value; + _listener.afterChanged(this, Y_COORDINATE__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java index 413ce01b..1e254093 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java @@ -33,6 +33,7 @@ public test.nojson.SimpleType setStr(String value) { protected final void internalSetStr(String value) { _listener.beforeSet(this, STR__PROP, value); _str = value; + _listener.afterChanged(this, STR__PROP); } @Override @@ -50,6 +51,7 @@ public test.nojson.SimpleType setX(int value) { protected final void internalSetX(int value) { _listener.beforeSet(this, X__PROP, value); _x = value; + _listener.afterChanged(this, X__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java index f76a304e..61a9e57e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java @@ -35,6 +35,7 @@ public test.notypekind.Car setWheel1(test.notypekind.Circle value) { protected final void internalSetWheel1(test.notypekind.Circle value) { _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; + _listener.afterChanged(this, WHEEL_1__PROP); } @Override @@ -57,6 +58,7 @@ public test.notypekind.Car setWheel2(test.notypekind.Circle value) { protected final void internalSetWheel2(test.notypekind.Circle value) { _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; + _listener.afterChanged(this, WHEEL_2__PROP); } @Override @@ -79,6 +81,7 @@ public test.notypekind.Car setBody(test.notypekind.Rectangle value) { protected final void internalSetBody(test.notypekind.Rectangle value) { _listener.beforeSet(this, BODY__PROP, value); _body = value; + _listener.afterChanged(this, BODY__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java index d4960c65..7d85380f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java @@ -31,6 +31,7 @@ public test.notypekind.Circle setRadius(int value) { protected final void internalSetRadius(int value) { _listener.beforeSet(this, RADIUS__PROP, value); _radius = value; + _listener.afterChanged(this, RADIUS__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java index 37f3ef66..d2dfe9b4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java @@ -15,6 +15,11 @@ protected void beforeAdd(int index, test.notypekind.Shape element) { protected void afterRemove(int index, test.notypekind.Shape element) { _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(Group_Impl.this, SHAPES__PROP); + } }; /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java index 822b11f4..41b0d6bc 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java @@ -33,6 +33,7 @@ public test.notypekind.Rectangle setWidth(int value) { protected final void internalSetWidth(int value) { _listener.beforeSet(this, WIDTH__PROP, value); _width = value; + _listener.afterChanged(this, WIDTH__PROP); } @Override @@ -50,6 +51,7 @@ public test.notypekind.Rectangle setHeight(int value) { protected final void internalSetHeight(int value) { _listener.beforeSet(this, HEIGHT__PROP, value); _height = value; + _listener.afterChanged(this, HEIGHT__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java index 0d7500ed..d4e110ef 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java @@ -31,6 +31,7 @@ public test.notypekind.Shape setXCoordinate(int value) { protected final void internalSetXCoordinate(int value) { _listener.beforeSet(this, X_COORDINATE__PROP, value); _xCoordinate = value; + _listener.afterChanged(this, X_COORDINATE__PROP); } @Override @@ -48,6 +49,7 @@ public test.notypekind.Shape setYCoordinate(int value) { protected final void internalSetYCoordinate(int value) { _listener.beforeSet(this, Y_COORDINATE__PROP, value); _yCoordinate = value; + _listener.afterChanged(this, Y_COORDINATE__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java index b1c3d7ae..6af30e36 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java @@ -33,6 +33,7 @@ public test.notypekind.SimpleType setStr(String value) { protected final void internalSetStr(String value) { _listener.beforeSet(this, STR__PROP, value); _str = value; + _listener.afterChanged(this, STR__PROP); } @Override @@ -50,6 +51,7 @@ public test.notypekind.SimpleType setX(int value) { protected final void internalSetX(int value) { _listener.beforeSet(this, X__PROP, value); _x = value; + _listener.afterChanged(this, X__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java index ecedb3d5..26183a08 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java @@ -40,6 +40,7 @@ public test.novisit.Car setWheel1(test.novisit.Circle value) { protected final void internalSetWheel1(test.novisit.Circle value) { _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; + _listener.afterChanged(this, WHEEL_1__PROP); } @Override @@ -62,6 +63,7 @@ public test.novisit.Car setWheel2(test.novisit.Circle value) { protected final void internalSetWheel2(test.novisit.Circle value) { _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; + _listener.afterChanged(this, WHEEL_2__PROP); } @Override @@ -84,6 +86,7 @@ public test.novisit.Car setBody(test.novisit.Rectangle value) { protected final void internalSetBody(test.novisit.Rectangle value) { _listener.beforeSet(this, BODY__PROP, value); _body = value; + _listener.afterChanged(this, BODY__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java index 78303126..7c2fb2e2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java @@ -36,6 +36,7 @@ public test.novisit.Circle setRadius(int value) { protected final void internalSetRadius(int value) { _listener.beforeSet(this, RADIUS__PROP, value); _radius = value; + _listener.afterChanged(this, RADIUS__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java index 4fbc0ca4..326d0227 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java @@ -15,6 +15,11 @@ protected void beforeAdd(int index, test.novisit.Shape element) { protected void afterRemove(int index, test.novisit.Shape element) { _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(Group_Impl.this, SHAPES__PROP); + } }; /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java index 6b12557b..c3a9cb41 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java @@ -38,6 +38,7 @@ public test.novisit.Rectangle setWidth(int value) { protected final void internalSetWidth(int value) { _listener.beforeSet(this, WIDTH__PROP, value); _width = value; + _listener.afterChanged(this, WIDTH__PROP); } @Override @@ -55,6 +56,7 @@ public test.novisit.Rectangle setHeight(int value) { protected final void internalSetHeight(int value) { _listener.beforeSet(this, HEIGHT__PROP, value); _height = value; + _listener.afterChanged(this, HEIGHT__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java index 003dc0ab..626c3d75 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java @@ -31,6 +31,7 @@ public test.novisit.Shape setXCoordinate(int value) { protected final void internalSetXCoordinate(int value) { _listener.beforeSet(this, X_COORDINATE__PROP, value); _xCoordinate = value; + _listener.afterChanged(this, X_COORDINATE__PROP); } @Override @@ -48,6 +49,7 @@ public test.novisit.Shape setYCoordinate(int value) { protected final void internalSetYCoordinate(int value) { _listener.beforeSet(this, Y_COORDINATE__PROP, value); _yCoordinate = value; + _listener.afterChanged(this, Y_COORDINATE__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java index 34c0b454..a372fc24 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java @@ -33,6 +33,7 @@ public test.novisit.SimpleType setStr(String value) { protected final void internalSetStr(String value) { _listener.beforeSet(this, STR__PROP, value); _str = value; + _listener.afterChanged(this, STR__PROP); } @Override @@ -50,6 +51,7 @@ public test.novisit.SimpleType setX(int value) { protected final void internalSetX(int value) { _listener.beforeSet(this, X__PROP, value); _x = value; + _listener.afterChanged(this, X__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java index 6f74ff1e..88afb5d4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java @@ -40,6 +40,7 @@ public test.novisitexceptions.Car setWheel1(test.novisitexceptions.Circle value) protected final void internalSetWheel1(test.novisitexceptions.Circle value) { _listener.beforeSet(this, WHEEL_1__PROP, value); _wheel1 = value; + _listener.afterChanged(this, WHEEL_1__PROP); } @Override @@ -62,6 +63,7 @@ public test.novisitexceptions.Car setWheel2(test.novisitexceptions.Circle value) protected final void internalSetWheel2(test.novisitexceptions.Circle value) { _listener.beforeSet(this, WHEEL_2__PROP, value); _wheel2 = value; + _listener.afterChanged(this, WHEEL_2__PROP); } @Override @@ -84,6 +86,7 @@ public test.novisitexceptions.Car setBody(test.novisitexceptions.Rectangle value protected final void internalSetBody(test.novisitexceptions.Rectangle value) { _listener.beforeSet(this, BODY__PROP, value); _body = value; + _listener.afterChanged(this, BODY__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java index 5fe6fe37..f52cd8e9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java @@ -36,6 +36,7 @@ public test.novisitexceptions.Circle setRadius(int value) { protected final void internalSetRadius(int value) { _listener.beforeSet(this, RADIUS__PROP, value); _radius = value; + _listener.afterChanged(this, RADIUS__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java index 083b2d86..a5354b25 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java @@ -15,6 +15,11 @@ protected void beforeAdd(int index, test.novisitexceptions.Shape element) { protected void afterRemove(int index, test.novisitexceptions.Shape element) { _listener.afterRemove(Group_Impl.this, SHAPES__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(Group_Impl.this, SHAPES__PROP); + } }; /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java index b4cd7e30..81f99997 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java @@ -38,6 +38,7 @@ public test.novisitexceptions.Rectangle setWidth(int value) { protected final void internalSetWidth(int value) { _listener.beforeSet(this, WIDTH__PROP, value); _width = value; + _listener.afterChanged(this, WIDTH__PROP); } @Override @@ -55,6 +56,7 @@ public test.novisitexceptions.Rectangle setHeight(int value) { protected final void internalSetHeight(int value) { _listener.beforeSet(this, HEIGHT__PROP, value); _height = value; + _listener.afterChanged(this, HEIGHT__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java index a551318a..42eb4002 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java @@ -31,6 +31,7 @@ public test.novisitexceptions.Shape setXCoordinate(int value) { protected final void internalSetXCoordinate(int value) { _listener.beforeSet(this, X_COORDINATE__PROP, value); _xCoordinate = value; + _listener.afterChanged(this, X_COORDINATE__PROP); } @Override @@ -48,6 +49,7 @@ public test.novisitexceptions.Shape setYCoordinate(int value) { protected final void internalSetYCoordinate(int value) { _listener.beforeSet(this, Y_COORDINATE__PROP, value); _yCoordinate = value; + _listener.afterChanged(this, Y_COORDINATE__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java index 32a25617..a44d55da 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java @@ -33,6 +33,7 @@ public test.novisitexceptions.SimpleType setStr(String value) { protected final void internalSetStr(String value) { _listener.beforeSet(this, STR__PROP, value); _str = value; + _listener.afterChanged(this, STR__PROP); } @Override @@ -50,6 +51,7 @@ public test.novisitexceptions.SimpleType setX(int value) { protected final void internalSetX(int value) { _listener.beforeSet(this, X__PROP, value); _x = value; + _listener.afterChanged(this, X__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java index dbdd9ca2..f34e0246 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java @@ -19,6 +19,11 @@ protected void beforeAdd(int index, test.references.data.A element) { protected void afterRemove(int index, test.references.data.A element) { _listener.afterRemove(A_Impl.this, CHILDREN__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(A_Impl.this, CHILDREN__PROP); + } }; private final java.util.List _bs = new de.haumacher.msgbuf.util.ReferenceList() { @@ -35,6 +40,11 @@ protected void afterRemove(int index, test.references.data.B element) { removed.removeInBs(A_Impl.this); _listener.afterRemove(A_Impl.this, BS__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(A_Impl.this, BS__PROP); + } }; private test.references.data.B _b = null; @@ -55,6 +65,11 @@ protected void afterRemove(int index, test.references.data.A element) { removed.removeInOthers(A_Impl.this); _listener.afterRemove(A_Impl.this, OTHERS__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(A_Impl.this, OTHERS__PROP); + } }; private final java.util.List _inOther = new de.haumacher.msgbuf.util.ReferenceList() { @@ -67,6 +82,11 @@ protected void beforeAdd(int index, test.references.data.A element) { protected void afterRemove(int index, test.references.data.A element) { _listener.afterRemove(A_Impl.this, IN_OTHER__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(A_Impl.this, IN_OTHER__PROP); + } }; private final java.util.List _inOthers = new de.haumacher.msgbuf.util.ReferenceList() { @@ -79,6 +99,11 @@ protected void beforeAdd(int index, test.references.data.A element) { protected void afterRemove(int index, test.references.data.A element) { _listener.afterRemove(A_Impl.this, IN_OTHERS__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(A_Impl.this, IN_OTHERS__PROP); + } }; /** @@ -105,6 +130,7 @@ public test.references.data.A setName(String value) { protected final void internalSetName(String value) { _listener.beforeSet(this, NAME__PROP, value); _name = value; + _listener.afterChanged(this, NAME__PROP); } @Override @@ -122,6 +148,7 @@ public test.references.data.A setContents(test.references.data.A value) { protected final void internalSetContents(test.references.data.A value) { _listener.beforeSet(this, CONTENTS__PROP, value); _contents = value; + _listener.afterChanged(this, CONTENTS__PROP); } @Override @@ -220,6 +247,7 @@ protected final void internalSetB(test.references.data.B value) { if (after != null) { after.addInB(this); } + _listener.afterChanged(this, B__PROP); } @Override @@ -250,6 +278,7 @@ protected final void internalSetOther(test.references.data.A value) { if (after != null) { after.addInOther(this); } + _listener.afterChanged(this, OTHER__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java index 8fb21331..093a15b0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java @@ -17,6 +17,11 @@ protected void beforeAdd(int index, test.references.data.A element) { protected void afterRemove(int index, test.references.data.A element) { _listener.afterRemove(B_Impl.this, IN_BS__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(B_Impl.this, IN_BS__PROP); + } }; private final java.util.List _inB = new de.haumacher.msgbuf.util.ReferenceList() { @@ -29,6 +34,11 @@ protected void beforeAdd(int index, test.references.data.A element) { protected void afterRemove(int index, test.references.data.A element) { _listener.afterRemove(B_Impl.this, IN_B__PROP, index, element); } + + @Override + protected void afterChanged() { + _listener.afterChanged(B_Impl.this, IN_B__PROP); + } }; /** @@ -55,6 +65,7 @@ public test.references.data.B setName(String value) { protected final void internalSetName(String value) { _listener.beforeSet(this, NAME__PROP, value); _name = value; + _listener.afterChanged(this, NAME__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java index 8577ff30..d03496bb 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java @@ -35,6 +35,7 @@ public test.types.data.SearchRequest setQuery(String value) { protected final void internalSetQuery(String value) { _listener.beforeSet(this, QUERY__PROP, value); _query = value; + _listener.afterChanged(this, QUERY__PROP); } @Override @@ -52,6 +53,7 @@ public test.types.data.SearchRequest setPageNumber(int value) { protected final void internalSetPageNumber(int value) { _listener.beforeSet(this, PAGE_NUMBER__PROP, value); _pageNumber = value; + _listener.afterChanged(this, PAGE_NUMBER__PROP); } @Override @@ -69,6 +71,7 @@ public test.types.data.SearchRequest setResultPerPage(int value) { protected final void internalSetResultPerPage(int value) { _listener.beforeSet(this, RESULT_PER_PAGE__PROP, value); _resultPerPage = value; + _listener.afterChanged(this, RESULT_PER_PAGE__PROP); } protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java index b6fa745a..cd8d1bec 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java @@ -36,6 +36,7 @@ public test.underscorename.AnnotatedMessage setAnnotatedField(String value) { protected final void internalSetAnnotatedField(String value) { _listener.beforeSet(this, ANNOTATED_FIELD__PROP, value); _annotatedField = value; + _listener.afterChanged(this, ANNOTATED_FIELD__PROP); } @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java index c9b4aeea..cdf357f0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java @@ -36,6 +36,7 @@ public test.underscorename.SomeName setMyField(String value) { protected final void internalSetMyField(String value) { _listener.beforeSet(this, MY_FIELD__PROP, value); _myField = value; + _listener.afterChanged(this, MY_FIELD__PROP); } @Override From 720f764f4b68078c116fb398ee7a5956355921e7 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 6 May 2025 11:26:23 +0200 Subject: [PATCH 108/207] [maven-release-plugin] prepare release msgbuf-api-1.1.8 --- de.haumacher.msgbuf.generator/pom.xml | 6 +++--- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 0c0029f5..2a99d7e0 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.8-SNAPSHOT + 1.1.8 msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.8-SNAPSHOT + 1.1.8 @@ -125,7 +125,7 @@ - + diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 0079e859..a0f576f3 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.8-SNAPSHOT + 1.1.8 msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index f4a8cda3..3cf80cad 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.8-SNAPSHOT + 1.1.8 msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.8-SNAPSHOT + 1.1.8 diff --git a/pom.xml b/pom.xml index 9ee12537..f4b1932c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.8-SNAPSHOT + 1.1.8 pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - HEAD + msgbuf-api-1.1.8 From de9069b6d0d4c5ea8ca4952180e2b1e237584f7d Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 6 May 2025 11:26:25 +0200 Subject: [PATCH 109/207] [maven-release-plugin] prepare for next development iteration --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 2a99d7e0..7aba0ee7 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.8 + 1.1.9-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.8 + 1.1.9-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index a0f576f3..90cdf2bb 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.8 + 1.1.9-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 3cf80cad..259c3d2d 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.8 + 1.1.9-SNAPSHOT msgbuf-generator-maven-plugin @@ -32,7 +32,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.8 + 1.1.9-SNAPSHOT diff --git a/pom.xml b/pom.xml index f4b1932c..227e51af 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.8 + 1.1.9-SNAPSHOT pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - msgbuf-api-1.1.8 + HEAD From 4d32bb1d0de2dd486d9eae82b09333a0a729c346 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 6 May 2025 11:58:52 +0200 Subject: [PATCH 110/207] Upated version in README to 1.1.8. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 074f204c..42d426d1 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ In contrast to `protobuf`, `msgbuf` supports: de.haumacher.msgbuf msgbuf-api - 1.1.7 + 1.1.8 ``` @@ -32,7 +32,7 @@ To the `build/plugins` section add: de.haumacher.msgbuf msgbuf-generator-maven-plugin - 1.1.7 + 1.1.8 From 74af31050b9f5adda193017b2003d3539d4c099b Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 6 May 2025 11:59:52 +0200 Subject: [PATCH 111/207] Fixed global option syntax in README. --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 42d426d1..ede93b13 100644 --- a/README.md +++ b/README.md @@ -90,40 +90,40 @@ Passing these definitions to the `msgbuf` compiler gives you a class hierarchy w ## Global protocol options -### `@NoJson` +### `option NoJson` Disables generation of read and write methods for the JSON format. -### `@NoBinary` +### `option NoBinary` Disables generation of read and write methods for binary format. -### `@NoXml` +### `option NoXml` Disables generation of read and write methods for XML format. -### `@NoXmlNames` +### `option NoXmlNames` Disables generation of constants for the XML format. -### `@NoInterfaces` +### `option NoInterfaces` Disables generation interfaces for data classes. Normally, data classes are represented by a Java interface. This enables multiple inheritance for data classes. To reduce the amout of generated code, this can be disabled for simple cases, where no multiple inheritance is required. -### `@NoListener` +### `option NoListener` Disables generation of listener interfaces and corresponding registration methods. Add this options, if observing data classes for changes is not required. -### `@NoReflection` +### `option NoReflection` Disables generation of reflective access methods that allow access to properties through their property names. -### `@NoVisitor` +### `option NoVisitor` Disables generation of visitor interfaces and visit methods. -### `@NoVisitorExceptions` +### `option NoVisitorExceptions` Produces visitor interfaces that cannot throw declared exceptions. -### `@NoTypeKind` +### `option NoTypeKind` Suppresses the type kind enumeration for a data class hierarchy. -### `@SharedGraph` +### `option SharedGraph` Allows to handle multiple synchronized instances of a data class graph. Each graph can be observed for changes. Changes generate synchronization messages to keep other instances of the same shared graph up to date. With this option, a shared graph can be instantiated on a server, transfered to a client while keeping the state in sync when changes From e4b2e7472ec95ddd5d199fa9047eff285fd1903a Mon Sep 17 00:00:00 2001 From: Daniel Busche Date: Tue, 2 Sep 2025 13:55:16 +0200 Subject: [PATCH 112/207] "beforeChange()" must be called when the changes are empty, i.e. on the first change. --- .../src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java index b5bed272..65d2c39e 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/DefaultScope.java @@ -334,7 +334,7 @@ private void foreachCommand(Transmission fun) throws IOException { } private Map changes(SharedGraphNode obj) { - if (!_changes.isEmpty()) { + if (_changes.isEmpty()) { beforeChange(); } return _changes.computeIfAbsent(obj, NEW_MAP); From 61713fd329aaba5e5e007fab0df8a06d45d0a368 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 2 Sep 2025 14:28:01 +0200 Subject: [PATCH 113/207] Added maven plugin project name. --- msgbuf-generator-maven-plugin/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 259c3d2d..490bcd08 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -14,6 +14,7 @@ maven-plugin + MsgBuf Maven Plugin Maven Plugin for generating classes with the MsgBuf compiler. @@ -144,4 +145,4 @@ - \ No newline at end of file + From 80d1136a23eeffb55e15f0b7148b5092c581de04 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 2 Sep 2025 14:29:28 +0200 Subject: [PATCH 114/207] [maven-release-plugin] prepare release msgbuf-api-1.1.9 --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 7aba0ee7..9c1bc8ad 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.9-SNAPSHOT + 1.1.9 msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.9-SNAPSHOT + 1.1.9 diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 90cdf2bb..3b672174 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.9-SNAPSHOT + 1.1.9 msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 490bcd08..d1ba8552 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.9-SNAPSHOT + 1.1.9 msgbuf-generator-maven-plugin @@ -33,7 +33,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.9-SNAPSHOT + 1.1.9 diff --git a/pom.xml b/pom.xml index 227e51af..ae960830 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.9-SNAPSHOT + 1.1.9 pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - HEAD + msgbuf-api-1.1.9 From 28b516ef0bf0a4231c90bc6def5516f9078c96f2 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Tue, 2 Sep 2025 14:29:31 +0200 Subject: [PATCH 115/207] [maven-release-plugin] prepare for next development iteration --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 9c1bc8ad..4e7df110 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.9 + 1.1.10-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.9 + 1.1.10-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 3b672174..88d1f636 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.9 + 1.1.10-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index d1ba8552..60d848bc 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.9 + 1.1.10-SNAPSHOT msgbuf-generator-maven-plugin @@ -33,7 +33,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.9 + 1.1.10-SNAPSHOT diff --git a/pom.xml b/pom.xml index ae960830..9aa1ac9c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.9 + 1.1.10-SNAPSHOT pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - msgbuf-api-1.1.9 + HEAD From df2bccb24c55436152a1a22c63518637292a512d Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 3 Sep 2025 16:08:07 +0200 Subject: [PATCH 116/207] Fixed missing inheritance of properties and transient properties. --- .../msgbuf/generator/MessageGenerator.java | 45 ++- .../data/impl/SearchRequest_Impl.java | 19 +- .../model/impl/MyContainer_Impl.java | 19 +- .../container/model/impl/MyContent_Impl.java | 19 +- .../nointerfaces/model/MyContainer.java | 19 +- .../nointerfaces/model/MyContent.java | 19 +- .../test/defaultvalue/data/impl/A_Impl.java | 19 +- .../embedded/data/impl/Container_Impl.java | 19 +- .../data/impl/EmbeddingContainer_Impl.java | 19 +- .../impl/EmbeddingSingleContainer_Impl.java | 19 +- .../data/impl/SingleContainer_Impl.java | 19 +- .../data/impl/SearchRequest_Impl.java | 19 +- .../java/test/graph/data/impl/Car_Impl.java | 25 +- .../test/graph/data/impl/Circle_Impl.java | 27 +- .../java/test/graph/data/impl/Group_Impl.java | 25 +- .../test/graph/data/impl/Rectangle_Impl.java | 27 +- .../java/test/graph/data/impl/Shape_Impl.java | 19 +- .../test/graph/data/impl/SimpleType_Impl.java | 19 +- .../test/hierarchy/data/impl/Car_Impl.java | 27 +- .../test/hierarchy/data/impl/Circle_Impl.java | 27 +- .../test/hierarchy/data/impl/Group_Impl.java | 25 +- .../hierarchy/data/impl/Optional_Impl.java | 25 +- .../hierarchy/data/impl/Rectangle_Impl.java | 25 +- .../test/hierarchy/data/impl/Shape_Impl.java | 19 +- .../hierarchy/data/impl/SimpleType_Impl.java | 19 +- .../java/test/innertypeclash/impl/A_Impl.java | 19 +- .../java/test/innertypeclash/impl/B_Impl.java | 19 +- .../test/lowercasemessage/impl/A_Impl.java | 38 ++- .../maptype/data/impl/MyMessage_Impl.java | 19 +- .../test/maptype/data/impl/Project_Impl.java | 19 +- .../nested/data/impl/SearchResponse_Impl.java | 38 ++- .../src/test/java/test/nointerfaces/Car.java | 27 +- .../test/java/test/nointerfaces/Circle.java | 27 +- .../test/java/test/nointerfaces/Group.java | 27 +- .../java/test/nointerfaces/Rectangle.java | 27 +- .../test/java/test/nointerfaces/Shape.java | 19 +- .../java/test/nointerfaces/SimpleType.java | 19 +- .../test/java/test/nojson/impl/Car_Impl.java | 27 +- .../java/test/nojson/impl/Circle_Impl.java | 27 +- .../java/test/nojson/impl/Group_Impl.java | 27 +- .../java/test/nojson/impl/Rectangle_Impl.java | 27 +- .../java/test/nojson/impl/Shape_Impl.java | 19 +- .../test/nojson/impl/SimpleType_Impl.java | 19 +- .../java/test/nolistener/impl/Car_Impl.java | 27 +- .../test/nolistener/impl/Circle_Impl.java | 27 +- .../java/test/nolistener/impl/Group_Impl.java | 25 +- .../test/nolistener/impl/Rectangle_Impl.java | 27 +- .../java/test/nolistener/impl/Shape_Impl.java | 19 +- .../test/nolistener/impl/SimpleType_Impl.java | 19 +- .../java/test/notypekind/impl/Car_Impl.java | 27 +- .../test/notypekind/impl/Circle_Impl.java | 27 +- .../java/test/notypekind/impl/Group_Impl.java | 25 +- .../test/notypekind/impl/Rectangle_Impl.java | 27 +- .../java/test/notypekind/impl/Shape_Impl.java | 19 +- .../test/notypekind/impl/SimpleType_Impl.java | 19 +- .../test/java/test/novisit/impl/Car_Impl.java | 27 +- .../java/test/novisit/impl/Circle_Impl.java | 27 +- .../java/test/novisit/impl/Group_Impl.java | 25 +- .../test/novisit/impl/Rectangle_Impl.java | 27 +- .../java/test/novisit/impl/Shape_Impl.java | 19 +- .../test/novisit/impl/SimpleType_Impl.java | 19 +- .../test/novisitexceptions/impl/Car_Impl.java | 27 +- .../novisitexceptions/impl/Circle_Impl.java | 27 +- .../novisitexceptions/impl/Group_Impl.java | 25 +- .../impl/Rectangle_Impl.java | 27 +- .../novisitexceptions/impl/Shape_Impl.java | 19 +- .../impl/SimpleType_Impl.java | 19 +- .../data/impl/NullableValues_Impl.java | 19 +- .../test/references/data/impl/A_Impl.java | 19 +- .../test/references/data/impl/B_Impl.java | 19 +- .../transientprops/TestTransientProps.java | 41 +++ .../test/java/test/transientprops/data/A.java | 83 +++++ .../test/java/test/transientprops/data/B.java | 65 ++++ .../test/java/test/transientprops/data/C.java | 71 +++++ .../test/transientprops/data/impl/A_Impl.java | 296 ++++++++++++++++++ .../test/transientprops/data/impl/B_Impl.java | 236 ++++++++++++++ .../test/transientprops/data/impl/C_Impl.java | 248 +++++++++++++++ .../transientprops/data/transientprops.proto | 16 + .../types/data/impl/SearchRequest_Impl.java | 19 +- .../impl/AnnotatedMessage_Impl.java | 19 +- .../underscorename/impl/SomeName_Impl.java | 19 +- 81 files changed, 2278 insertions(+), 475 deletions(-) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/transientprops/TestTransientProps.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/A.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/B.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/C.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/A_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/B_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/C_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/transientprops.proto diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 97b3700c..deb981c0 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -6,7 +6,7 @@ import static de.haumacher.msgbuf.generator.CodeConvention.*; import static de.haumacher.msgbuf.generator.DefaultValueGenerator.*; import static de.haumacher.msgbuf.generator.TypeGenerator.*; -import static de.haumacher.msgbuf.generator.util.CodeUtil.stringLiteral; +import static de.haumacher.msgbuf.generator.util.CodeUtil.*; import java.util.ArrayList; import java.util.List; @@ -1120,10 +1120,19 @@ private void jsonTypeDoc() { } private void reflectionPropertiesConstant() { + MessageDef anchestor = _def.getExtendedDef(); + while (anchestor != null && !hasFields(anchestor)) { + anchestor = anchestor.getExtendedDef(); + } + nl(); - line("private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList("); + if (anchestor != null) { + line("@SuppressWarnings(\"hiding\")"); + } + line("static final java.util.List PROPERTIES;"); + line("static {"); { - line("java.util.Arrays.asList("); + line("java.util.List local = java.util.Arrays.asList("); { boolean first = true; for (Field field : getFields()) { @@ -1135,15 +1144,34 @@ private void reflectionPropertiesConstant() { } lineStart(constant(field)); } - append("));"); + append(");"); nl(); } + + if (anchestor != null) { + line("java.util.List tmp = new java.util.ArrayList<>();"); + line("tmp.addAll(" + qImplName(anchestor) + ".PROPERTIES" + ");"); + line("tmp.addAll(local);"); + line("PROPERTIES = java.util.Collections.unmodifiableList(tmp);"); + } else { + line("PROPERTIES = java.util.Collections.unmodifiableList(local);"); + } } + line("}"); nl(); - line("private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>("); + if (anchestor != null) { + line("@SuppressWarnings(\"hiding\")"); + } + line("static final java.util.Set TRANSIENT_PROPERTIES;"); + line("static {"); { - line("java.util.Arrays.asList("); + line("java.util.HashSet tmp = new java.util.HashSet<>();"); + + if (anchestor != null) { + line("tmp.addAll(" + qImplName(anchestor) + ".TRANSIENT_PROPERTIES" + ");"); + } + line("tmp.addAll(java.util.Arrays.asList("); { boolean first = true; for (Field field : getFields()) { @@ -1161,10 +1189,13 @@ private void reflectionPropertiesConstant() { if (first) { lineStart(""); } - append(")));"); + append("));"); nl(); } + + line("TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp);"); } + line("}"); } private void reflectionProperties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java index 8b4b6698..99099464 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/comments/data/impl/SearchRequest_Impl.java @@ -101,15 +101,22 @@ public String jsonType() { return SEARCH_REQUEST__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( QUERY__PROP, PAGE_NUMBER__PROP, - RESULT_PER_PAGE__PROP)); + RESULT_PER_PAGE__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java index a38e7f36..95bb36a3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java @@ -336,19 +336,26 @@ public String jsonType() { return MY_CONTAINER__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( NAME__PROP, CONTENT_1__PROP, CONTENT_2__PROP, CONTENT_LIST__PROP, CONTENT_MAP__PROP, OTHER__PROP, - OTHERS__PROP)); + OTHERS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java index f789d5e5..b0fc6d0e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java @@ -91,14 +91,21 @@ public String jsonType() { return MY_CONTENT__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( CONTAINER__PROP, - NAME__PROP)); + NAME__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java index c196b9ba..ec8de9a7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java @@ -410,19 +410,26 @@ public String jsonType() { return MY_CONTAINER__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( NAME__PROP, CONTENT_1__PROP, CONTENT_2__PROP, CONTENT_LIST__PROP, CONTENT_MAP__PROP, OTHER__PROP, - OTHERS__PROP)); + OTHERS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java index 4dfafd72..df8cbdb3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java @@ -109,14 +109,21 @@ public String jsonType() { return MY_CONTENT__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( CONTAINER__PROP, - NAME__PROP)); + NAME__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java index b4eb81bf..da1eb262 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/defaultvalue/data/impl/A_Impl.java @@ -121,16 +121,23 @@ public String jsonType() { return A__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( S__PROP, X__PROP, Y__PROP, - STATE__PROP)); + STATE__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java index b27e3150..b4173f96 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/Container_Impl.java @@ -112,14 +112,21 @@ public String jsonType() { return CONTAINER__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( NAME__PROP, - CONTENTS__PROP)); + CONTENTS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java index 70e2ed38..886b3d40 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingContainer_Impl.java @@ -112,14 +112,21 @@ public String jsonType() { return EMBEDDING_CONTAINER__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( NAME__PROP, - CONTENTS__PROP)); + CONTENTS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java index fb5c2fc0..7a30ad3c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/EmbeddingSingleContainer_Impl.java @@ -86,14 +86,21 @@ public String jsonType() { return EMBEDDING_SINGLE_CONTAINER__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( NAME__PROP, - CONTENTS__PROP)); + CONTENTS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java index 7d0b32b0..d7f46f06 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/embedded/data/impl/SingleContainer_Impl.java @@ -86,14 +86,21 @@ public String jsonType() { return SINGLE_CONTAINER__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( NAME__PROP, - CONTENTS__PROP)); + CONTENTS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java index f39eb727..c5844f02 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumeration/data/impl/SearchRequest_Impl.java @@ -122,16 +122,23 @@ public String jsonType() { return SEARCH_REQUEST__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( QUERY__PROP, PAGE_NUMBER__PROP, RESULT_PER_PAGE__PROP, - CORPUS__PROP)); + CORPUS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java index c34890fc..333e1af2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Car_Impl.java @@ -111,15 +111,28 @@ public String jsonType() { return CAR__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WHEEL_1__PROP, WHEEL_2__PROP, - BODY__PROP)); + BODY__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.graph.data.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.graph.data.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java index 62d7241f..9f3876f3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Circle_Impl.java @@ -56,13 +56,26 @@ public String jsonType() { return CIRCLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - RADIUS__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + RADIUS__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.graph.data.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.graph.data.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java index e7ef44a8..4d9455c7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Group_Impl.java @@ -87,13 +87,26 @@ public String jsonType() { return GROUP__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - SHAPES__PROP)); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + SHAPES__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.graph.data.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.graph.data.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java index 66e990df..58dc7902 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Rectangle_Impl.java @@ -76,14 +76,27 @@ public String jsonType() { return RECTANGLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WIDTH__PROP, - HEIGHT__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + HEIGHT__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.graph.data.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.graph.data.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java index b6949acf..e3d43d96 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/Shape_Impl.java @@ -52,14 +52,21 @@ protected final void internalSetYCoordinate(int value) { _listener.afterChanged(this, Y_COORDINATE__PROP); } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( X_COORDINATE__PROP, - Y_COORDINATE__PROP)); + Y_COORDINATE__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java index a1eee0e8..c8eedaa5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/graph/data/impl/SimpleType_Impl.java @@ -59,14 +59,21 @@ public String jsonType() { return SIMPLE_TYPE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( STR__PROP, - X__PROP)); + X__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java index 0d99b561..74f9b10a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Car_Impl.java @@ -117,15 +117,28 @@ public String jsonType() { return CAR__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WHEEL_1__PROP, WHEEL_2__PROP, - BODY__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + BODY__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.hierarchy.data.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.hierarchy.data.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java index bec3fb66..6c5a3886 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Circle_Impl.java @@ -62,13 +62,26 @@ public String jsonType() { return CIRCLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - RADIUS__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + RADIUS__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.hierarchy.data.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.hierarchy.data.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java index c0741db3..f3cecea9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Group_Impl.java @@ -93,13 +93,26 @@ public String jsonType() { return GROUP__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - SHAPES__PROP)); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + SHAPES__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.hierarchy.data.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.hierarchy.data.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java index ec1d3eeb..f251129a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Optional_Impl.java @@ -87,14 +87,27 @@ public String jsonType() { return OPTIONAL__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( HIDDEN__PROP, - SHAPE__PROP)); + SHAPE__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.hierarchy.data.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.hierarchy.data.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java index ed534fb7..0f2b9bd0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Rectangle_Impl.java @@ -82,14 +82,27 @@ public String jsonType() { return RECTANGLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WIDTH__PROP, - HEIGHT__PROP)); + HEIGHT__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.hierarchy.data.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.hierarchy.data.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java index 34c479bc..83df47fd 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/Shape_Impl.java @@ -95,15 +95,22 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( X_COORDINATE__PROP, Y_COORDINATE__PROP, - COLOR__PROP)); + COLOR__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java index fd50ef72..b0e1842b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/impl/SimpleType_Impl.java @@ -81,14 +81,21 @@ public String jsonType() { return SIMPLE_TYPE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( STR__PROP, - X__PROP)); + X__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java index 45e2fd3f..28882ba9 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/A_Impl.java @@ -281,15 +281,22 @@ public String jsonType() { return A__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( AC__PROP, BC__PROP, - C__PROP)); + C__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java index 828270c3..bd53cf60 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/innertypeclash/impl/B_Impl.java @@ -281,15 +281,22 @@ public String jsonType() { return B__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( AC__PROP, BC__PROP, - C__PROP)); + C__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java index ed09389d..e52da6b6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/lowercasemessage/impl/A_Impl.java @@ -95,14 +95,21 @@ public String jsonType() { return B__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( A_1__PROP, - B_1__PROP)); + B_1__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { @@ -396,14 +403,21 @@ public String jsonType() { return A__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( A_1__PROP, - B_1__PROP)); + B_1__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java index 1c49fba3..8f6d657f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java @@ -149,14 +149,21 @@ public String jsonType() { return MY_MESSAGE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( PROJECTS__PROP, - RATING__PROP)); + RATING__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java index 9a10186f..aeb6fde4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/Project_Impl.java @@ -81,14 +81,21 @@ public String jsonType() { return PROJECT__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( NAME__PROP, - COST__PROP)); + COST__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java index c7b40a7c..221d6773 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/SearchResponse_Impl.java @@ -135,15 +135,22 @@ public String jsonType() { return RESULT__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( URL__PROP, TITLE__PROP, - SNIPPETS__PROP)); + SNIPPETS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { @@ -478,13 +485,20 @@ public String jsonType() { return SEARCH_RESPONSE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - RESULTS__PROP)); + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + RESULTS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java index 4d5dc6d9..0a93daa1 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Car.java @@ -160,15 +160,28 @@ public String jsonType() { return CAR__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WHEEL_1__PROP, WHEEL_2__PROP, - BODY__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + BODY__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nointerfaces.Shape.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nointerfaces.Shape.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java index 1eefb6cb..b01c4105 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Circle.java @@ -79,13 +79,26 @@ public String jsonType() { return CIRCLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - RADIUS__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + RADIUS__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nointerfaces.Shape.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nointerfaces.Shape.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java index 44a5a681..386166f8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Group.java @@ -118,13 +118,26 @@ public String jsonType() { return GROUP__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - SHAPES__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + SHAPES__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nointerfaces.Shape.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nointerfaces.Shape.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java index cbe8cfad..0fe71971 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Rectangle.java @@ -117,14 +117,27 @@ public String jsonType() { return RECTANGLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WIDTH__PROP, - HEIGHT__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + HEIGHT__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nointerfaces.Shape.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nointerfaces.Shape.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java index b4ab54e0..b332dda3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/Shape.java @@ -126,14 +126,21 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( X_COORDINATE__PROP, - Y_COORDINATE__PROP)); + Y_COORDINATE__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java index d6dab94f..5594dc6c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nointerfaces/SimpleType.java @@ -111,14 +111,21 @@ public String jsonType() { return SIMPLE_TYPE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( STR__PROP, - X__PROP)); + X__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java index 4658c329..37d124f3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Car_Impl.java @@ -111,15 +111,28 @@ public String jsonType() { return CAR__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WHEEL_1__PROP, WHEEL_2__PROP, - BODY__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + BODY__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nojson.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nojson.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java index 4fa75538..da581f14 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Circle_Impl.java @@ -56,13 +56,26 @@ public String jsonType() { return CIRCLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - RADIUS__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + RADIUS__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nojson.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nojson.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java index f69809ca..50434af4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Group_Impl.java @@ -87,13 +87,26 @@ public String jsonType() { return GROUP__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - SHAPES__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + SHAPES__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nojson.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nojson.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java index 5f5dcd37..d158f6f1 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Rectangle_Impl.java @@ -76,14 +76,27 @@ public String jsonType() { return RECTANGLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WIDTH__PROP, - HEIGHT__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + HEIGHT__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nojson.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nojson.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java index 3af9178c..03744ca7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/Shape_Impl.java @@ -74,14 +74,21 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( X_COORDINATE__PROP, - Y_COORDINATE__PROP)); + Y_COORDINATE__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java index 1e254093..4ae1f752 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nojson/impl/SimpleType_Impl.java @@ -81,14 +81,21 @@ public String jsonType() { return SIMPLE_TYPE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( STR__PROP, - X__PROP)); + X__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Car_Impl.java index fe4ececb..af23a111 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Car_Impl.java @@ -105,15 +105,28 @@ public String jsonType() { return CAR__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WHEEL_1__PROP, WHEEL_2__PROP, - BODY__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + BODY__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nolistener.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nolistener.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Circle_Impl.java index de2957f3..3924bb2d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Circle_Impl.java @@ -54,13 +54,26 @@ public String jsonType() { return CIRCLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - RADIUS__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + RADIUS__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nolistener.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nolistener.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java index 08b8ead4..1f1eef7a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Group_Impl.java @@ -72,13 +72,26 @@ public String jsonType() { return GROUP__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - SHAPES__PROP)); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + SHAPES__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nolistener.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nolistener.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Rectangle_Impl.java index 69314f90..50587c02 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Rectangle_Impl.java @@ -72,14 +72,27 @@ public String jsonType() { return RECTANGLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WIDTH__PROP, - HEIGHT__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + HEIGHT__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nolistener.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nolistener.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java index 35904cad..57f28e59 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/Shape_Impl.java @@ -48,14 +48,21 @@ protected final void internalSetYCoordinate(int value) { _yCoordinate = value; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( X_COORDINATE__PROP, - Y_COORDINATE__PROP)); + Y_COORDINATE__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/SimpleType_Impl.java index 6e3201d5..61356dce 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nolistener/impl/SimpleType_Impl.java @@ -55,14 +55,21 @@ public String jsonType() { return SIMPLE_TYPE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( STR__PROP, - X__PROP)); + X__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java index 61a9e57e..7554c2ad 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Car_Impl.java @@ -106,15 +106,28 @@ public String jsonType() { return CAR__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WHEEL_1__PROP, WHEEL_2__PROP, - BODY__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + BODY__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.notypekind.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.notypekind.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java index 7d85380f..f493f1c6 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Circle_Impl.java @@ -51,13 +51,26 @@ public String jsonType() { return CIRCLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - RADIUS__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + RADIUS__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.notypekind.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.notypekind.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java index d2dfe9b4..18efce79 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Group_Impl.java @@ -82,13 +82,26 @@ public String jsonType() { return GROUP__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - SHAPES__PROP)); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + SHAPES__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.notypekind.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.notypekind.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java index 41b0d6bc..569d37f5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Rectangle_Impl.java @@ -71,14 +71,27 @@ public String jsonType() { return RECTANGLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WIDTH__PROP, - HEIGHT__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + HEIGHT__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.notypekind.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.notypekind.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java index d4e110ef..c4434dfb 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/Shape_Impl.java @@ -74,14 +74,21 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( X_COORDINATE__PROP, - Y_COORDINATE__PROP)); + Y_COORDINATE__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java index 6af30e36..e23f2a9a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/notypekind/impl/SimpleType_Impl.java @@ -81,14 +81,21 @@ public String jsonType() { return SIMPLE_TYPE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( STR__PROP, - X__PROP)); + X__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java index 26183a08..8617ce05 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Car_Impl.java @@ -111,15 +111,28 @@ public String jsonType() { return CAR__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WHEEL_1__PROP, WHEEL_2__PROP, - BODY__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + BODY__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.novisit.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.novisit.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java index 7c2fb2e2..4debdcd7 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Circle_Impl.java @@ -56,13 +56,26 @@ public String jsonType() { return CIRCLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - RADIUS__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + RADIUS__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.novisit.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.novisit.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java index 326d0227..133c3240 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Group_Impl.java @@ -87,13 +87,26 @@ public String jsonType() { return GROUP__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - SHAPES__PROP)); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + SHAPES__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.novisit.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.novisit.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java index c3a9cb41..9f14e0b4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Rectangle_Impl.java @@ -76,14 +76,27 @@ public String jsonType() { return RECTANGLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WIDTH__PROP, - HEIGHT__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + HEIGHT__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.novisit.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.novisit.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java index 626c3d75..a0567be2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/Shape_Impl.java @@ -74,14 +74,21 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( X_COORDINATE__PROP, - Y_COORDINATE__PROP)); + Y_COORDINATE__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java index a372fc24..0031c482 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisit/impl/SimpleType_Impl.java @@ -81,14 +81,21 @@ public String jsonType() { return SIMPLE_TYPE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( STR__PROP, - X__PROP)); + X__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java index 88afb5d4..aab59735 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Car_Impl.java @@ -111,15 +111,28 @@ public String jsonType() { return CAR__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WHEEL_1__PROP, WHEEL_2__PROP, - BODY__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + BODY__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.novisitexceptions.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.novisitexceptions.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java index f52cd8e9..667f3a10 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Circle_Impl.java @@ -56,13 +56,26 @@ public String jsonType() { return CIRCLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - RADIUS__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + RADIUS__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.novisitexceptions.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.novisitexceptions.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java index a5354b25..d25c4cd4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Group_Impl.java @@ -87,13 +87,26 @@ public String jsonType() { return GROUP__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - SHAPES__PROP)); + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + SHAPES__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.novisitexceptions.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.novisitexceptions.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java index 81f99997..c871cc62 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Rectangle_Impl.java @@ -76,14 +76,27 @@ public String jsonType() { return RECTANGLE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( WIDTH__PROP, - HEIGHT__PROP)); - - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + HEIGHT__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.novisitexceptions.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.novisitexceptions.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java index 42eb4002..e6303a6f 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/Shape_Impl.java @@ -74,14 +74,21 @@ protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Lis _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( X_COORDINATE__PROP, - Y_COORDINATE__PROP)); + Y_COORDINATE__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java index a44d55da..7d8584dc 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/novisitexceptions/impl/SimpleType_Impl.java @@ -81,14 +81,21 @@ public String jsonType() { return SIMPLE_TYPE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( STR__PROP, - X__PROP)); + X__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java index 4579e16c..efefbc61 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java @@ -266,8 +266,9 @@ public String jsonType() { return NULLABLE_VALUES__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( INT__PROP, LONG__PROP, BOOLEAN__PROP, @@ -275,11 +276,17 @@ public String jsonType() { INT_LIST__PROP, STRING_LIST__PROP, STRING_INT_MAP__PROP, - OPTIONAL_DECISION__PROP)); + OPTIONAL_DECISION__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java index f34e0246..8a76a6df 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java @@ -415,8 +415,9 @@ public String jsonType() { return A__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( NAME__PROP, CONTENTS__PROP, CHILDREN__PROP, @@ -425,11 +426,17 @@ public String jsonType() { OTHER__PROP, OTHERS__PROP, IN_OTHER__PROP, - IN_OTHERS__PROP)); + IN_OTHERS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java index 093a15b0..f196d9fd 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java @@ -163,15 +163,22 @@ public String jsonType() { return B__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( NAME__PROP, IN_BS__PROP, - IN_B__PROP)); + IN_B__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/TestTransientProps.java b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/TestTransientProps.java new file mode 100644 index 00000000..88284748 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/TestTransientProps.java @@ -0,0 +1,41 @@ +/* + * SPDX-FileCopyrightText: 2025 (c) Business Operation Systems GmbH + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-BOS-TopLogic-1.0 + */ +package test.transientprops; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import junit.framework.TestCase; +import test.transientprops.data.A; +import test.transientprops.data.B; +import test.transientprops.data.C; + +/** + * Test case for transient properties. + */ +public class TestTransientProps extends TestCase { + + public void testA() { + assertEquals(set(A.X_2__PROP), A.create().transientProperties()); + assertEquals(Arrays.asList(A.X_1__PROP, A.X_2__PROP), A.create().properties()); + } + + public void testB() { + assertEquals(set(A.X_2__PROP, B.Y_2__PROP), B.create().transientProperties()); + assertEquals(Arrays.asList(A.X_1__PROP, A.X_2__PROP, B.Y_1__PROP, B.Y_2__PROP), B.create().properties()); + } + + public void testC() { + assertEquals(set(A.X_2__PROP, B.Y_2__PROP, C.Z_2__PROP), C.create().transientProperties()); + assertEquals(Arrays.asList(A.X_1__PROP, A.X_2__PROP, B.Y_1__PROP, B.Y_2__PROP, C.Z_1__PROP, C.Z_2__PROP), C.create().properties()); + } + + private Set set(String ...s) { + return new HashSet<>(Arrays.asList(s)); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/A.java b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/A.java new file mode 100644 index 00000000..3d474a1e --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/A.java @@ -0,0 +1,83 @@ +package test.transientprops.data; + +public interface A extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** Type codes for the {@link test.transientprops.data.A} hierarchy. */ + public enum TypeKind { + + /** Type literal for {@link test.transientprops.data.A}. */ + A, + + /** Type literal for {@link test.transientprops.data.B}. */ + B, + + /** Type literal for {@link test.transientprops.data.C}. */ + C, + ; + + } + + /** + * Creates a {@link test.transientprops.data.A} instance. + */ + static test.transientprops.data.A create() { + return new test.transientprops.data.impl.A_Impl(); + } + + /** Identifier for the {@link test.transientprops.data.A} type in JSON format. */ + String A__TYPE = "A"; + + /** @see #getX1() */ + String X_1__PROP = "x1"; + + /** @see #getX2() */ + String X_2__PROP = "x2"; + + /** Identifier for the property {@link #getX1()} in binary format. */ + static final int X_1__ID = 1; + + /** The type code of this instance. */ + TypeKind kind(); + + String getX1(); + + /** + * @see #getX1() + */ + test.transientprops.data.A setX1(String value); + + String getX2(); + + /** + * @see #getX2() + */ + test.transientprops.data.A setX2(String value); + + @Override + public test.transientprops.data.A registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.transientprops.data.A unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.transientprops.data.A readA(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.transientprops.data.impl.A_Impl result = new test.transientprops.data.impl.A_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.transientprops.data.A readA(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.transientprops.data.A result = test.transientprops.data.impl.A_Impl.readA_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static A readA(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.transientprops.data.impl.A_Impl.readA_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/B.java b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/B.java new file mode 100644 index 00000000..e6a2fae7 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/B.java @@ -0,0 +1,65 @@ +package test.transientprops.data; + +public interface B extends A { + + /** + * Creates a {@link test.transientprops.data.B} instance. + */ + static test.transientprops.data.B create() { + return new test.transientprops.data.impl.B_Impl(); + } + + /** Identifier for the {@link test.transientprops.data.B} type in JSON format. */ + String B__TYPE = "B"; + + /** @see #getY1() */ + String Y_1__PROP = "y1"; + + /** @see #getY2() */ + String Y_2__PROP = "y2"; + + /** Identifier for the property {@link #getY1()} in binary format. */ + static final int Y_1__ID = 3; + + String getY1(); + + /** + * @see #getY1() + */ + test.transientprops.data.B setY1(String value); + + String getY2(); + + /** + * @see #getY2() + */ + test.transientprops.data.B setY2(String value); + + @Override + test.transientprops.data.B setX1(String value); + + @Override + test.transientprops.data.B setX2(String value); + + /** Reads a new instance from the given reader. */ + static test.transientprops.data.B readB(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.transientprops.data.impl.B_Impl result = new test.transientprops.data.impl.B_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.transientprops.data.B readB(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.transientprops.data.B result = test.transientprops.data.impl.B_Impl.readB_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static B readB(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.transientprops.data.impl.B_Impl.readB_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/C.java b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/C.java new file mode 100644 index 00000000..653044cc --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/C.java @@ -0,0 +1,71 @@ +package test.transientprops.data; + +public interface C extends B { + + /** + * Creates a {@link test.transientprops.data.C} instance. + */ + static test.transientprops.data.C create() { + return new test.transientprops.data.impl.C_Impl(); + } + + /** Identifier for the {@link test.transientprops.data.C} type in JSON format. */ + String C__TYPE = "C"; + + /** @see #getZ1() */ + String Z_1__PROP = "z1"; + + /** @see #getZ2() */ + String Z_2__PROP = "z2"; + + /** Identifier for the property {@link #getZ1()} in binary format. */ + static final int Z_1__ID = 5; + + String getZ1(); + + /** + * @see #getZ1() + */ + test.transientprops.data.C setZ1(String value); + + String getZ2(); + + /** + * @see #getZ2() + */ + test.transientprops.data.C setZ2(String value); + + @Override + test.transientprops.data.C setY1(String value); + + @Override + test.transientprops.data.C setY2(String value); + + @Override + test.transientprops.data.C setX1(String value); + + @Override + test.transientprops.data.C setX2(String value); + + /** Reads a new instance from the given reader. */ + static test.transientprops.data.C readC(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.transientprops.data.impl.C_Impl result = new test.transientprops.data.impl.C_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.transientprops.data.C readC(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.transientprops.data.C result = test.transientprops.data.impl.C_Impl.readC_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link C} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static C readC(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.transientprops.data.impl.C_Impl.readC_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/A_Impl.java new file mode 100644 index 00000000..00ec7a92 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/A_Impl.java @@ -0,0 +1,296 @@ +package test.transientprops.data.impl; + +/** + * Implementation of {@link test.transientprops.data.A}. + */ +public class A_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.transientprops.data.A { + + private String _x1 = ""; + + private transient String _x2 = ""; + + /** + * Creates a {@link A_Impl} instance. + * + * @see test.transientprops.data.A#create() + */ + public A_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.A; + } + + @Override + public final String getX1() { + return _x1; + } + + @Override + public test.transientprops.data.A setX1(String value) { + internalSetX1(value); + return this; + } + + /** Internal setter for {@link #getX1()} without chain call utility. */ + protected final void internalSetX1(String value) { + _listener.beforeSet(this, X_1__PROP, value); + _x1 = value; + _listener.afterChanged(this, X_1__PROP); + } + + @Override + public final String getX2() { + return _x2; + } + + @Override + public test.transientprops.data.A setX2(String value) { + internalSetX2(value); + return this; + } + + /** Internal setter for {@link #getX2()} without chain call utility. */ + protected final void internalSetX2(String value) { + _listener.beforeSet(this, X_2__PROP, value); + _x2 = value; + _listener.afterChanged(this, X_2__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.transientprops.data.A registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.transientprops.data.A unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return A__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + X_1__PROP, + X_2__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + X_2__PROP)); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case X_1__PROP: return getX1(); + case X_2__PROP: return getX2(); + default: return test.transientprops.data.A.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case X_1__PROP: internalSetX1((String) value); break; + case X_2__PROP: internalSetX2((String) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(X_1__PROP); + out.value(getX1()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case X_1__PROP: setX1(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(X_1__ID); + out.value(getX1()); + } + + /** Helper for creating an object of type {@link test.transientprops.data.A} from a polymorphic composition. */ + public static test.transientprops.data.A readA_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.transientprops.data.impl.A_Impl result = new A_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case X_1__ID: setX1(in.nextString()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.transientprops.data.A} type. */ + public static final String A__XML_ELEMENT = "a"; + + /** XML attribute or element name of a {@link #getX1} property. */ + private static final String X_1__XML_ATTR = "x-1"; + + /** XML attribute or element name of a {@link #getX2} property. */ + private static final String X_2__XML_ATTR = "x-2"; + + @Override + public String getXmlTagName() { + return A__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(X_1__XML_ATTR, getX1()); + out.writeAttribute(X_2__XML_ATTR, getX2()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.transientprops.data.A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static A_Impl readA_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + A_Impl result = new A_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case X_1__XML_ATTR: { + setX1(value); + break; + } + case X_2__XML_ATTR: { + setX2(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case X_1__XML_ATTR: { + setX1(in.getElementText()); + break; + } + case X_2__XML_ATTR: { + setX2(in.getElementText()); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/B_Impl.java new file mode 100644 index 00000000..89f9a5a8 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/B_Impl.java @@ -0,0 +1,236 @@ +package test.transientprops.data.impl; + +/** + * Implementation of {@link test.transientprops.data.B}. + */ +public class B_Impl extends test.transientprops.data.impl.A_Impl implements test.transientprops.data.B { + + private String _y1 = ""; + + private transient String _y2 = ""; + + /** + * Creates a {@link B_Impl} instance. + * + * @see test.transientprops.data.B#create() + */ + public B_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.B; + } + + @Override + public final String getY1() { + return _y1; + } + + @Override + public test.transientprops.data.B setY1(String value) { + internalSetY1(value); + return this; + } + + /** Internal setter for {@link #getY1()} without chain call utility. */ + protected final void internalSetY1(String value) { + _listener.beforeSet(this, Y_1__PROP, value); + _y1 = value; + _listener.afterChanged(this, Y_1__PROP); + } + + @Override + public final String getY2() { + return _y2; + } + + @Override + public test.transientprops.data.B setY2(String value) { + internalSetY2(value); + return this; + } + + /** Internal setter for {@link #getY2()} without chain call utility. */ + protected final void internalSetY2(String value) { + _listener.beforeSet(this, Y_2__PROP, value); + _y2 = value; + _listener.afterChanged(this, Y_2__PROP); + } + + @Override + public test.transientprops.data.B setX1(String value) { + internalSetX1(value); + return this; + } + + @Override + public test.transientprops.data.B setX2(String value) { + internalSetX2(value); + return this; + } + + @Override + public String jsonType() { + return B__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + Y_1__PROP, + Y_2__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.transientprops.data.impl.A_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.transientprops.data.impl.A_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + Y_2__PROP)); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case Y_1__PROP: return getY1(); + case Y_2__PROP: return getY2(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case Y_1__PROP: internalSetY1((String) value); break; + case Y_2__PROP: internalSetY2((String) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(Y_1__PROP); + out.value(getY1()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case Y_1__PROP: setY1(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(Y_1__ID); + out.value(getY1()); + } + + /** Helper for creating an object of type {@link test.transientprops.data.B} from a polymorphic composition. */ + public static test.transientprops.data.B readB_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.transientprops.data.impl.B_Impl result = new B_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case Y_1__ID: setY1(in.nextString()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.transientprops.data.B} type. */ + public static final String B__XML_ELEMENT = "b"; + + /** XML attribute or element name of a {@link #getY1} property. */ + private static final String Y_1__XML_ATTR = "y-1"; + + /** XML attribute or element name of a {@link #getY2} property. */ + private static final String Y_2__XML_ATTR = "y-2"; + + @Override + public String getXmlTagName() { + return B__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(Y_1__XML_ATTR, getY1()); + out.writeAttribute(Y_2__XML_ATTR, getY2()); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.transientprops.data.B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static B_Impl readB_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + B_Impl result = new B_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case Y_1__XML_ATTR: { + setY1(value); + break; + } + case Y_2__XML_ATTR: { + setY2(value); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case Y_1__XML_ATTR: { + setY1(in.getElementText()); + break; + } + case Y_2__XML_ATTR: { + setY2(in.getElementText()); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/C_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/C_Impl.java new file mode 100644 index 00000000..bc857802 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/C_Impl.java @@ -0,0 +1,248 @@ +package test.transientprops.data.impl; + +/** + * Implementation of {@link test.transientprops.data.C}. + */ +public class C_Impl extends test.transientprops.data.impl.B_Impl implements test.transientprops.data.C { + + private String _z1 = ""; + + private transient String _z2 = ""; + + /** + * Creates a {@link C_Impl} instance. + * + * @see test.transientprops.data.C#create() + */ + public C_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.C; + } + + @Override + public final String getZ1() { + return _z1; + } + + @Override + public test.transientprops.data.C setZ1(String value) { + internalSetZ1(value); + return this; + } + + /** Internal setter for {@link #getZ1()} without chain call utility. */ + protected final void internalSetZ1(String value) { + _listener.beforeSet(this, Z_1__PROP, value); + _z1 = value; + _listener.afterChanged(this, Z_1__PROP); + } + + @Override + public final String getZ2() { + return _z2; + } + + @Override + public test.transientprops.data.C setZ2(String value) { + internalSetZ2(value); + return this; + } + + /** Internal setter for {@link #getZ2()} without chain call utility. */ + protected final void internalSetZ2(String value) { + _listener.beforeSet(this, Z_2__PROP, value); + _z2 = value; + _listener.afterChanged(this, Z_2__PROP); + } + + @Override + public test.transientprops.data.C setY1(String value) { + internalSetY1(value); + return this; + } + + @Override + public test.transientprops.data.C setY2(String value) { + internalSetY2(value); + return this; + } + + @Override + public test.transientprops.data.C setX1(String value) { + internalSetX1(value); + return this; + } + + @Override + public test.transientprops.data.C setX2(String value) { + internalSetX2(value); + return this; + } + + @Override + public String jsonType() { + return C__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + Z_1__PROP, + Z_2__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.transientprops.data.impl.B_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.transientprops.data.impl.B_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + Z_2__PROP)); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case Z_1__PROP: return getZ1(); + case Z_2__PROP: return getZ2(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case Z_1__PROP: internalSetZ1((String) value); break; + case Z_2__PROP: internalSetZ2((String) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(Z_1__PROP); + out.value(getZ1()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case Z_1__PROP: setZ1(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(Z_1__ID); + out.value(getZ1()); + } + + /** Helper for creating an object of type {@link test.transientprops.data.C} from a polymorphic composition. */ + public static test.transientprops.data.C readC_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.transientprops.data.impl.C_Impl result = new C_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case Z_1__ID: setZ1(in.nextString()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.transientprops.data.C} type. */ + public static final String C__XML_ELEMENT = "c"; + + /** XML attribute or element name of a {@link #getZ1} property. */ + private static final String Z_1__XML_ATTR = "z-1"; + + /** XML attribute or element name of a {@link #getZ2} property. */ + private static final String Z_2__XML_ATTR = "z-2"; + + @Override + public String getXmlTagName() { + return C__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(Z_1__XML_ATTR, getZ1()); + out.writeAttribute(Z_2__XML_ATTR, getZ2()); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.transientprops.data.C} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static C_Impl readC_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + C_Impl result = new C_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case Z_1__XML_ATTR: { + setZ1(value); + break; + } + case Z_2__XML_ATTR: { + setZ2(value); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case Z_1__XML_ATTR: { + setZ1(in.getElementText()); + break; + } + case Z_2__XML_ATTR: { + setZ2(in.getElementText()); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/transientprops.proto b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/transientprops.proto new file mode 100644 index 00000000..f88ff1f4 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/transientprops.proto @@ -0,0 +1,16 @@ +package test.transientprops.data; + +message A { + string x1; + transient string x2; +} + +message B extends A { + string y1; + transient string y2; +} + +message C extends B { + string z1; + transient string z2; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java index d03496bb..68b2678e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/types/data/impl/SearchRequest_Impl.java @@ -101,15 +101,22 @@ public String jsonType() { return SEARCH_REQUEST__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( QUERY__PROP, PAGE_NUMBER__PROP, - RESULT_PER_PAGE__PROP)); + RESULT_PER_PAGE__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java index cd8d1bec..a0a2cd78 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/AnnotatedMessage_Impl.java @@ -44,13 +44,20 @@ public String jsonType() { return ANNOTATED_MESSAGE__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - ANNOTATED_FIELD__PROP)); + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + ANNOTATED_FIELD__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java index cdf357f0..a94e7c6b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/underscorename/impl/SomeName_Impl.java @@ -44,13 +44,20 @@ public String jsonType() { return SOME_NAME__TYPE; } - private static java.util.List PROPERTIES = java.util.Collections.unmodifiableList( - java.util.Arrays.asList( - MY_FIELD__PROP)); + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + MY_FIELD__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } - private static java.util.Set TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(new java.util.HashSet<>( - java.util.Arrays.asList( - ))); + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } @Override public java.util.List properties() { From 11307bd73c8089e842ee3d81c2c183001fd59dc7 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 3 Sep 2025 16:08:38 +0200 Subject: [PATCH 117/207] Refer signing key through property. --- msgbuf-parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msgbuf-parent/pom.xml b/msgbuf-parent/pom.xml index 6ad083f3..d655569d 100644 --- a/msgbuf-parent/pom.xml +++ b/msgbuf-parent/pom.xml @@ -124,7 +124,7 @@ maven-gpg-plugin 1.5 - 3FDEA7509C2E6ACFBAAE4E4C062F98BC833AC2BF + ${gpg.keyname} From c6af212fbb2d794cd2bf1cfb64d3b5119d38d5e0 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 3 Sep 2025 16:45:21 +0200 Subject: [PATCH 118/207] [maven-release-plugin] prepare release msgbuf-api-1.1.10 --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 4e7df110..22d8f2c6 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.10-SNAPSHOT + 1.1.10 msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.10-SNAPSHOT + 1.1.10 diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 88d1f636..f5d038b5 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.10-SNAPSHOT + 1.1.10 msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 60d848bc..0e60d4be 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.10-SNAPSHOT + 1.1.10 msgbuf-generator-maven-plugin @@ -33,7 +33,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.10-SNAPSHOT + 1.1.10 diff --git a/pom.xml b/pom.xml index 9aa1ac9c..b515cd4e 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.10-SNAPSHOT + 1.1.10 pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - HEAD + msgbuf-api-1.1.10 From ee6434da266ae9149f8331f2a48ca8b59e0f0456 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 3 Sep 2025 16:45:23 +0200 Subject: [PATCH 119/207] [maven-release-plugin] prepare for next development iteration --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 22d8f2c6..c3fc1d78 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.10 + 1.1.11-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.10 + 1.1.11-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index f5d038b5..049444e7 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.10 + 1.1.11-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 0e60d4be..bc05f34c 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.10 + 1.1.11-SNAPSHOT msgbuf-generator-maven-plugin @@ -33,7 +33,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.10 + 1.1.11-SNAPSHOT diff --git a/pom.xml b/pom.xml index b515cd4e..0624ba6d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.10 + 1.1.11-SNAPSHOT pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - msgbuf-api-1.1.10 + HEAD From ff3ccaf2667598fe28cfeea0e6e52010edded7ca Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 16 Jan 2026 09:29:15 +0100 Subject: [PATCH 120/207] Add CLAUDE.md documentation for AI code assistant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create comprehensive documentation covering project structure, build commands, development workflow, and key architectural concepts to help future Claude Code instances work effectively in this repository. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- CLAUDE.md | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000..5a7122b8 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,159 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +MsgBuf is a code generator for GWT-compatible Java data classes suitable for typed client-server messaging. Inspired by Google's Protocol Buffers, it generates Java classes from `.proto` definition files with additional features like inheritance, abstract classes, and polymorphic data composition. + +The project supports multiple serialization formats: JSON (primary), Binary, and XML. + +## Project Structure + +This is a multi-module Maven project with three core modules: + +- **de.haumacher.msgbuf** (`msgbuf-api`) - Runtime library containing base classes for generated code, serialization support (JSON/Binary/XML), and GWT-compatible I/O abstractions. Licensed under Apache-2.0. + +- **de.haumacher.msgbuf.generator** (`msgbuf-generator`) - Code generator that reads `.proto` files and generates Java classes. Uses JavaCC for parsing. Can be run standalone via shaded JAR. Licensed under GPL-3.0-or-later. + +- **msgbuf-generator-maven-plugin** - Maven plugin wrapper for the generator, allowing proto compilation during Maven build. + +- **de.haumacher.msgbuf.eclipse** - Eclipse plugin providing automatic proto file compilation (separate from Maven build). + +## Building and Testing + +### Full Build +```bash +mvn clean install +``` + +### Build Individual Module +```bash +# Build runtime library only +mvn clean install -pl de.haumacher.msgbuf + +# Build generator only +mvn clean install -pl de.haumacher.msgbuf.generator + +# Build Maven plugin only +mvn clean install -pl msgbuf-generator-maven-plugin +``` + +### Run Tests +```bash +# All tests +mvn test + +# Single module tests +mvn test -pl de.haumacher.msgbuf.generator +``` + +### Check for Vulnerabilities +```bash +mvn dependency-check:check +``` + +### Update Dependencies +```bash +mvn versions:use-latest-releases +``` + +## Development Workflow + +### Working with Proto Files + +Proto definition files use the `syntax = "msgbuf";` declaration (not `proto3`). Test proto files in `de.haumacher.msgbuf.generator/src/test/java/test/**/` demonstrate various features. + +Key proto file locations: +- Test examples: `de.haumacher.msgbuf.generator/src/test/java/test/*/` +- Generator's own AST model: `de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto` +- Shared graph commands: `de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/graph/cmd/update.proto` + +### Generator Architecture + +The code generator pipeline: +1. **Parser** (JavaCC) - Parses `.proto` files into AST (see `generator/ast/proto.proto`) +2. **Synthesizers** - Add field IDs and type IDs if not explicitly defined +3. **Code Generators** - Generate Java source code: + - `MessageGenerator` - Concrete message classes + - `AbstractMessageGenerator` - Abstract base classes with visitor pattern + - `EnumGenerator` - Enum types + - `TypeGenerator` - Orchestrates generation + +Main entry point: `de.haumacher.msgbuf.generator.Generator.main()` + +### Running Generator Standalone + +The shaded JAR allows standalone execution: +```bash +java -jar de.haumacher.msgbuf.generator/target/msgbuf-generator-*-full.jar +``` + +### Generated Code Structure + +Each message definition generates: +- Interface (if `NoInterfaces` option not set) +- Implementation class with: + - Getters/setters for properties + - JSON read/write methods (`readX()`, `writeTo()`) + - Binary read/write methods (if `NoBinary` not set) + - XML read/write methods (if `NoXml` not set) + - Visitor pattern support (if abstract/polymorphic) + - Property listeners (if `NoListener` not set) + - Reflective property access (if `NoReflection` not set) + +## Key Concepts + +### Inheritance and Polymorphism + +MsgBuf extends protobuf syntax with: +- `abstract message` - Creates abstract base classes +- `extends` keyword - Message inheritance +- Visitor pattern generation for polymorphic hierarchies +- Type discrimination in serialization + +### Serialization Formats + +**JSON** - Primary format, uses modified Gson reader/writer abstracted for GWT compatibility +**Binary** - Compact format using DataReader/DataWriter +**XML** - Document format with XmlSerializable interface + +### GWT Compatibility + +The runtime library (`msgbuf-api`) avoids Java I/O classes (java.io.Reader/Writer) to work with GWT. Custom abstractions in `de.haumacher.msgbuf.io` package provide compatible interfaces. + +### Shared Graph Support + +The `SharedGraph` option enables synchronized object graphs across client/server with change tracking and update commands (see `de.haumacher.msgbuf.graph.cmd`). + +## Release Process + +Follow the documented release process: +```bash +# Set version and create tag +mvn release:clean release:prepare + +# Deploy to Maven Central +mvn release:perform +``` + +Release configuration in parent POM includes GPG signing and automatic publishing to Maven Central via the central-publishing-maven-plugin. + +## Important Constraints + +- Java 11+ required (maven.compiler.source/target = 11) +- Generated code must be GWT-compatible (no java.io usage in msgbuf-api) +- Generator uses JavaCC for parsing - regenerate parser after grammar changes +- Proto files must use `syntax = "msgbuf";` not `proto3` +- Different licenses: API is Apache-2.0, Generator is GPL-3.0-or-later + +## Testing Strategy + +Test proto files in `de.haumacher.msgbuf.generator/src/test/java/test/` cover: +- Hierarchy and inheritance (`test.hierarchy`) +- Various options (NoJson, NoInterfaces, NoVisitor, etc.) +- Container/reference handling (`test.container`, `test.references`) +- Shared graphs (`test.graph`) +- Edge cases (reserved names, lowercase messages, etc.) + +The Maven plugin has integration tests in `msgbuf-generator-maven-plugin/src/it/`. From 0b72a79a04f48c616ab2ae7dbc7be5c64b1c9e77 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 16 Jan 2026 09:38:13 +0100 Subject: [PATCH 121/207] Improve plural-to-singular conversion for generated method names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace simple "remove trailing s" heuristic with comprehensive English pluralization rules. This fixes incorrect singularization for words like "properties" (was "propertie", now "property"). New conversion rules handle: - -ies → -y (properties → property, categories → category) - -xes/-sses/-shes/-ches → remove -es (boxes → box, classes → class) - -oes → -o (tomatoes → tomato, heroes → hero) - -ives → -ife (knives → knife, wives → wife) - -ves → -f (wolves → wolf, shelves → shelf) - -s → remove s (items → item, entries → entry) All existing tests pass, confirming backward compatibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../msgbuf/generator/CodeConvention.java | 66 +++++++++++++++++-- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java index 42bdc020..c4cfe6ef 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java @@ -153,19 +153,75 @@ public static String removerName(Field field) { private static String singularSuffix(Field field) { String suffix = suffix(field); - if (suffix.endsWith("s")) { - String singularSuffix = suffix.substring(0, suffix.length() - 1); - String name = field.getName(); - String singularName = name.substring(0, name.length() - 1); - + String name = field.getName(); + + // Try to compute the singular form + String singularSuffix = toSingular(suffix); + String singularName = toSingular(name); + + // Check if we successfully converted to singular and it doesn't clash with existing field + if (!singularSuffix.equals(suffix)) { MessageDef owner = (MessageDef) field.getOwner(); if (getField(owner, singularName) == null) { // No clash with other singular field. return singularSuffix; } } + return suffix; } + + /** + * Converts a plural word to its singular form using common English pluralization rules. + * + * @param plural The plural form + * @return The singular form, or the original word if no conversion rule applies + */ + private static String toSingular(String plural) { + if (plural.isEmpty()) { + return plural; + } + + // Words ending in "ies" -> change to "y" (e.g., "properties" -> "property") + if (plural.endsWith("ies") && plural.length() > 3) { + char beforeIes = plural.charAt(plural.length() - 4); + // Make sure it's not "eies" which would suggest "eie" -> "eies" isn't a valid pattern + if (beforeIes != 'e' && beforeIes != 'a' && beforeIes != 'i' && beforeIes != 'o' && beforeIes != 'u') { + return plural.substring(0, plural.length() - 3) + "y"; + } + } + + // Words ending in "xes", "sses", "shes", "ches" -> remove "es" (e.g., "boxes" -> "box", "classes" -> "class") + if (plural.endsWith("xes") || plural.endsWith("sses") || plural.endsWith("shes") || plural.endsWith("ches")) { + return plural.substring(0, plural.length() - 2); + } + + // Words ending in "oes" -> change to "o" (e.g., "tomatoes" -> "tomato", "heroes" -> "hero") + // But not "shoes" -> "sho", so check the character before "oes" + if (plural.endsWith("oes") && plural.length() > 3) { + char beforeOes = plural.charAt(plural.length() - 4); + if (beforeOes != 'o' && beforeOes != 'e') { + return plural.substring(0, plural.length() - 2); + } + } + + // Words ending in "ves" -> change to "fe" or "f" (e.g., "knives" -> "knife", "wolves" -> "wolf") + // Use "fe" for words ending in "ife" pattern (knife, wife, life) + if (plural.endsWith("ives") && plural.length() > 4) { + return plural.substring(0, plural.length() - 4) + "ife"; + } + if (plural.endsWith("ves") && plural.length() > 3) { + return plural.substring(0, plural.length() - 3) + "f"; + } + + // Words ending in "s" but not "ss" -> remove "s" (e.g., "items" -> "item", "entries" -> "entry") + if (plural.endsWith("s") && !plural.endsWith("ss")) { + return plural.substring(0, plural.length() - 1); + } + + // No rule applies, return as-is + return plural; + } public static String hasName(Field field) { return "has" + suffix(field); From 93d4461e9085bf9ba0b123027eebf29467c965fc Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 16 Jan 2026 09:42:51 +0100 Subject: [PATCH 122/207] Add @Singular annotation to override plural-to-singular heuristics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Users can now explicitly specify the singular form for repeated fields using the @Singular annotation when the automatic pluralization heuristics fail or produce incorrect results. Example usage: ```protobuf message Container { @Singular("person") repeated string people; // Generates addPerson() @Singular("child") repeated string children; // Generates addChild() @Singular("datum") repeated string data; // Generates addDatum() } ``` The annotation takes precedence over automatic heuristics, allowing users to handle irregular plurals (person/people, child/children), words that are the same in singular and plural (sheep/sheep), and other edge cases where English pluralization rules don't apply. Updated README.md with documentation and examples. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- README.md | 21 ++++++++++++++++++- .../msgbuf/generator/CodeConvention.java | 13 +++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ede93b13..21590add 100644 --- a/README.md +++ b/README.md @@ -166,9 +166,28 @@ public void testOperations() { ## Property options ### `@Nullable` -A property of a primitive type that does not allow `null` values (e.g. `int` and `string`) can be explicitly marked to +A property of a primitive type that does not allow `null` values (e.g. `int` and `string`) can be explicitly marked to allow `null` values. +### `@Singular("item")` +Specifies the singular form for a repeated field, used when generating `addXxx()` and `removeXxx()` methods. This annotation +takes precedence over the automatic pluralization heuristics. Useful for irregular plurals or when the heuristics produce +incorrect results. + +Example: +```protobuf +message Container { + @Singular("person") + repeated string people; // Generates addPerson() instead of addPeople() + + @Singular("child") + repeated string children; // Generates addChild() instead of addChildren() + + @Singular("datum") + repeated string data; // Generates addDatum() instead of addData() +} +``` + ### `@Name("myProp")` Sets a custom property name. This name is used in JSON serialization. diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java index c4cfe6ef..588fd329 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java @@ -9,6 +9,8 @@ import java.util.function.Function; import java.util.stream.Collectors; +import java.util.Optional; + import de.haumacher.msgbuf.generator.ast.Constant; import de.haumacher.msgbuf.generator.ast.CustomType; import de.haumacher.msgbuf.generator.ast.Definition; @@ -16,8 +18,10 @@ import de.haumacher.msgbuf.generator.ast.Field; import de.haumacher.msgbuf.generator.ast.MapType; import de.haumacher.msgbuf.generator.ast.MessageDef; +import de.haumacher.msgbuf.generator.ast.Option; import de.haumacher.msgbuf.generator.ast.PrimitiveType; import de.haumacher.msgbuf.generator.ast.QName; +import de.haumacher.msgbuf.generator.ast.StringOption; import de.haumacher.msgbuf.generator.ast.Type; import de.haumacher.msgbuf.generator.common.Util; import de.haumacher.msgbuf.generator.util.CodeUtil; @@ -152,10 +156,17 @@ public static String removerName(Field field) { } private static String singularSuffix(Field field) { + // Check for explicit @Singular annotation first + Optional
+ + + + + + +
diff --git a/de.haumacher.msgbuf.generator/.settings/org.eclipse.core.resources.prefs b/de.haumacher.msgbuf.generator/.settings/org.eclipse.core.resources.prefs index a05fb4b5..226a7eb3 100644 --- a/de.haumacher.msgbuf.generator/.settings/org.eclipse.core.resources.prefs +++ b/de.haumacher.msgbuf.generator/.settings/org.eclipse.core.resources.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 encoding//src/main/java=utf-8 encoding//src/test/java=utf-8 +encoding//src/test/resources=utf-8 encoding/=utf-8 From 8c4b4ecd2fed0d78ce694eab85097fae24533d46 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 25 Mar 2026 08:46:36 +0100 Subject: [PATCH 166/207] docs: document option OpenWorld in README Co-Authored-By: Claude Opus 4.6 (1M context) --- README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/README.md b/README.md index 8b694bc0..161af108 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,58 @@ message Config { } ``` +### `option OpenWorld` +Enables cross-file protocol extension for abstract type hierarchies. With this option, subtypes can be defined in +separate `.proto` files (and separate modules) using `import` and `extends`: + +```protobuf +// base-module: events.proto +option OpenWorld; + +abstract message Event { + long timestamp; +} + +message TextEvent extends Event { + string text; +} +``` + +```protobuf +// extension-module: graph-events.proto +import "../base-module/events.proto"; + +message GraphPatchEvent extends base.pkg.Event { + string controlId; + string patch; +} +``` + +Extension types are discovered at runtime via `ServiceLoader`. The generator produces a registration class +(e.g. `GraphEventsTypes`) and a `META-INF/services` descriptor automatically when the `-resources` output +directory is configured. On platforms without `ServiceLoader` (e.g. GWT), call `GraphEventsTypes.init()` explicitly. + +Implications: +- Implies `option NoBinary` (only JSON and XML serialization are supported) +- Cannot be combined with `option NoInterfaces` +- The generated `Visitor` interface includes a `visitDefault()` fallback method for unknown extension types +- Extension types generate their own `Visitor` sub-interface with an `instanceof`-based dispatch + +CLI usage with imports: +``` +java -jar msgbuf-generator.jar -out src/main/java -resources src/main/resources -I /path/to/base-module/src/main/java extension.proto +``` + +Maven plugin configuration: +```xml + + + ${project.basedir}/../base-module/src/main/java + + ${project.basedir}/src/main/resources + +``` + ## Message options ### Mix-in interfaces (`@Operations(...)`) From ffcbf321fb52db62f2352e6cd5195d1f1c8e9d22 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 25 Mar 2026 08:56:24 +0100 Subject: [PATCH 167/207] feat: resolve imports from classpath (dependency JARs) Proto files packaged as resources in dependency JARs can now be imported without having the source files on disk. The generator tries file system resolution first, then falls back to classpath. Generator changes: - New setImportClassLoader() API for classpath-based resolution - New -cp CLI argument for standalone usage - resolveImports() tries file system first, then classpath - Extracted loadPlugins() as public method Maven plugin changes: - Uses Generator API directly instead of main() CLI - Automatically builds URLClassLoader from compile classpath - requiresDependencyResolution = COMPILE on @Mojo Co-Authored-By: Claude Opus 4.6 (1M context) --- .../haumacher/msgbuf/generator/Generator.java | 121 ++++++++++++++---- .../maven/GenerateMessageClasses.java | 55 +++++--- 2 files changed, 134 insertions(+), 42 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java index 1676a51d..b8dde37b 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java @@ -11,6 +11,8 @@ import java.io.InputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; +import java.net.URL; +import java.net.URLClassLoader; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -60,6 +62,7 @@ public class Generator { private File _resourceOut; private List _files = new ArrayList<>(); private List _includePaths = new ArrayList<>(); + private ClassLoader _importClassLoader; private Set _loadedFiles = new HashSet<>(); private List _importedFiles = new ArrayList<>(); @@ -75,6 +78,14 @@ public void addIncludePath(File path) { _includePaths.add(path); } + /** + * Sets a class loader used to resolve imports from the classpath. + * Proto files packaged as resources in dependency JARs can be found this way. + */ + public void setImportClassLoader(ClassLoader classLoader) { + _importClassLoader = classLoader; + } + public DefinitionFile load(String fileName) throws IOException, ParseException { return load(new File(fileName)); } @@ -209,34 +220,85 @@ private void propagateOpenWorldOptions(DefinitionFile file) { private void resolveImports(DefinitionFile file, File sourceFile) throws IOException, ParseException { for (String importPath : file.getImports()) { - File resolved = resolveImportPath(importPath, sourceFile); - if (resolved == null) { - error("Cannot resolve import '" + importPath + "' from '" + sourceFile + "'."); + // Try file system first + File resolved = resolveImportPathFromFileSystem(importPath, sourceFile); + if (resolved != null) { + String canonical = resolved.getCanonicalPath(); + if (_loadedFiles.contains(canonical)) { + continue; + } + _loadedFiles.add(canonical); + DefinitionFile imported; + try (InputStream in = new FileInputStream(resolved)) { + imported = parse(in); + } + _files.add(imported); + _table.enter(imported); + _importedFiles.add(imported); + resolveImports(imported, resolved); continue; } - String canonical = resolved.getCanonicalPath(); - if (_loadedFiles.contains(canonical)) { + + // Fall back to classpath + if (_importClassLoader != null) { + String resourceKey = "classpath:" + importPath; + if (_loadedFiles.contains(resourceKey)) { + continue; + } + InputStream classpathStream = _importClassLoader.getResourceAsStream(importPath); + if (classpathStream != null) { + _loadedFiles.add(resourceKey); + DefinitionFile imported; + try (InputStream in = classpathStream) { + imported = parse(in); + } + _files.add(imported); + _table.enter(imported); + _importedFiles.add(imported); + // Recursive imports from classpath-loaded files can only resolve via classpath + resolveImportsFromClasspath(imported); + continue; + } + } + + error("Cannot resolve import '" + importPath + "' from '" + sourceFile + "'."); + } + } + + private void resolveImportsFromClasspath(DefinitionFile file) throws IOException, ParseException { + for (String importPath : file.getImports()) { + String resourceKey = "classpath:" + importPath; + if (_loadedFiles.contains(resourceKey)) { continue; } - _loadedFiles.add(canonical); - DefinitionFile imported; - try (InputStream in = new FileInputStream(resolved)) { - imported = parse(in); + + if (_importClassLoader != null) { + InputStream classpathStream = _importClassLoader.getResourceAsStream(importPath); + if (classpathStream != null) { + _loadedFiles.add(resourceKey); + DefinitionFile imported; + try (InputStream in = classpathStream) { + imported = parse(in); + } + _files.add(imported); + _table.enter(imported); + _importedFiles.add(imported); + resolveImportsFromClasspath(imported); + continue; + } } - // Add to table for name resolution, and to _files for buildSpecializations - _files.add(imported); - _table.enter(imported); - _importedFiles.add(imported); - // Recursively resolve imports of the imported file - resolveImports(imported, resolved); + + error("Cannot resolve import '" + importPath + "'."); } } - private File resolveImportPath(String importPath, File sourceFile) { - // 1. Relative to importing file's directory - File relative = new File(sourceFile.getParentFile(), importPath); - if (relative.isFile()) { - return relative; + private File resolveImportPathFromFileSystem(String importPath, File sourceFile) { + if (sourceFile != null) { + // 1. Relative to importing file's directory + File relative = new File(sourceFile.getParentFile(), importPath); + if (relative.isFile()) { + return relative; + } } // 2. From configured include paths for (File includePath : _includePaths) { @@ -508,6 +570,14 @@ public static void main(String... args) throws ParseException, IOException, Inst return; } else if (arg.equals("-I")) { generator.addIncludePath(new File(args[n++])); + } else if (arg.equals("-cp")) { + String classpath = args[n++]; + String[] entries = classpath.split(File.pathSeparator); + URL[] urls = new URL[entries.length]; + for (int i = 0; i < entries.length; i++) { + urls[i] = new File(entries[i]).toURI().toURL(); + } + generator.setImportClassLoader(new URLClassLoader(urls, null)); } else { File file = new File(arg); DefinitionFile content = generator.load(file); @@ -520,14 +590,19 @@ public static void main(String... args) throws ParseException, IOException, Inst generator.setOut(out); } + generator.generate(loadPlugins()); + } + + /** + * Loads generator plugins via {@link ServiceLoader}. + */ + public static GeneratorPlugin loadPlugins() { ServiceLoader pluginLoader = ServiceLoader.load(GeneratorPlugin.class); - GeneratorPlugin plugin = GeneratorPlugin.none(); for (GeneratorPlugin p : pluginLoader) { plugin = plugin.andThen(p); } - - generator.generate(plugin); + return plugin; } private static void printHelp() { diff --git a/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java b/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java index 0a273e21..c291c1d0 100644 --- a/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java +++ b/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java @@ -1,9 +1,9 @@ package de.haumacher.msgbuf.generator.maven; import java.io.File; +import java.net.URL; +import java.net.URLClassLoader; import java.nio.file.Files; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -13,13 +13,15 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; import de.haumacher.msgbuf.generator.Generator; /** * Goal that invokes the MsgBuf compiler. */ -@Mojo(name = GenerateMessageClasses.NAME, defaultPhase = LifecyclePhase.GENERATE_SOURCES) +@Mojo(name = GenerateMessageClasses.NAME, defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE) public class GenerateMessageClasses extends AbstractMojo { /** @@ -51,6 +53,9 @@ public class GenerateMessageClasses extends AbstractMojo { @Parameter(defaultValue = "${project.basedir}/src/main/resources", property = "resourceOutputDir") private File _resourceOutputDirectory; + @Parameter(defaultValue = "${project}", readonly = true, required = true) + private MavenProject _project; + @Override public void execute() throws MojoExecutionException { File outputDirectory = _outputDirectory; @@ -59,35 +64,47 @@ public void execute() throws MojoExecutionException { } try { - List files; + List protoFiles; if (_input.isDirectory()) { - files = Files.walk(_input.toPath()) - .filter(p -> p.toFile().isFile()) - .filter(p -> p.getFileName().toString().endsWith(".proto")) - .map(p -> p.toAbsolutePath().toString()) + protoFiles = Files.walk(_input.toPath()) + .map(p -> p.toFile()) + .filter(File::isFile) + .filter(p -> p.getName().endsWith(".proto")) .collect(Collectors.toList()); } else { - files = Collections.singletonList(_input.getAbsolutePath()); + protoFiles = Collections.singletonList(_input); } - if (files.isEmpty()) { + if (protoFiles.isEmpty()) { getLog().info("No protocol files found, skipping."); return; } - - ArrayList argList = new ArrayList<>(Arrays.asList(Generator.OUTPUT_DIR_ARG, _outputDirectory.getAbsolutePath())); + + Generator generator = new Generator(); + generator.setOut(outputDirectory); if (_resourceOutputDirectory != null) { - argList.add(Generator.RESOURCE_DIR_ARG); - argList.add(_resourceOutputDirectory.getAbsolutePath()); + generator.setResourceOut(_resourceOutputDirectory); } if (_includePaths != null) { for (File includePath : _includePaths) { - argList.add("-I"); - argList.add(includePath.getAbsolutePath()); + generator.addIncludePath(includePath); } } - argList.addAll(files); - String[] args = argList.toArray(new String[0]); - Generator.main(args); + + // Build classpath from compile dependencies for resolving imports from JARs + List classpathElements = _project.getCompileClasspathElements(); + if (classpathElements != null && !classpathElements.isEmpty()) { + URL[] urls = new URL[classpathElements.size()]; + for (int i = 0; i < classpathElements.size(); i++) { + urls[i] = new File(classpathElements.get(i)).toURI().toURL(); + } + generator.setImportClassLoader(new URLClassLoader(urls, null)); + } + + for (File protoFile : protoFiles) { + generator.load(protoFile); + } + + generator.generate(Generator.loadPlugins()); } catch (Throwable ex) { throw new MojoExecutionException("Failed to invoke the generator: " + ex.getMessage(), ex); } From 1f36a3d342328b97f2575b511136190682dbfe2f Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 25 Mar 2026 08:58:23 +0100 Subject: [PATCH 168/207] docs: document classpath-based import resolution in README Imports are resolved from dependency JARs automatically in Maven. For CLI usage, the -cp argument specifies JARs to search. Co-Authored-By: Claude Opus 4.6 (1M context) --- README.md | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 161af108..82966570 100644 --- a/README.md +++ b/README.md @@ -246,27 +246,34 @@ Extension types are discovered at runtime via `ServiceLoader`. The generator pro (e.g. `GraphEventsTypes`) and a `META-INF/services` descriptor automatically when the `-resources` output directory is configured. On platforms without `ServiceLoader` (e.g. GWT), call `GraphEventsTypes.init()` explicitly. +The base module's `.proto` files should be packaged as resources in its JAR (e.g. in `src/main/resources`). +The Maven plugin automatically resolves imports from compile-scope dependency JARs, so no file system paths +to the base module are needed. + Implications: - Implies `option NoBinary` (only JSON and XML serialization are supported) - Cannot be combined with `option NoInterfaces` - The generated `Visitor` interface includes a `visitDefault()` fallback method for unknown extension types - Extension types generate their own `Visitor` sub-interface with an `instanceof`-based dispatch -CLI usage with imports: -``` -java -jar msgbuf-generator.jar -out src/main/java -resources src/main/resources -I /path/to/base-module/src/main/java extension.proto -``` - -Maven plugin configuration: +Maven plugin configuration (extension module): ```xml - - ${project.basedir}/../base-module/src/main/java - ${project.basedir}/src/main/resources ``` +Imports are resolved automatically from the compile classpath. If the base module packages its `.proto` files +as resources, no additional configuration is needed beyond declaring the dependency. + +CLI usage (standalone, without Maven): +``` +java -jar msgbuf-generator.jar -out src/main/java -resources src/main/resources -cp base-module.jar extension.proto +``` + +The `-cp` option specifies JARs to search for imported `.proto` files. The `-I` option can still be used +for file system include paths. + ## Message options ### Mix-in interfaces (`@Operations(...)`) From c54946d44d3e1706e56a7533a362a1afdfe64524 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 25 Mar 2026 11:36:52 +0100 Subject: [PATCH 169/207] test: add cross-file message embedding test Verify that the import mechanism supports embedding messages from one protocol as field types in another (not just cross-file extends). Two proto files: shared.proto defines Address/Coordinate, composite.proto imports them and uses them as fields in Person and DeliveryOrder. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../test/java/test/crossref/TestCrossRef.java | 107 ++++ .../crossref/composite/DeliveryOrder.java | 126 +++++ .../java/test/crossref/composite/Item.java | 71 +++ .../java/test/crossref/composite/Person.java | 100 ++++ .../test/crossref/composite/composite.proto | 34 ++ .../composite/impl/DeliveryOrder_Impl.java | 465 ++++++++++++++++++ .../crossref/composite/impl/Item_Impl.java | 297 +++++++++++ .../crossref/composite/impl/Person_Impl.java | 355 +++++++++++++ .../java/test/crossref/shared/Address.java | 84 ++++ .../java/test/crossref/shared/Coordinate.java | 71 +++ .../crossref/shared/impl/Address_Impl.java | 338 +++++++++++++ .../crossref/shared/impl/Coordinate_Impl.java | 297 +++++++++++ .../java/test/crossref/shared/shared.proto | 14 + 13 files changed, 2359 insertions(+) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/crossref/TestCrossRef.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/DeliveryOrder.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/Item.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/Person.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/composite.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/impl/DeliveryOrder_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/impl/Item_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/impl/Person_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/Address.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/Coordinate.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/impl/Address_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/impl/Coordinate_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/shared.proto diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/crossref/TestCrossRef.java b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/TestCrossRef.java new file mode 100644 index 00000000..aefcb41f --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/TestCrossRef.java @@ -0,0 +1,107 @@ +package test.crossref; + +import java.io.IOException; + +import de.haumacher.msgbuf.io.StringR; +import de.haumacher.msgbuf.json.JsonReader; +import junit.framework.TestCase; +import test.crossref.composite.DeliveryOrder; +import test.crossref.composite.Item; +import test.crossref.composite.Person; +import test.crossref.shared.Address; +import test.crossref.shared.Coordinate; + +/** + * Tests cross-file message embedding: composite protocol references types from shared protocol. + */ +@SuppressWarnings("javadoc") +public class TestCrossRef extends TestCase { + + public void testPersonWithAddress() throws IOException { + Person person = Person.create() + .setName("Alice") + .setAddress(Address.create() + .setStreet("Main St 1") + .setCity("Springfield") + .setZip("12345")) + .setLocation(Coordinate.create() + .setLat(48.137154) + .setLon(11.576124)); + + String json = person.toString(); + + // Deserialize and verify + Person copy = Person.readPerson(new JsonReader(new StringR(json))); + assertEquals("Alice", copy.getName()); + assertTrue(copy.hasAddress()); + assertEquals("Main St 1", copy.getAddress().getStreet()); + assertEquals("Springfield", copy.getAddress().getCity()); + assertEquals("12345", copy.getAddress().getZip()); + assertTrue(copy.hasLocation()); + assertEquals(48.137154, copy.getLocation().getLat(), 0.0001); + assertEquals(11.576124, copy.getLocation().getLon(), 0.0001); + } + + public void testDeliveryOrderWithSharedAddresses() throws IOException { + DeliveryOrder order = DeliveryOrder.create() + .setOrderId("ORD-42") + .setSender(Address.create() + .setStreet("Warehouse Ave 10") + .setCity("Munich") + .setZip("80331")) + .setRecipient(Address.create() + .setStreet("Elm St 5") + .setCity("Berlin") + .setZip("10115")); + order.addItem(Item.create().setProductName("Widget").setQuantity(3)); + order.addItem(Item.create().setProductName("Gadget").setQuantity(1)); + + String json = order.toString(); + + // Deserialize and verify + DeliveryOrder copy = DeliveryOrder.readDeliveryOrder(new JsonReader(new StringR(json))); + assertEquals("ORD-42", copy.getOrderId()); + + // Sender from shared protocol + assertTrue(copy.hasSender()); + assertEquals("Warehouse Ave 10", copy.getSender().getStreet()); + assertEquals("Munich", copy.getSender().getCity()); + + // Recipient from shared protocol + assertTrue(copy.hasRecipient()); + assertEquals("Elm St 5", copy.getRecipient().getStreet()); + assertEquals("Berlin", copy.getRecipient().getCity()); + + // Items from composite protocol + assertEquals(2, copy.getItems().size()); + assertEquals("Widget", copy.getItems().get(0).getProductName()); + assertEquals(3, copy.getItems().get(0).getQuantity()); + assertEquals("Gadget", copy.getItems().get(1).getProductName()); + } + + public void testNullEmbeddedField() throws IOException { + Person person = Person.create().setName("Bob"); + + String json = person.toString(); + Person copy = Person.readPerson(new JsonReader(new StringR(json))); + assertEquals("Bob", copy.getName()); + assertFalse(copy.hasAddress()); + assertNull(copy.getAddress()); + assertFalse(copy.hasLocation()); + assertNull(copy.getLocation()); + } + + public void testSharedTypeIndependentRoundTrip() throws IOException { + // Shared types can also be used standalone + Address addr = Address.create() + .setStreet("Solo St 99") + .setCity("Hamburg") + .setZip("20095"); + + String json = addr.toString(); + Address copy = Address.readAddress(new JsonReader(new StringR(json))); + assertEquals("Solo St 99", copy.getStreet()); + assertEquals("Hamburg", copy.getCity()); + assertEquals("20095", copy.getZip()); + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/DeliveryOrder.java b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/DeliveryOrder.java new file mode 100644 index 00000000..4a335bd0 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/DeliveryOrder.java @@ -0,0 +1,126 @@ +package test.crossref.composite; + +/** + * A delivery order referencing shared types. + */ +public interface DeliveryOrder extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.crossref.composite.DeliveryOrder} instance. + */ + static test.crossref.composite.DeliveryOrder create() { + return new test.crossref.composite.impl.DeliveryOrder_Impl(); + } + + /** Identifier for the {@link test.crossref.composite.DeliveryOrder} type in JSON format. */ + String DELIVERY_ORDER__TYPE = "DeliveryOrder"; + + /** @see #getOrderId() */ + String ORDER_ID__PROP = "orderId"; + + /** @see #getSender() */ + String SENDER__PROP = "sender"; + + /** @see #getRecipient() */ + String RECIPIENT__PROP = "recipient"; + + /** @see #getItems() */ + String ITEMS__PROP = "items"; + + /** Identifier for the property {@link #getOrderId()} in binary format. */ + static final int ORDER_ID__ID = 1; + + /** Identifier for the property {@link #getSender()} in binary format. */ + static final int SENDER__ID = 2; + + /** Identifier for the property {@link #getRecipient()} in binary format. */ + static final int RECIPIENT__ID = 3; + + /** Identifier for the property {@link #getItems()} in binary format. */ + static final int ITEMS__ID = 4; + + String getOrderId(); + + /** + * @see #getOrderId() + */ + test.crossref.composite.DeliveryOrder setOrderId(String value); + + /** + * Sender address. + */ + test.crossref.shared.Address getSender(); + + /** + * @see #getSender() + */ + test.crossref.composite.DeliveryOrder setSender(test.crossref.shared.Address value); + + /** + * Checks, whether {@link #getSender()} has a value. + */ + boolean hasSender(); + + /** + * Recipient address. + */ + test.crossref.shared.Address getRecipient(); + + /** + * @see #getRecipient() + */ + test.crossref.composite.DeliveryOrder setRecipient(test.crossref.shared.Address value); + + /** + * Checks, whether {@link #getRecipient()} has a value. + */ + boolean hasRecipient(); + + /** + * Delivery items. + */ + java.util.List getItems(); + + /** + * @see #getItems() + */ + test.crossref.composite.DeliveryOrder setItems(java.util.List value); + + /** + * Adds a value to the {@link #getItems()} list. + */ + test.crossref.composite.DeliveryOrder addItem(test.crossref.composite.Item value); + + /** + * Removes a value from the {@link #getItems()} list. + */ + void removeItem(test.crossref.composite.Item value); + + @Override + public test.crossref.composite.DeliveryOrder registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.crossref.composite.DeliveryOrder unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.crossref.composite.DeliveryOrder readDeliveryOrder(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.crossref.composite.impl.DeliveryOrder_Impl result = new test.crossref.composite.impl.DeliveryOrder_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.crossref.composite.DeliveryOrder readDeliveryOrder(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.crossref.composite.DeliveryOrder result = test.crossref.composite.impl.DeliveryOrder_Impl.readDeliveryOrder_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link DeliveryOrder} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static DeliveryOrder readDeliveryOrder(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.crossref.composite.impl.DeliveryOrder_Impl.readDeliveryOrder_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/Item.java b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/Item.java new file mode 100644 index 00000000..c21b9685 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/Item.java @@ -0,0 +1,71 @@ +package test.crossref.composite; + +/** + * An item in a delivery. + */ +public interface Item extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.crossref.composite.Item} instance. + */ + static test.crossref.composite.Item create() { + return new test.crossref.composite.impl.Item_Impl(); + } + + /** Identifier for the {@link test.crossref.composite.Item} type in JSON format. */ + String ITEM__TYPE = "Item"; + + /** @see #getProductName() */ + String PRODUCT_NAME__PROP = "productName"; + + /** @see #getQuantity() */ + String QUANTITY__PROP = "quantity"; + + /** Identifier for the property {@link #getProductName()} in binary format. */ + static final int PRODUCT_NAME__ID = 1; + + /** Identifier for the property {@link #getQuantity()} in binary format. */ + static final int QUANTITY__ID = 2; + + String getProductName(); + + /** + * @see #getProductName() + */ + test.crossref.composite.Item setProductName(String value); + + int getQuantity(); + + /** + * @see #getQuantity() + */ + test.crossref.composite.Item setQuantity(int value); + + @Override + public test.crossref.composite.Item registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.crossref.composite.Item unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.crossref.composite.Item readItem(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.crossref.composite.impl.Item_Impl result = new test.crossref.composite.impl.Item_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.crossref.composite.Item readItem(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.crossref.composite.Item result = test.crossref.composite.impl.Item_Impl.readItem_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Item} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Item readItem(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.crossref.composite.impl.Item_Impl.readItem_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/Person.java b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/Person.java new file mode 100644 index 00000000..b85f2bd3 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/Person.java @@ -0,0 +1,100 @@ +package test.crossref.composite; + +/** + * A person with an address from the shared protocol. + */ +public interface Person extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.crossref.composite.Person} instance. + */ + static test.crossref.composite.Person create() { + return new test.crossref.composite.impl.Person_Impl(); + } + + /** Identifier for the {@link test.crossref.composite.Person} type in JSON format. */ + String PERSON__TYPE = "Person"; + + /** @see #getName() */ + String NAME__PROP = "name"; + + /** @see #getAddress() */ + String ADDRESS__PROP = "address"; + + /** @see #getLocation() */ + String LOCATION__PROP = "location"; + + /** Identifier for the property {@link #getName()} in binary format. */ + static final int NAME__ID = 1; + + /** Identifier for the property {@link #getAddress()} in binary format. */ + static final int ADDRESS__ID = 2; + + /** Identifier for the property {@link #getLocation()} in binary format. */ + static final int LOCATION__ID = 3; + + String getName(); + + /** + * @see #getName() + */ + test.crossref.composite.Person setName(String value); + + /** + * The person's home address (embedded from shared protocol). + */ + test.crossref.shared.Address getAddress(); + + /** + * @see #getAddress() + */ + test.crossref.composite.Person setAddress(test.crossref.shared.Address value); + + /** + * Checks, whether {@link #getAddress()} has a value. + */ + boolean hasAddress(); + + /** + * The person's location. + */ + test.crossref.shared.Coordinate getLocation(); + + /** + * @see #getLocation() + */ + test.crossref.composite.Person setLocation(test.crossref.shared.Coordinate value); + + /** + * Checks, whether {@link #getLocation()} has a value. + */ + boolean hasLocation(); + + @Override + public test.crossref.composite.Person registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.crossref.composite.Person unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.crossref.composite.Person readPerson(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.crossref.composite.impl.Person_Impl result = new test.crossref.composite.impl.Person_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.crossref.composite.Person readPerson(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.crossref.composite.Person result = test.crossref.composite.impl.Person_Impl.readPerson_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Person} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Person readPerson(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.crossref.composite.impl.Person_Impl.readPerson_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/composite.proto b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/composite.proto new file mode 100644 index 00000000..d488304a --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/composite.proto @@ -0,0 +1,34 @@ +package test.crossref.composite; + +import "../shared/shared.proto"; + +/** A person with an address from the shared protocol. */ +message Person { + string name; + + /** The person's home address (embedded from shared protocol). */ + test.crossref.shared.Address address; + + /** The person's location. */ + test.crossref.shared.Coordinate location; +} + +/** A delivery order referencing shared types. */ +message DeliveryOrder { + string orderId; + + /** Sender address. */ + test.crossref.shared.Address sender; + + /** Recipient address. */ + test.crossref.shared.Address recipient; + + /** Delivery items. */ + repeated Item items; +} + +/** An item in a delivery. */ +message Item { + string productName; + int32 quantity; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/impl/DeliveryOrder_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/impl/DeliveryOrder_Impl.java new file mode 100644 index 00000000..d9c2a27b --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/impl/DeliveryOrder_Impl.java @@ -0,0 +1,465 @@ +package test.crossref.composite.impl; + +/** + * Implementation of {@link test.crossref.composite.DeliveryOrder}. + */ +public class DeliveryOrder_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.crossref.composite.DeliveryOrder { + + private String _orderId = ""; + + private test.crossref.shared.Address _sender = null; + + private test.crossref.shared.Address _recipient = null; + + private final java.util.List _items = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.crossref.composite.Item element) { + _listener.beforeAdd(DeliveryOrder_Impl.this, ITEMS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.crossref.composite.Item element) { + _listener.afterRemove(DeliveryOrder_Impl.this, ITEMS__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(DeliveryOrder_Impl.this, ITEMS__PROP); + } + }; + + /** + * Creates a {@link DeliveryOrder_Impl} instance. + * + * @see test.crossref.composite.DeliveryOrder#create() + */ + public DeliveryOrder_Impl() { + super(); + } + + @Override + public final String getOrderId() { + return _orderId; + } + + @Override + public test.crossref.composite.DeliveryOrder setOrderId(String value) { + internalSetOrderId(value); + return this; + } + + /** Internal setter for {@link #getOrderId()} without chain call utility. */ + protected final void internalSetOrderId(String value) { + _listener.beforeSet(this, ORDER_ID__PROP, value); + _orderId = value; + _listener.afterChanged(this, ORDER_ID__PROP); + } + + @Override + public final test.crossref.shared.Address getSender() { + return _sender; + } + + @Override + public test.crossref.composite.DeliveryOrder setSender(test.crossref.shared.Address value) { + internalSetSender(value); + return this; + } + + /** Internal setter for {@link #getSender()} without chain call utility. */ + protected final void internalSetSender(test.crossref.shared.Address value) { + _listener.beforeSet(this, SENDER__PROP, value); + _sender = value; + _listener.afterChanged(this, SENDER__PROP); + } + + @Override + public final boolean hasSender() { + return _sender != null; + } + + @Override + public final test.crossref.shared.Address getRecipient() { + return _recipient; + } + + @Override + public test.crossref.composite.DeliveryOrder setRecipient(test.crossref.shared.Address value) { + internalSetRecipient(value); + return this; + } + + /** Internal setter for {@link #getRecipient()} without chain call utility. */ + protected final void internalSetRecipient(test.crossref.shared.Address value) { + _listener.beforeSet(this, RECIPIENT__PROP, value); + _recipient = value; + _listener.afterChanged(this, RECIPIENT__PROP); + } + + @Override + public final boolean hasRecipient() { + return _recipient != null; + } + + @Override + public final java.util.List getItems() { + return _items; + } + + @Override + public test.crossref.composite.DeliveryOrder setItems(java.util.List value) { + internalSetItems(value); + return this; + } + + /** Internal setter for {@link #getItems()} without chain call utility. */ + protected final void internalSetItems(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'items' cannot be null."); + _items.clear(); + _items.addAll(value); + } + + @Override + public test.crossref.composite.DeliveryOrder addItem(test.crossref.composite.Item value) { + internalAddItem(value); + return this; + } + + /** Implementation of {@link #addItem(test.crossref.composite.Item)} without chain call utility. */ + protected final void internalAddItem(test.crossref.composite.Item value) { + _items.add(value); + } + + @Override + public final void removeItem(test.crossref.composite.Item value) { + _items.remove(value); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.crossref.composite.DeliveryOrder registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.crossref.composite.DeliveryOrder unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return DELIVERY_ORDER__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + ORDER_ID__PROP, + SENDER__PROP, + RECIPIENT__PROP, + ITEMS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case ORDER_ID__PROP: return getOrderId(); + case SENDER__PROP: return getSender(); + case RECIPIENT__PROP: return getRecipient(); + case ITEMS__PROP: return getItems(); + default: return test.crossref.composite.DeliveryOrder.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case ORDER_ID__PROP: internalSetOrderId((String) value); break; + case SENDER__PROP: internalSetSender((test.crossref.shared.Address) value); break; + case RECIPIENT__PROP: internalSetRecipient((test.crossref.shared.Address) value); break; + case ITEMS__PROP: internalSetItems(de.haumacher.msgbuf.util.Conversions.asList(test.crossref.composite.Item.class, value)); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(ORDER_ID__PROP); + out.value(getOrderId()); + if (hasSender()) { + out.name(SENDER__PROP); + getSender().writeTo(out); + } + if (hasRecipient()) { + out.name(RECIPIENT__PROP); + getRecipient().writeTo(out); + } + out.name(ITEMS__PROP); + out.beginArray(); + for (test.crossref.composite.Item x : getItems()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case ORDER_ID__PROP: setOrderId(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case SENDER__PROP: setSender(test.crossref.shared.Address.readAddress(in)); break; + case RECIPIENT__PROP: setRecipient(test.crossref.shared.Address.readAddress(in)); break; + case ITEMS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.crossref.composite.Item.readItem(in)); + } + in.endArray(); + setItems(newValue); + } + break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(ORDER_ID__ID); + out.value(getOrderId()); + if (hasSender()) { + out.name(SENDER__ID); + getSender().writeTo(out); + } + if (hasRecipient()) { + out.name(RECIPIENT__ID); + getRecipient().writeTo(out); + } + out.name(ITEMS__ID); + { + java.util.List values = getItems(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.crossref.composite.Item x : values) { + x.writeTo(out); + } + out.endArray(); + } + } + + /** Helper for creating an object of type {@link test.crossref.composite.DeliveryOrder} from a polymorphic composition. */ + public static test.crossref.composite.DeliveryOrder readDeliveryOrder_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.crossref.composite.impl.DeliveryOrder_Impl result = new DeliveryOrder_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case ORDER_ID__ID: setOrderId(in.nextString()); break; + case SENDER__ID: setSender(test.crossref.shared.Address.readAddress(in)); break; + case RECIPIENT__ID: setRecipient(test.crossref.shared.Address.readAddress(in)); break; + case ITEMS__ID: { + in.beginArray(); + while (in.hasNext()) { + addItem(test.crossref.composite.Item.readItem(in)); + } + in.endArray(); + } + break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.crossref.composite.DeliveryOrder} type. */ + public static final String DELIVERY_ORDER__XML_ELEMENT = "delivery-order"; + + /** XML attribute or element name of a {@link #getOrderId} property. */ + private static final String ORDER_ID__XML_ATTR = "order-id"; + + /** XML attribute or element name of a {@link #getSender} property. */ + private static final String SENDER__XML_ATTR = "sender"; + + /** XML attribute or element name of a {@link #getRecipient} property. */ + private static final String RECIPIENT__XML_ATTR = "recipient"; + + /** XML attribute or element name of a {@link #getItems} property. */ + private static final String ITEMS__XML_ATTR = "items"; + + @Override + public String getXmlTagName() { + return DELIVERY_ORDER__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(ORDER_ID__XML_ATTR, getOrderId()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasSender()) { + out.writeStartElement(SENDER__XML_ATTR); + getSender().writeContent(out); + out.writeEndElement(); + } + if (hasRecipient()) { + out.writeStartElement(RECIPIENT__XML_ATTR); + getRecipient().writeContent(out); + out.writeEndElement(); + } + out.writeStartElement(ITEMS__XML_ATTR); + for (test.crossref.composite.Item element : getItems()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.crossref.composite.DeliveryOrder} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static DeliveryOrder_Impl readDeliveryOrder_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + DeliveryOrder_Impl result = new DeliveryOrder_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case ORDER_ID__XML_ATTR: { + setOrderId(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case ORDER_ID__XML_ATTR: { + setOrderId(in.getElementText()); + break; + } + case SENDER__XML_ATTR: { + setSender(test.crossref.shared.impl.Address_Impl.readAddress_XmlContent(in)); + break; + } + case RECIPIENT__XML_ATTR: { + setRecipient(test.crossref.shared.impl.Address_Impl.readAddress_XmlContent(in)); + break; + } + case ITEMS__XML_ATTR: { + internalReadItemsListXml(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadItemsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addItem(test.crossref.composite.impl.Item_Impl.readItem_XmlContent(in)); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/impl/Item_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/impl/Item_Impl.java new file mode 100644 index 00000000..961b8092 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/impl/Item_Impl.java @@ -0,0 +1,297 @@ +package test.crossref.composite.impl; + +/** + * Implementation of {@link test.crossref.composite.Item}. + */ +public class Item_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.crossref.composite.Item { + + private String _productName = ""; + + private int _quantity = 0; + + /** + * Creates a {@link Item_Impl} instance. + * + * @see test.crossref.composite.Item#create() + */ + public Item_Impl() { + super(); + } + + @Override + public final String getProductName() { + return _productName; + } + + @Override + public test.crossref.composite.Item setProductName(String value) { + internalSetProductName(value); + return this; + } + + /** Internal setter for {@link #getProductName()} without chain call utility. */ + protected final void internalSetProductName(String value) { + _listener.beforeSet(this, PRODUCT_NAME__PROP, value); + _productName = value; + _listener.afterChanged(this, PRODUCT_NAME__PROP); + } + + @Override + public final int getQuantity() { + return _quantity; + } + + @Override + public test.crossref.composite.Item setQuantity(int value) { + internalSetQuantity(value); + return this; + } + + /** Internal setter for {@link #getQuantity()} without chain call utility. */ + protected final void internalSetQuantity(int value) { + _listener.beforeSet(this, QUANTITY__PROP, value); + _quantity = value; + _listener.afterChanged(this, QUANTITY__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.crossref.composite.Item registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.crossref.composite.Item unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return ITEM__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + PRODUCT_NAME__PROP, + QUANTITY__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case PRODUCT_NAME__PROP: return getProductName(); + case QUANTITY__PROP: return getQuantity(); + default: return test.crossref.composite.Item.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case PRODUCT_NAME__PROP: internalSetProductName((String) value); break; + case QUANTITY__PROP: internalSetQuantity((int) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(PRODUCT_NAME__PROP); + out.value(getProductName()); + out.name(QUANTITY__PROP); + out.value(getQuantity()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case PRODUCT_NAME__PROP: setProductName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case QUANTITY__PROP: setQuantity(in.nextInt()); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(PRODUCT_NAME__ID); + out.value(getProductName()); + out.name(QUANTITY__ID); + out.value(getQuantity()); + } + + /** Helper for creating an object of type {@link test.crossref.composite.Item} from a polymorphic composition. */ + public static test.crossref.composite.Item readItem_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.crossref.composite.impl.Item_Impl result = new Item_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case PRODUCT_NAME__ID: setProductName(in.nextString()); break; + case QUANTITY__ID: setQuantity(in.nextInt()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.crossref.composite.Item} type. */ + public static final String ITEM__XML_ELEMENT = "item"; + + /** XML attribute or element name of a {@link #getProductName} property. */ + private static final String PRODUCT_NAME__XML_ATTR = "product-name"; + + /** XML attribute or element name of a {@link #getQuantity} property. */ + private static final String QUANTITY__XML_ATTR = "quantity"; + + @Override + public String getXmlTagName() { + return ITEM__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(PRODUCT_NAME__XML_ATTR, getProductName()); + out.writeAttribute(QUANTITY__XML_ATTR, Integer.toString(getQuantity())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.crossref.composite.Item} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Item_Impl readItem_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Item_Impl result = new Item_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case PRODUCT_NAME__XML_ATTR: { + setProductName(value); + break; + } + case QUANTITY__XML_ATTR: { + setQuantity(Integer.parseInt(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case PRODUCT_NAME__XML_ATTR: { + setProductName(in.getElementText()); + break; + } + case QUANTITY__XML_ATTR: { + setQuantity(Integer.parseInt(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/impl/Person_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/impl/Person_Impl.java new file mode 100644 index 00000000..0e504b30 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/composite/impl/Person_Impl.java @@ -0,0 +1,355 @@ +package test.crossref.composite.impl; + +/** + * Implementation of {@link test.crossref.composite.Person}. + */ +public class Person_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.crossref.composite.Person { + + private String _name = ""; + + private test.crossref.shared.Address _address = null; + + private test.crossref.shared.Coordinate _location = null; + + /** + * Creates a {@link Person_Impl} instance. + * + * @see test.crossref.composite.Person#create() + */ + public Person_Impl() { + super(); + } + + @Override + public final String getName() { + return _name; + } + + @Override + public test.crossref.composite.Person setName(String value) { + internalSetName(value); + return this; + } + + /** Internal setter for {@link #getName()} without chain call utility. */ + protected final void internalSetName(String value) { + _listener.beforeSet(this, NAME__PROP, value); + _name = value; + _listener.afterChanged(this, NAME__PROP); + } + + @Override + public final test.crossref.shared.Address getAddress() { + return _address; + } + + @Override + public test.crossref.composite.Person setAddress(test.crossref.shared.Address value) { + internalSetAddress(value); + return this; + } + + /** Internal setter for {@link #getAddress()} without chain call utility. */ + protected final void internalSetAddress(test.crossref.shared.Address value) { + _listener.beforeSet(this, ADDRESS__PROP, value); + _address = value; + _listener.afterChanged(this, ADDRESS__PROP); + } + + @Override + public final boolean hasAddress() { + return _address != null; + } + + @Override + public final test.crossref.shared.Coordinate getLocation() { + return _location; + } + + @Override + public test.crossref.composite.Person setLocation(test.crossref.shared.Coordinate value) { + internalSetLocation(value); + return this; + } + + /** Internal setter for {@link #getLocation()} without chain call utility. */ + protected final void internalSetLocation(test.crossref.shared.Coordinate value) { + _listener.beforeSet(this, LOCATION__PROP, value); + _location = value; + _listener.afterChanged(this, LOCATION__PROP); + } + + @Override + public final boolean hasLocation() { + return _location != null; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.crossref.composite.Person registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.crossref.composite.Person unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return PERSON__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + NAME__PROP, + ADDRESS__PROP, + LOCATION__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NAME__PROP: return getName(); + case ADDRESS__PROP: return getAddress(); + case LOCATION__PROP: return getLocation(); + default: return test.crossref.composite.Person.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NAME__PROP: internalSetName((String) value); break; + case ADDRESS__PROP: internalSetAddress((test.crossref.shared.Address) value); break; + case LOCATION__PROP: internalSetLocation((test.crossref.shared.Coordinate) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NAME__PROP); + out.value(getName()); + if (hasAddress()) { + out.name(ADDRESS__PROP); + getAddress().writeTo(out); + } + if (hasLocation()) { + out.name(LOCATION__PROP); + getLocation().writeTo(out); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case ADDRESS__PROP: setAddress(test.crossref.shared.Address.readAddress(in)); break; + case LOCATION__PROP: setLocation(test.crossref.shared.Coordinate.readCoordinate(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(NAME__ID); + out.value(getName()); + if (hasAddress()) { + out.name(ADDRESS__ID); + getAddress().writeTo(out); + } + if (hasLocation()) { + out.name(LOCATION__ID); + getLocation().writeTo(out); + } + } + + /** Helper for creating an object of type {@link test.crossref.composite.Person} from a polymorphic composition. */ + public static test.crossref.composite.Person readPerson_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.crossref.composite.impl.Person_Impl result = new Person_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case NAME__ID: setName(in.nextString()); break; + case ADDRESS__ID: setAddress(test.crossref.shared.Address.readAddress(in)); break; + case LOCATION__ID: setLocation(test.crossref.shared.Coordinate.readCoordinate(in)); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.crossref.composite.Person} type. */ + public static final String PERSON__XML_ELEMENT = "person"; + + /** XML attribute or element name of a {@link #getName} property. */ + private static final String NAME__XML_ATTR = "name"; + + /** XML attribute or element name of a {@link #getAddress} property. */ + private static final String ADDRESS__XML_ATTR = "address"; + + /** XML attribute or element name of a {@link #getLocation} property. */ + private static final String LOCATION__XML_ATTR = "location"; + + @Override + public String getXmlTagName() { + return PERSON__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasAddress()) { + out.writeStartElement(ADDRESS__XML_ATTR); + getAddress().writeContent(out); + out.writeEndElement(); + } + if (hasLocation()) { + out.writeStartElement(LOCATION__XML_ATTR); + getLocation().writeContent(out); + out.writeEndElement(); + } + } + + /** Creates a new {@link test.crossref.composite.Person} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Person_Impl readPerson_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Person_Impl result = new Person_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NAME__XML_ATTR: { + setName(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NAME__XML_ATTR: { + setName(in.getElementText()); + break; + } + case ADDRESS__XML_ATTR: { + setAddress(test.crossref.shared.impl.Address_Impl.readAddress_XmlContent(in)); + break; + } + case LOCATION__XML_ATTR: { + setLocation(test.crossref.shared.impl.Coordinate_Impl.readCoordinate_XmlContent(in)); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/Address.java b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/Address.java new file mode 100644 index 00000000..15cb5015 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/Address.java @@ -0,0 +1,84 @@ +package test.crossref.shared; + +/** + * Shared address type used by other protocols. + */ +public interface Address extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.crossref.shared.Address} instance. + */ + static test.crossref.shared.Address create() { + return new test.crossref.shared.impl.Address_Impl(); + } + + /** Identifier for the {@link test.crossref.shared.Address} type in JSON format. */ + String ADDRESS__TYPE = "Address"; + + /** @see #getStreet() */ + String STREET__PROP = "street"; + + /** @see #getCity() */ + String CITY__PROP = "city"; + + /** @see #getZip() */ + String ZIP__PROP = "zip"; + + /** Identifier for the property {@link #getStreet()} in binary format. */ + static final int STREET__ID = 1; + + /** Identifier for the property {@link #getCity()} in binary format. */ + static final int CITY__ID = 2; + + /** Identifier for the property {@link #getZip()} in binary format. */ + static final int ZIP__ID = 3; + + String getStreet(); + + /** + * @see #getStreet() + */ + test.crossref.shared.Address setStreet(String value); + + String getCity(); + + /** + * @see #getCity() + */ + test.crossref.shared.Address setCity(String value); + + String getZip(); + + /** + * @see #getZip() + */ + test.crossref.shared.Address setZip(String value); + + @Override + public test.crossref.shared.Address registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.crossref.shared.Address unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.crossref.shared.Address readAddress(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.crossref.shared.impl.Address_Impl result = new test.crossref.shared.impl.Address_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.crossref.shared.Address readAddress(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.crossref.shared.Address result = test.crossref.shared.impl.Address_Impl.readAddress_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Address} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Address readAddress(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.crossref.shared.impl.Address_Impl.readAddress_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/Coordinate.java b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/Coordinate.java new file mode 100644 index 00000000..2b17d8b9 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/Coordinate.java @@ -0,0 +1,71 @@ +package test.crossref.shared; + +/** + * A coordinate pair. + */ +public interface Coordinate extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.crossref.shared.Coordinate} instance. + */ + static test.crossref.shared.Coordinate create() { + return new test.crossref.shared.impl.Coordinate_Impl(); + } + + /** Identifier for the {@link test.crossref.shared.Coordinate} type in JSON format. */ + String COORDINATE__TYPE = "Coordinate"; + + /** @see #getLat() */ + String LAT__PROP = "lat"; + + /** @see #getLon() */ + String LON__PROP = "lon"; + + /** Identifier for the property {@link #getLat()} in binary format. */ + static final int LAT__ID = 1; + + /** Identifier for the property {@link #getLon()} in binary format. */ + static final int LON__ID = 2; + + double getLat(); + + /** + * @see #getLat() + */ + test.crossref.shared.Coordinate setLat(double value); + + double getLon(); + + /** + * @see #getLon() + */ + test.crossref.shared.Coordinate setLon(double value); + + @Override + public test.crossref.shared.Coordinate registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.crossref.shared.Coordinate unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.crossref.shared.Coordinate readCoordinate(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.crossref.shared.impl.Coordinate_Impl result = new test.crossref.shared.impl.Coordinate_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.crossref.shared.Coordinate readCoordinate(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.crossref.shared.Coordinate result = test.crossref.shared.impl.Coordinate_Impl.readCoordinate_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Coordinate} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Coordinate readCoordinate(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.crossref.shared.impl.Coordinate_Impl.readCoordinate_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/impl/Address_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/impl/Address_Impl.java new file mode 100644 index 00000000..4194c298 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/impl/Address_Impl.java @@ -0,0 +1,338 @@ +package test.crossref.shared.impl; + +/** + * Implementation of {@link test.crossref.shared.Address}. + */ +public class Address_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.crossref.shared.Address { + + private String _street = ""; + + private String _city = ""; + + private String _zip = ""; + + /** + * Creates a {@link Address_Impl} instance. + * + * @see test.crossref.shared.Address#create() + */ + public Address_Impl() { + super(); + } + + @Override + public final String getStreet() { + return _street; + } + + @Override + public test.crossref.shared.Address setStreet(String value) { + internalSetStreet(value); + return this; + } + + /** Internal setter for {@link #getStreet()} without chain call utility. */ + protected final void internalSetStreet(String value) { + _listener.beforeSet(this, STREET__PROP, value); + _street = value; + _listener.afterChanged(this, STREET__PROP); + } + + @Override + public final String getCity() { + return _city; + } + + @Override + public test.crossref.shared.Address setCity(String value) { + internalSetCity(value); + return this; + } + + /** Internal setter for {@link #getCity()} without chain call utility. */ + protected final void internalSetCity(String value) { + _listener.beforeSet(this, CITY__PROP, value); + _city = value; + _listener.afterChanged(this, CITY__PROP); + } + + @Override + public final String getZip() { + return _zip; + } + + @Override + public test.crossref.shared.Address setZip(String value) { + internalSetZip(value); + return this; + } + + /** Internal setter for {@link #getZip()} without chain call utility. */ + protected final void internalSetZip(String value) { + _listener.beforeSet(this, ZIP__PROP, value); + _zip = value; + _listener.afterChanged(this, ZIP__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.crossref.shared.Address registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.crossref.shared.Address unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return ADDRESS__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + STREET__PROP, + CITY__PROP, + ZIP__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case STREET__PROP: return getStreet(); + case CITY__PROP: return getCity(); + case ZIP__PROP: return getZip(); + default: return test.crossref.shared.Address.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case STREET__PROP: internalSetStreet((String) value); break; + case CITY__PROP: internalSetCity((String) value); break; + case ZIP__PROP: internalSetZip((String) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(STREET__PROP); + out.value(getStreet()); + out.name(CITY__PROP); + out.value(getCity()); + out.name(ZIP__PROP); + out.value(getZip()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case STREET__PROP: setStreet(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case CITY__PROP: setCity(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case ZIP__PROP: setZip(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(STREET__ID); + out.value(getStreet()); + out.name(CITY__ID); + out.value(getCity()); + out.name(ZIP__ID); + out.value(getZip()); + } + + /** Helper for creating an object of type {@link test.crossref.shared.Address} from a polymorphic composition. */ + public static test.crossref.shared.Address readAddress_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.crossref.shared.impl.Address_Impl result = new Address_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case STREET__ID: setStreet(in.nextString()); break; + case CITY__ID: setCity(in.nextString()); break; + case ZIP__ID: setZip(in.nextString()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.crossref.shared.Address} type. */ + public static final String ADDRESS__XML_ELEMENT = "address"; + + /** XML attribute or element name of a {@link #getStreet} property. */ + private static final String STREET__XML_ATTR = "street"; + + /** XML attribute or element name of a {@link #getCity} property. */ + private static final String CITY__XML_ATTR = "city"; + + /** XML attribute or element name of a {@link #getZip} property. */ + private static final String ZIP__XML_ATTR = "zip"; + + @Override + public String getXmlTagName() { + return ADDRESS__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(STREET__XML_ATTR, getStreet()); + out.writeAttribute(CITY__XML_ATTR, getCity()); + out.writeAttribute(ZIP__XML_ATTR, getZip()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.crossref.shared.Address} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Address_Impl readAddress_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Address_Impl result = new Address_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case STREET__XML_ATTR: { + setStreet(value); + break; + } + case CITY__XML_ATTR: { + setCity(value); + break; + } + case ZIP__XML_ATTR: { + setZip(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case STREET__XML_ATTR: { + setStreet(in.getElementText()); + break; + } + case CITY__XML_ATTR: { + setCity(in.getElementText()); + break; + } + case ZIP__XML_ATTR: { + setZip(in.getElementText()); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/impl/Coordinate_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/impl/Coordinate_Impl.java new file mode 100644 index 00000000..f4ffdf3e --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/impl/Coordinate_Impl.java @@ -0,0 +1,297 @@ +package test.crossref.shared.impl; + +/** + * Implementation of {@link test.crossref.shared.Coordinate}. + */ +public class Coordinate_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.crossref.shared.Coordinate { + + private double _lat = 0.0d; + + private double _lon = 0.0d; + + /** + * Creates a {@link Coordinate_Impl} instance. + * + * @see test.crossref.shared.Coordinate#create() + */ + public Coordinate_Impl() { + super(); + } + + @Override + public final double getLat() { + return _lat; + } + + @Override + public test.crossref.shared.Coordinate setLat(double value) { + internalSetLat(value); + return this; + } + + /** Internal setter for {@link #getLat()} without chain call utility. */ + protected final void internalSetLat(double value) { + _listener.beforeSet(this, LAT__PROP, value); + _lat = value; + _listener.afterChanged(this, LAT__PROP); + } + + @Override + public final double getLon() { + return _lon; + } + + @Override + public test.crossref.shared.Coordinate setLon(double value) { + internalSetLon(value); + return this; + } + + /** Internal setter for {@link #getLon()} without chain call utility. */ + protected final void internalSetLon(double value) { + _listener.beforeSet(this, LON__PROP, value); + _lon = value; + _listener.afterChanged(this, LON__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.crossref.shared.Coordinate registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.crossref.shared.Coordinate unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return COORDINATE__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + LAT__PROP, + LON__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case LAT__PROP: return getLat(); + case LON__PROP: return getLon(); + default: return test.crossref.shared.Coordinate.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case LAT__PROP: internalSetLat((double) value); break; + case LON__PROP: internalSetLon((double) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(LAT__PROP); + out.value(getLat()); + out.name(LON__PROP); + out.value(getLon()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case LAT__PROP: setLat(in.nextDouble()); break; + case LON__PROP: setLon(in.nextDouble()); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(LAT__ID); + out.value(getLat()); + out.name(LON__ID); + out.value(getLon()); + } + + /** Helper for creating an object of type {@link test.crossref.shared.Coordinate} from a polymorphic composition. */ + public static test.crossref.shared.Coordinate readCoordinate_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.crossref.shared.impl.Coordinate_Impl result = new Coordinate_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case LAT__ID: setLat(in.nextDouble()); break; + case LON__ID: setLon(in.nextDouble()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.crossref.shared.Coordinate} type. */ + public static final String COORDINATE__XML_ELEMENT = "coordinate"; + + /** XML attribute or element name of a {@link #getLat} property. */ + private static final String LAT__XML_ATTR = "lat"; + + /** XML attribute or element name of a {@link #getLon} property. */ + private static final String LON__XML_ATTR = "lon"; + + @Override + public String getXmlTagName() { + return COORDINATE__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(LAT__XML_ATTR, Double.toString(getLat())); + out.writeAttribute(LON__XML_ATTR, Double.toString(getLon())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.crossref.shared.Coordinate} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Coordinate_Impl readCoordinate_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Coordinate_Impl result = new Coordinate_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case LAT__XML_ATTR: { + setLat(Double.parseDouble(value)); + break; + } + case LON__XML_ATTR: { + setLon(Double.parseDouble(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case LAT__XML_ATTR: { + setLat(Double.parseDouble(in.getElementText())); + break; + } + case LON__XML_ATTR: { + setLon(Double.parseDouble(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/shared.proto b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/shared.proto new file mode 100644 index 00000000..bbe73f82 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/crossref/shared/shared.proto @@ -0,0 +1,14 @@ +package test.crossref.shared; + +/** Shared address type used by other protocols. */ +message Address { + string street; + string city; + string zip; +} + +/** A coordinate pair. */ +message Coordinate { + double lat; + double lon; +} From dbcdd211e7f9ffb382ac7423e62f39a216045d1f Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 25 Mar 2026 11:37:16 +0100 Subject: [PATCH 170/207] feat: add native json field type with JsonValue envelope for binary Add a `json` primitive type to msgbuf that represents an opaque JSON value. In JSON format, the value is written natively without string-wrapping. For binary serialization, values are wrapped in a JsonValue message hierarchy (JsonString, JsonLong, JsonDouble, JsonBoolean, JsonNull, JsonArray, JsonObject). Also fixes a pre-existing bug where map fields were not serialized in binary format (binaryWriteValue had a TODO for MapType). Closes #11 Co-Authored-By: Claude Opus 4.6 (1M context) --- .../generator/DefaultValueGenerator.java | 1 + .../msgbuf/generator/MessageGenerator.java | 54 +++- .../msgbuf/generator/TypeGenerator.java | 2 + .../msgbuf/generator/ast/Constant.java | 2 +- .../msgbuf/generator/ast/CustomType.java | 2 +- .../msgbuf/generator/ast/Definition.java | 2 +- .../msgbuf/generator/ast/DefinitionBase.java | 2 +- .../msgbuf/generator/ast/DefinitionFile.java | 2 +- .../msgbuf/generator/ast/EnumDef.java | 2 +- .../haumacher/msgbuf/generator/ast/Field.java | 2 +- .../haumacher/msgbuf/generator/ast/Flag.java | 2 +- .../msgbuf/generator/ast/MapType.java | 2 +- .../msgbuf/generator/ast/MessageDef.java | 2 +- .../msgbuf/generator/ast/NumberOption.java | 2 +- .../msgbuf/generator/ast/OptionContainer.java | 2 +- .../haumacher/msgbuf/generator/ast/Part.java | 2 +- .../msgbuf/generator/ast/PrimitiveType.java | 10 +- .../msgbuf/generator/ast/StringOption.java | 2 +- .../msgbuf/generator/ast/WithOptions.java | 2 +- .../msgbuf/generator/ast/proto.proto | 3 + .../msgbuf/generator/common/Util.java | 4 + .../generator/parser/ProtobufParser.java | 115 ++++---- .../parser/ProtobufParserConstants.java | 17 +- .../parser/ProtobufParserTokenManager.java | 256 +++++++++--------- .../msgbuf/generator/parser/protobuf.jj | 5 + .../generator/plugins/XmlStreamingPlugin.java | 10 +- .../model/impl/MyContainer_Impl.java | 12 + .../nointerfaces/model/MyContainer.java | 12 + .../java/test/jsonbinary/TestJsonBinary.java | 124 +++++++++ .../jsonbinary/data/BinaryPatchEvent.java | 67 +++++ .../data/impl/BinaryPatchEvent_Impl.java | 130 +++++++++ .../test/jsonbinary/data/jsonbinary.proto | 14 + .../java/test/jsonvalue/TestJsonValue.java | 156 +++++++++++ .../test/jsonvalue/data/DynamicConfig.java | 71 +++++ .../java/test/jsonvalue/data/PatchEvent.java | 56 ++++ .../data/impl/DynamicConfig_Impl.java | 111 ++++++++ .../jsonvalue/data/impl/PatchEvent_Impl.java | 83 ++++++ .../java/test/jsonvalue/data/jsonvalue.proto | 27 ++ .../maptype/data/impl/MyMessage_Impl.java | 24 ++ .../data/impl/NullableValues_Impl.java | 12 + .../de/haumacher/msgbuf/json/JsonUtil.java | 224 ++++++++++++++- .../msgbuf/json/value/JsonArray.java | 245 +++++++++++++++++ .../msgbuf/json/value/JsonBoolean.java | 186 +++++++++++++ .../msgbuf/json/value/JsonDouble.java | 186 +++++++++++++ .../haumacher/msgbuf/json/value/JsonLong.java | 186 +++++++++++++ .../haumacher/msgbuf/json/value/JsonNull.java | 119 ++++++++ .../msgbuf/json/value/JsonObject.java | 245 +++++++++++++++++ .../msgbuf/json/value/JsonString.java | 186 +++++++++++++ .../msgbuf/json/value/JsonValue.java | 244 +++++++++++++++++ .../msgbuf/json/value/jsonvalue.proto | 44 +++ 50 files changed, 3062 insertions(+), 209 deletions(-) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/TestJsonBinary.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/data/BinaryPatchEvent.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/data/impl/BinaryPatchEvent_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/data/jsonbinary.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/TestJsonValue.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/DynamicConfig.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/PatchEvent.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/impl/DynamicConfig_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/impl/PatchEvent_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/jsonvalue.proto create mode 100644 de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonArray.java create mode 100644 de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonBoolean.java create mode 100644 de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonDouble.java create mode 100644 de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonLong.java create mode 100644 de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonNull.java create mode 100644 de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonObject.java create mode 100644 de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonString.java create mode 100644 de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonValue.java create mode 100644 de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/jsonvalue.proto diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/DefaultValueGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/DefaultValueGenerator.java index 38599252..5484608a 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/DefaultValueGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/DefaultValueGenerator.java @@ -66,6 +66,7 @@ public String visit(PrimitiveType self, Void arg) { switch (self.getKind()) { case BOOL: return "false"; case BYTES: return "null"; + case JSON: return "null"; case DOUBLE: return "0.0d"; case FLOAT: return "0.0f"; case STRING: return "\"\""; diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 2df0424d..d3d7abd4 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -1683,8 +1683,11 @@ private String jsonType(PrimitiveType.Kind primitive) { case BYTES: return "de.haumacher.msgbuf.json.JsonUtil.nextBinaryOptional(in)"; - } - + + case JSON: + return "de.haumacher.msgbuf.json.JsonUtil.nextJsonValue(in)"; + } + throw new RuntimeException("No such type: " + primitive); } @@ -1699,6 +1702,10 @@ private void jsonOutValue(Type type, String x, int depth) { line("de.haumacher.msgbuf.json.JsonUtil.writeBinaryOptional(out, " + x + ");"); break; } + case JSON: { + line("de.haumacher.msgbuf.json.JsonUtil.writeJsonValue(out, " + x + ");"); + break; + } default: { line("out.value(" + x + ");"); break; @@ -1873,11 +1880,34 @@ private void binaryWrite() { private void binaryWriteValue(Type type, String x) { if (type instanceof PrimitiveType) { - line("out.value(" + x + ");"); + if (((PrimitiveType) type).getKind() == Kind.JSON) { + line("de.haumacher.msgbuf.json.JsonUtil.toJsonValue(" + x + ").writeTo(out);"); + } else { + line("out.value(" + x + ");"); + } } else if (type instanceof CustomType) { line(x + ".writeTo(out);"); - } else { - // TODO + } else if (type instanceof MapType) { + MapType mapType = (MapType) type; + Type keyType = mapType.getKeyType(); + Type valueType = mapType.getValueType(); + line("{"); + { + String entry = "entry"; + line("out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, " + x + ".size());"); + line("for (" + mkEntryType(mapType) + " " + entry + " : " + x + ".entrySet()) {"); + { + line("out.beginObject();"); + line("out.name(1);"); + binaryWriteValue(keyType, entry + ".getKey()"); + line("out.name(2);"); + binaryWriteValue(valueType, entry + ".getValue()"); + line("out.endObject();"); + } + line("}"); + line("out.endArray();"); + } + line("}"); } } @@ -2079,8 +2109,11 @@ private String mkBinaryReadValue(Kind kind) { case BYTES: return "in.nextBinary()"; - } - + + case JSON: + return "de.haumacher.msgbuf.json.JsonUtil.fromJsonValue(de.haumacher.msgbuf.json.value.JsonValue.readJsonValue(in))"; + } + throw new RuntimeException("No such type: " + kind); } @@ -2132,8 +2165,11 @@ private DataType mkBinaryType(PrimitiveType.Kind primitive) { case BYTES: return DataType.BINARY; - } - + + case JSON: + return DataType.OBJECT; + } + throw new RuntimeException("No such type: " + primitive); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/TypeGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/TypeGenerator.java index f80387b9..3c8ddb20 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/TypeGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/TypeGenerator.java @@ -108,6 +108,8 @@ public String visit(PrimitiveType type, Boolean wrapped) { return wrapped ? "Long" : "long"; case STRING: return "String"; + case JSON: + return "Object"; } throw new RuntimeException("No such type: " + type.getKind()); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Constant.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Constant.java index bf50dabe..af26ed25 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Constant.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Constant.java @@ -5,7 +5,7 @@ * * @see EnumDef#getConstants() */ -public class Constant extends Part { +public class Constant extends de.haumacher.msgbuf.generator.ast.Part { /** * Creates a {@link de.haumacher.msgbuf.generator.ast.Constant} instance. diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/CustomType.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/CustomType.java index 0fcd8568..1017f7cd 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/CustomType.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/CustomType.java @@ -5,7 +5,7 @@ * * A custom type is either a {@link EnumDef}, or a {@link MessageDef}. */ -public class CustomType extends Type { +public class CustomType extends de.haumacher.msgbuf.generator.ast.Type { /** * Creates a {@link de.haumacher.msgbuf.generator.ast.CustomType} instance. diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Definition.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Definition.java index 61162cb6..f2804f4f 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Definition.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Definition.java @@ -3,7 +3,7 @@ /** * Base class of a definition in a {@link DefinitionFile}. */ -public abstract class Definition extends DefinitionBase { +public abstract class Definition extends de.haumacher.msgbuf.generator.ast.DefinitionBase { /** Visitor interface for the {@link de.haumacher.msgbuf.generator.ast.Definition} hierarchy.*/ public interface Visitor { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionBase.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionBase.java index 01e1746e..a94b9b6f 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionBase.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionBase.java @@ -3,7 +3,7 @@ /** * Base class for type and field definitions. */ -public abstract class DefinitionBase extends WithOptions { +public abstract class DefinitionBase extends de.haumacher.msgbuf.generator.ast.WithOptions { /** Visitor interface for the {@link de.haumacher.msgbuf.generator.ast.DefinitionBase} hierarchy.*/ public interface Visitor extends de.haumacher.msgbuf.generator.ast.Part.Visitor, de.haumacher.msgbuf.generator.ast.Definition.Visitor { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java index 1ee2fc21..1b6894dd 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java @@ -5,7 +5,7 @@ * * @see #getDefinitions() */ -public class DefinitionFile extends WithOptions { +public class DefinitionFile extends de.haumacher.msgbuf.generator.ast.WithOptions { /** * Creates a {@link de.haumacher.msgbuf.generator.ast.DefinitionFile} instance. diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/EnumDef.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/EnumDef.java index a15df7cb..23eca799 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/EnumDef.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/EnumDef.java @@ -3,7 +3,7 @@ /** * {@link Definition} of an enumeration. */ -public class EnumDef extends Definition { +public class EnumDef extends de.haumacher.msgbuf.generator.ast.Definition { /** * Creates a {@link de.haumacher.msgbuf.generator.ast.EnumDef} instance. diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java index 46f4eb10..c8e42003 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Field.java @@ -3,7 +3,7 @@ /** * A field definition of a {@link MessageDef}. */ -public class Field extends Part implements de.haumacher.msgbuf.generator.FieldOperations { +public class Field extends de.haumacher.msgbuf.generator.ast.Part implements de.haumacher.msgbuf.generator.FieldOperations { /** * Creates a {@link de.haumacher.msgbuf.generator.ast.Field} instance. diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Flag.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Flag.java index 7d84764c..a53910a8 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Flag.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Flag.java @@ -3,7 +3,7 @@ /** * {@link Option} annotating a boolean value */ -public class Flag extends Option { +public class Flag extends de.haumacher.msgbuf.generator.ast.Option { /** * Creates a {@link de.haumacher.msgbuf.generator.ast.Flag} instance. diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MapType.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MapType.java index d6962698..d50c1c43 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MapType.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MapType.java @@ -3,7 +3,7 @@ /** * A {@link Type} that is composed of a key and a value. */ -public class MapType extends Type { +public class MapType extends de.haumacher.msgbuf.generator.ast.Type { /** * Creates a {@link de.haumacher.msgbuf.generator.ast.MapType} instance. diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java index 4d67cc51..7126942f 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/MessageDef.java @@ -3,7 +3,7 @@ /** * {@link Definition} of a data class. */ -public class MessageDef extends Definition implements de.haumacher.msgbuf.generator.MessageDefOperations { +public class MessageDef extends de.haumacher.msgbuf.generator.ast.Definition implements de.haumacher.msgbuf.generator.MessageDefOperations { /** * Creates a {@link de.haumacher.msgbuf.generator.ast.MessageDef} instance. diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/NumberOption.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/NumberOption.java index 65ce62e7..3e47cdde 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/NumberOption.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/NumberOption.java @@ -3,7 +3,7 @@ /** * {@link Option} annotating an int value */ -public class NumberOption extends Option { +public class NumberOption extends de.haumacher.msgbuf.generator.ast.Option { /** * Creates a {@link de.haumacher.msgbuf.generator.ast.NumberOption} instance. diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/OptionContainer.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/OptionContainer.java index 8e40a308..574b97cf 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/OptionContainer.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/OptionContainer.java @@ -3,7 +3,7 @@ /** * Container for temporary collecting annotations without further semantics. */ -public class OptionContainer extends WithOptions { +public class OptionContainer extends de.haumacher.msgbuf.generator.ast.WithOptions { /** * Creates a {@link de.haumacher.msgbuf.generator.ast.OptionContainer} instance. diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Part.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Part.java index 0d2a57e7..a49a2424 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Part.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/Part.java @@ -3,7 +3,7 @@ /** * Member of a {@link Definition}. */ -public abstract class Part extends DefinitionBase { +public abstract class Part extends de.haumacher.msgbuf.generator.ast.DefinitionBase { /** Visitor interface for the {@link de.haumacher.msgbuf.generator.ast.Part} hierarchy.*/ public interface Visitor { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/PrimitiveType.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/PrimitiveType.java index eab1a0d3..503668e7 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/PrimitiveType.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/PrimitiveType.java @@ -3,7 +3,7 @@ /** * A primitive built-in {@link Type}. */ -public class PrimitiveType extends Type { +public class PrimitiveType extends de.haumacher.msgbuf.generator.ast.Type { /** * Supported built-in types. @@ -85,6 +85,11 @@ public enum Kind implements de.haumacher.msgbuf.data.ProtocolEnum { */ BYTES("BYTES"), + /** + * An opaque JSON value (any valid JSON: object, array, string, number, boolean, null). + */ + JSON("JSON"), + ; private final String _protocolName; @@ -122,6 +127,7 @@ public static Kind valueOfProtocol(String protocolName) { case "FLOAT": return FLOAT; case "DOUBLE": return DOUBLE; case "BYTES": return BYTES; + case "JSON": return JSON; } return INT_32; } @@ -154,6 +160,7 @@ public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java case FLOAT: out.value(13); break; case DOUBLE: out.value(14); break; case BYTES: out.value(15); break; + case JSON: out.value(16); break; default: out.value(0); } } @@ -176,6 +183,7 @@ public static Kind readKind(de.haumacher.msgbuf.binary.DataReader in) throws jav case 13: return FLOAT; case 14: return DOUBLE; case 15: return BYTES; + case 16: return JSON; default: return INT_32; } } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/StringOption.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/StringOption.java index 793f9f18..0409d949 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/StringOption.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/StringOption.java @@ -3,7 +3,7 @@ /** * {@link Option} annotating a string value */ -public class StringOption extends Option { +public class StringOption extends de.haumacher.msgbuf.generator.ast.Option { /** * Creates a {@link de.haumacher.msgbuf.generator.ast.StringOption} instance. diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/WithOptions.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/WithOptions.java index b8008249..e1b9bd01 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/WithOptions.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/WithOptions.java @@ -184,11 +184,11 @@ public static de.haumacher.msgbuf.generator.ast.WithOptions readWithOptions(de.h String type = in.nextString(); switch (type) { case OptionContainer.OPTION_CONTAINER__TYPE: result = de.haumacher.msgbuf.generator.ast.OptionContainer.readOptionContainer(in); break; - case DefinitionFile.DEFINITION_FILE__TYPE: result = de.haumacher.msgbuf.generator.ast.DefinitionFile.readDefinitionFile(in); break; case Constant.CONSTANT__TYPE: result = de.haumacher.msgbuf.generator.ast.Constant.readConstant(in); break; case Field.FIELD__TYPE: result = de.haumacher.msgbuf.generator.ast.Field.readField(in); break; case EnumDef.ENUM_DEF__TYPE: result = de.haumacher.msgbuf.generator.ast.EnumDef.readEnumDef(in); break; case MessageDef.MESSAGE_DEF__TYPE: result = de.haumacher.msgbuf.generator.ast.MessageDef.readMessageDef(in); break; + case DefinitionFile.DEFINITION_FILE__TYPE: result = de.haumacher.msgbuf.generator.ast.DefinitionFile.readDefinitionFile(in); break; default: in.skipValue(); result = null; break; } in.endArray(); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto index d94dfdb1..c4c5d3d8 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto @@ -216,6 +216,9 @@ message PrimitiveType extends Type { /** A string of octets. */ BYTES; + + /** An opaque JSON value (any valid JSON: object, array, string, number, boolean, null). */ + JSON; } /** The type kind. */ diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/Util.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/Util.java index 3ae43630..f2ace617 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/Util.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/Util.java @@ -17,6 +17,7 @@ import de.haumacher.msgbuf.generator.ast.MessageDef; import de.haumacher.msgbuf.generator.ast.Option; import de.haumacher.msgbuf.generator.ast.Part; +import de.haumacher.msgbuf.generator.ast.PrimitiveType; import de.haumacher.msgbuf.generator.ast.QName; import de.haumacher.msgbuf.generator.ast.Type; import de.haumacher.msgbuf.generator.ast.WithOptions; @@ -76,6 +77,9 @@ public static boolean isNullable(Field field) { } public static boolean isNullable(Type type) { + if (type instanceof PrimitiveType) { + return ((PrimitiveType) type).getKind() == PrimitiveType.Kind.JSON; + } return type instanceof CustomType && !isEnumType(type); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParser.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParser.java index d7b52b58..34bd1245 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParser.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParser.java @@ -16,9 +16,9 @@ public class ProtobufParser implements ProtobufParserConstants { switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case SYNTAX:{ jj_consume_token(SYNTAX); - jj_consume_token(36); - jj_consume_token(STRING); jj_consume_token(37); + jj_consume_token(STRING); + jj_consume_token(38); break; } default: @@ -29,7 +29,7 @@ public class ProtobufParser implements ProtobufParserConstants { case PACKAGE:{ jj_consume_token(PACKAGE); pkgName = qName(); - jj_consume_token(37); + jj_consume_token(38); result.setPackage(pkgName); break; } @@ -52,7 +52,7 @@ public class ProtobufParser implements ProtobufParserConstants { Token importPath; importPath = jj_consume_token(STRING); result.addImport(de.haumacher.msgbuf.generator.common.Util.stringContent(importPath.image)); - jj_consume_token(37); + jj_consume_token(38); } label_2: while (true) { @@ -73,7 +73,7 @@ public class ProtobufParser implements ProtobufParserConstants { case MESSAGE: case ENUM: case ABSTRACT: - case 40:{ + case 41:{ ; break; } @@ -91,15 +91,15 @@ public class ProtobufParser implements ProtobufParserConstants { final public void optionStatement(WithOptions part) throws ParseException { jj_consume_token(OPTION); optionAssignment(part); - jj_consume_token(37); + jj_consume_token(38); } final public void optionAssignment(WithOptions part) throws ParseException {Option option; Token t; t = jj_consume_token(NAME); switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { - case 36:{ - jj_consume_token(36); + case 37:{ + jj_consume_token(37); option = value(); part.getOptions().put(t.image, option); break; @@ -191,6 +191,7 @@ final public void optionStatement(WithOptions part) throws ParseException { case INT_TYPE: case LONG_TYPE: case BOOLEAN_TYPE: + case JSON_TYPE: case TYPE: case XNAME: case NAME:{ @@ -214,7 +215,7 @@ final public void optionStatement(WithOptions part) throws ParseException { Token d; d = jj_consume_token(ENUM); name = name(); - jj_consume_token(38); + jj_consume_token(39); result.setName(name); result.setComment(Util.stripComment(d)); label_4: @@ -236,9 +237,10 @@ final public void optionStatement(WithOptions part) throws ParseException { case RESERVED: case TO: case MAX: + case JSON_TYPE: case XNAME: case NAME: - case 40:{ + case 41:{ ; break; } @@ -249,9 +251,10 @@ final public void optionStatement(WithOptions part) throws ParseException { switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case TO: case MAX: + case JSON_TYPE: case XNAME: case NAME: - case 40:{ + case 41:{ constant = constant(); result.addConstant(constant); break; @@ -266,7 +269,7 @@ final public void optionStatement(WithOptions part) throws ParseException { throw new ParseException(); } } - jj_consume_token(39); + jj_consume_token(40); {if ("" != null) return result;} throw new Error("Missing return statement in function"); } @@ -279,8 +282,8 @@ final public void optionStatement(WithOptions part) throws ParseException { name = name(); result.setName(name); switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { - case 36:{ - jj_consume_token(36); + case 37:{ + jj_consume_token(37); index = jj_consume_token(NUMBER); result.setIndex(Integer.parseInt(index.image)); break; @@ -290,7 +293,7 @@ final public void optionStatement(WithOptions part) throws ParseException { ; } partOptions(result); - jj_consume_token(37); + jj_consume_token(38); {if ("" != null) return result;} throw new Error("Missing return statement in function"); } @@ -325,7 +328,7 @@ final public void optionStatement(WithOptions part) throws ParseException { jj_la1[14] = jj_gen; ; } - jj_consume_token(38); + jj_consume_token(39); label_6: while (true) { switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { @@ -343,10 +346,11 @@ final public void optionStatement(WithOptions part) throws ParseException { case INT_TYPE: case LONG_TYPE: case BOOLEAN_TYPE: + case JSON_TYPE: case TYPE: case XNAME: case NAME: - case 40:{ + case 41:{ ; break; } @@ -370,10 +374,11 @@ final public void optionStatement(WithOptions part) throws ParseException { case INT_TYPE: case LONG_TYPE: case BOOLEAN_TYPE: + case JSON_TYPE: case TYPE: case XNAME: case NAME: - case 40:{ + case 41:{ def = memberDefinition(); if (def instanceof Field) { result.addField((Field) def); @@ -396,7 +401,7 @@ final public void optionStatement(WithOptions part) throws ParseException { throw new ParseException(); } } - jj_consume_token(39); + jj_consume_token(40); {if ("" != null) return result;} throw new Error("Missing return statement in function"); } @@ -433,8 +438,8 @@ final public void optionStatement(WithOptions part) throws ParseException { name = name(); result.setName(name); switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { - case 36:{ - jj_consume_token(36); + case 37:{ + jj_consume_token(37); switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case NUMBER:{ def = jj_consume_token(NUMBER); @@ -469,7 +474,7 @@ final public void optionStatement(WithOptions part) throws ParseException { ; } partOptions(result); - jj_consume_token(37); + jj_consume_token(38); {if ("" != null) return result;} throw new Error("Missing return statement in function"); } @@ -485,7 +490,7 @@ final public void optionStatement(WithOptions part) throws ParseException { label_7: while (true) { switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { - case 40:{ + case 41:{ ; break; } @@ -494,13 +499,13 @@ final public void optionStatement(WithOptions part) throws ParseException { break label_7; } if (result == null) result = OptionContainer.create(); - jj_consume_token(40); + jj_consume_token(41); optionName = jj_consume_token(NAME); switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { - case 41:{ - jj_consume_token(41); - option = value(); + case 42:{ jj_consume_token(42); + option = value(); + jj_consume_token(43); result.getOptions().put(optionName.image, option); break; } @@ -515,13 +520,13 @@ final public void optionStatement(WithOptions part) throws ParseException { final public void partOptions(Part part) throws ParseException { switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { - case 43:{ - jj_consume_token(43); + case 44:{ + jj_consume_token(44); optionAssignment(part); label_8: while (true) { switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { - case 44:{ + case 45:{ ; break; } @@ -529,10 +534,10 @@ final public void partOptions(Part part) throws ParseException { jj_la1[23] = jj_gen; break label_8; } - jj_consume_token(44); + jj_consume_token(45); optionAssignment(part); } - jj_consume_token(45); + jj_consume_token(46); break; } default: @@ -547,7 +552,7 @@ final public void reserved() throws ParseException { label_9: while (true) { switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { - case 44:{ + case 45:{ ; break; } @@ -555,10 +560,10 @@ final public void reserved() throws ParseException { jj_la1[25] = jj_gen; break label_9; } - jj_consume_token(44); + jj_consume_token(45); reservation(); } - jj_consume_token(37); + jj_consume_token(38); } final public void reservation() throws ParseException { @@ -604,14 +609,14 @@ final public void reservation() throws ParseException { final public void oneof() throws ParseException { jj_consume_token(ONEOF); jj_consume_token(NAME); - jj_consume_token(38); + jj_consume_token(39); label_10: while (true) { type(); jj_consume_token(NAME); switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { - case 36:{ - jj_consume_token(36); + case 37:{ + jj_consume_token(37); jj_consume_token(NUMBER); break; } @@ -619,7 +624,7 @@ final public void oneof() throws ParseException { jj_la1[29] = jj_gen; ; } - jj_consume_token(37); + jj_consume_token(38); switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case MAP: case TO: @@ -627,6 +632,7 @@ final public void oneof() throws ParseException { case INT_TYPE: case LONG_TYPE: case BOOLEAN_TYPE: + case JSON_TYPE: case TYPE: case XNAME: case NAME:{ @@ -638,7 +644,7 @@ final public void oneof() throws ParseException { break label_10; } } - jj_consume_token(39); + jj_consume_token(40); } final public Type type() throws ParseException {Type result; @@ -646,6 +652,7 @@ final public void oneof() throws ParseException { case INT_TYPE: case LONG_TYPE: case BOOLEAN_TYPE: + case JSON_TYPE: case TYPE:{ result = primitiveType(); break; @@ -693,6 +700,11 @@ final public void oneof() throws ParseException { result = PrimitiveType.create().setKind(PrimitiveType.Kind.BOOL); break; } + case JSON_TYPE:{ + t = jj_consume_token(JSON_TYPE); +result = PrimitiveType.create().setKind(PrimitiveType.Kind.JSON); + break; + } default: jj_la1[32] = jj_gen; jj_consume_token(-1); @@ -711,11 +723,11 @@ final public void oneof() throws ParseException { final public MapType map() throws ParseException {Type keyType; Type valueType; jj_consume_token(MAP); - jj_consume_token(46); + jj_consume_token(47); keyType = type(); - jj_consume_token(44); + jj_consume_token(45); valueType = type(); - jj_consume_token(47); + jj_consume_token(48); {if ("" != null) return MapType.create().setKeyType(keyType).setValueType(valueType);} throw new Error("Missing return statement in function"); } @@ -727,7 +739,7 @@ final public void oneof() throws ParseException { label_11: while (true) { switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { - case 48:{ + case 49:{ ; break; } @@ -735,7 +747,7 @@ final public void oneof() throws ParseException { jj_la1[33] = jj_gen; break label_11; } - jj_consume_token(48); + jj_consume_token(49); name = name(); result.addName(name); } @@ -758,6 +770,11 @@ final public void oneof() throws ParseException { } case MAX:{ t = jj_consume_token(MAX); +result = t.image; + break; + } + case JSON_TYPE:{ + t = jj_consume_token(JSON_TYPE); result = t.image; break; } @@ -792,10 +809,10 @@ final public void oneof() throws ParseException { jj_la1_init_1(); } private static void jj_la1_init_0() { - jj_la1_0 = new int[] {0x400,0x100,0x200,0x20000,0x81800,0x0,0x81800000,0x81800,0x3c69b800,0x20000,0x700000,0x700000,0x0,0x80000,0x40000,0x3c7bf800,0x3c7bf800,0x10000,0x8000,0x83800000,0x0,0x0,0x0,0x0,0x0,0x0,0x80400000,0x200000,0x80000000,0x0,0x3c602000,0x3c602000,0x3c000000,0x0,0x600000,}; + jj_la1_0 = new int[] {0x400,0x100,0x200,0x20000,0x81800,0x0,0x1800000,0x81800,0x7c69b800,0x20000,0x20700000,0x20700000,0x0,0x80000,0x40000,0x7c7bf800,0x7c7bf800,0x10000,0x8000,0x3800000,0x0,0x0,0x0,0x0,0x0,0x0,0x400000,0x200000,0x0,0x0,0x7c602000,0x7c602000,0x7c000000,0x0,0x20600000,}; } private static void jj_la1_init_1() { - jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x100,0x10,0x1,0x0,0xa,0x0,0x10a,0x10a,0x10,0x0,0x0,0x10a,0x10a,0x0,0x0,0x1,0x10,0x100,0x200,0x1000,0x800,0x1000,0x0,0x0,0x1,0x10,0xa,0xa,0x0,0x10000,0xa,}; + jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x200,0x20,0x3,0x0,0x14,0x0,0x214,0x214,0x20,0x0,0x0,0x214,0x214,0x0,0x0,0x3,0x20,0x200,0x400,0x2000,0x1000,0x2000,0x1,0x0,0x3,0x20,0x14,0x14,0x0,0x20000,0x14,}; } /** Constructor with InputStream. */ @@ -920,7 +937,7 @@ private int jj_ntk_f() { /** Generate ParseException. */ public ParseException generateParseException() { jj_expentries.clear(); - boolean[] la1tokens = new boolean[49]; + boolean[] la1tokens = new boolean[50]; if (jj_kind >= 0) { la1tokens[jj_kind] = true; jj_kind = -1; @@ -937,7 +954,7 @@ public ParseException generateParseException() { } } } - for (int i = 0; i < 49; i++) { + for (int i = 0; i < 50; i++) { if (la1tokens[i]) { jj_expentry = new int[1]; jj_expentry[0] = i; diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParserConstants.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParserConstants.java index 62a9b730..7c13a62e 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParserConstants.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParserConstants.java @@ -67,19 +67,21 @@ public interface ProtobufParserConstants { /** RegularExpression Id. */ int BOOLEAN_TYPE = 28; /** RegularExpression Id. */ - int TYPE = 29; + int JSON_TYPE = 29; /** RegularExpression Id. */ - int INT = 30; + int TYPE = 30; /** RegularExpression Id. */ - int NUMBER = 31; + int INT = 31; /** RegularExpression Id. */ - int STRING = 32; + int NUMBER = 32; /** RegularExpression Id. */ - int XNAME = 33; + int STRING = 33; /** RegularExpression Id. */ - int QUOTE = 34; + int XNAME = 34; /** RegularExpression Id. */ - int NAME = 35; + int QUOTE = 35; + /** RegularExpression Id. */ + int NAME = 36; /** Lexical state. */ int DEFAULT = 0; @@ -115,6 +117,7 @@ public interface ProtobufParserConstants { "\"int\"", "\"long\"", "\"boolean\"", + "\"json\"", "", "", "", diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParserTokenManager.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParserTokenManager.java index 39aec111..0193045f 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParserTokenManager.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParserTokenManager.java @@ -16,64 +16,64 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0){ switch (pos) { case 0: - if ((active0 & 0x4000200L) != 0L) - { - jjmatchedKind = 35; - return 56; - } if ((active0 & 0x10000000L) != 0L) { - jjmatchedKind = 35; + jjmatchedKind = 36; return 98; } - if ((active0 & 0xafff900L) != 0L) + if ((active0 & 0x4000200L) != 0L) { - jjmatchedKind = 35; - return 35; + jjmatchedKind = 36; + return 56; + } + if ((active0 & 0x1000000L) != 0L) + { + jjmatchedKind = 36; + return 40; } if ((active0 & 0x400L) != 0L) { - jjmatchedKind = 35; + jjmatchedKind = 36; return 73; } - if ((active0 & 0x1000000L) != 0L) + if ((active0 & 0x2afff900L) != 0L) { - jjmatchedKind = 35; - return 40; + jjmatchedKind = 36; + return 35; } return -1; case 1: - if ((active0 & 0xbdfff00L) != 0L) - { - jjmatchedKind = 35; - jjmatchedPos = 1; + if ((active0 & 0x200000L) != 0L) return 35; - } if ((active0 & 0x4000000L) != 0L) { - jjmatchedKind = 35; + jjmatchedKind = 36; jjmatchedPos = 1; return 55; } - if ((active0 & 0x200000L) != 0L) - return 35; if ((active0 & 0x10000000L) != 0L) { - jjmatchedKind = 35; + jjmatchedKind = 36; jjmatchedPos = 1; return 97; } + if ((active0 & 0x2bdfff00L) != 0L) + { + jjmatchedKind = 36; + jjmatchedPos = 1; + return 35; + } return -1; case 2: - if ((active0 & 0xb9fdf00L) != 0L) + if ((active0 & 0x2b9fdf00L) != 0L) { - jjmatchedKind = 35; + jjmatchedKind = 36; jjmatchedPos = 2; return 35; } if ((active0 & 0x10000000L) != 0L) { - jjmatchedKind = 35; + jjmatchedKind = 36; jjmatchedPos = 2; return 96; } @@ -83,17 +83,17 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0){ return 54; return -1; case 3: - if ((active0 & 0xa801000L) != 0L) + if ((active0 & 0x2a801000L) != 0L) return 35; if ((active0 & 0x11fcf00L) != 0L) { - jjmatchedKind = 35; + jjmatchedKind = 36; jjmatchedPos = 3; return 35; } if ((active0 & 0x10000000L) != 0L) { - jjmatchedKind = 29; + jjmatchedKind = 30; jjmatchedPos = 3; return 35; } @@ -103,7 +103,7 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0){ return 35; if ((active0 & 0x101f8f00L) != 0L) { - jjmatchedKind = 35; + jjmatchedKind = 36; jjmatchedPos = 4; return 35; } @@ -111,7 +111,7 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0){ case 5: if ((active0 & 0x101d8900L) != 0L) { - jjmatchedKind = 35; + jjmatchedKind = 36; jjmatchedPos = 5; return 35; } @@ -121,7 +121,7 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0){ case 6: if ((active0 & 0x198000L) != 0L) { - jjmatchedKind = 35; + jjmatchedKind = 36; jjmatchedPos = 6; return 35; } @@ -133,7 +133,7 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0){ return 35; if ((active0 & 0x10000L) != 0L) { - jjmatchedKind = 35; + jjmatchedKind = 36; jjmatchedPos = 7; return 35; } @@ -155,27 +155,27 @@ private int jjMoveStringLiteralDfa0_0(){ switch(curChar) { case 40: - return jjStopAtPos(0, 41); - case 41: return jjStopAtPos(0, 42); + case 41: + return jjStopAtPos(0, 43); case 44: - return jjStopAtPos(0, 44); + return jjStopAtPos(0, 45); case 46: - return jjStopAtPos(0, 48); + return jjStopAtPos(0, 49); case 59: - return jjStopAtPos(0, 37); + return jjStopAtPos(0, 38); case 60: - return jjStopAtPos(0, 46); + return jjStopAtPos(0, 47); case 61: - return jjStopAtPos(0, 36); + return jjStopAtPos(0, 37); case 62: - return jjStopAtPos(0, 47); + return jjStopAtPos(0, 48); case 64: - return jjStopAtPos(0, 40); + return jjStopAtPos(0, 41); case 91: - return jjStopAtPos(0, 43); + return jjStopAtPos(0, 44); case 93: - return jjStopAtPos(0, 45); + return jjStopAtPos(0, 46); case 97: return jjMoveStringLiteralDfa1_0(0x80000L); case 98: @@ -186,6 +186,8 @@ private int jjMoveStringLiteralDfa0_0(){ return jjMoveStringLiteralDfa1_0(0x1000000L); case 105: return jjMoveStringLiteralDfa1_0(0x4000200L); + case 106: + return jjMoveStringLiteralDfa1_0(0x20000000L); case 108: return jjMoveStringLiteralDfa1_0(0x8000000L); case 109: @@ -203,9 +205,9 @@ private int jjMoveStringLiteralDfa0_0(){ case 116: return jjMoveStringLiteralDfa1_0(0xa10000L); case 123: - return jjStopAtPos(0, 38); - case 125: return jjStopAtPos(0, 39); + case 125: + return jjStopAtPos(0, 40); default : return jjMoveNfa_0(5, 0); } @@ -236,6 +238,8 @@ private int jjMoveStringLiteralDfa1_0(long active0){ return jjMoveStringLiteralDfa2_0(active0, 0x20000L); case 114: return jjMoveStringLiteralDfa2_0(active0, 0x810000L); + case 115: + return jjMoveStringLiteralDfa2_0(active0, 0x20000000L); case 117: return jjMoveStringLiteralDfa2_0(active0, 0x2000000L); case 120: @@ -268,7 +272,7 @@ private int jjMoveStringLiteralDfa2_0(long old0, long active0){ case 110: return jjMoveStringLiteralDfa3_0(active0, 0x8000400L); case 111: - return jjMoveStringLiteralDfa3_0(active0, 0x10000000L); + return jjMoveStringLiteralDfa3_0(active0, 0x30000000L); case 112: if ((active0 & 0x2000L) != 0L) return jjStartNfaWithStates_0(2, 13, 35); @@ -321,6 +325,8 @@ private int jjMoveStringLiteralDfa3_0(long old0, long active0){ return jjStartNfaWithStates_0(3, 12, 35); break; case 110: + if ((active0 & 0x20000000L) != 0L) + return jjStartNfaWithStates_0(3, 29, 35); return jjMoveStringLiteralDfa4_0(active0, 0x10000L); case 111: return jjMoveStringLiteralDfa4_0(active0, 0x4200L); @@ -516,22 +522,22 @@ private int jjMoveNfa_0(int startState, int curPos) case 35: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } break; case 96: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } break; case 5: if ((0x3fe000000000000L & l) != 0L) { - if (kind > 31) - kind = 31; + if (kind > 32) + kind = 32; { jjCheckNAddStates(0, 2); } } else if (curChar == 47) @@ -542,8 +548,8 @@ else if (curChar == 39) { jjCheckNAddStates(11, 13); } else if (curChar == 48) { - if (kind > 31) - kind = 31; + if (kind > 32) + kind = 32; { jjCheckNAddTwoStates(8, 10); } } else if (curChar == 45) @@ -552,8 +558,8 @@ else if (curChar == 45) case 54: if ((0x3ff000000000000L & l) != 0L) { - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } } if (curChar == 54) @@ -564,36 +570,36 @@ else if (curChar == 51) case 40: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } break; case 97: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } break; case 73: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } break; case 98: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } break; case 56: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } break; case 6: @@ -603,8 +609,8 @@ else if (curChar == 51) case 7: if (curChar != 48) break; - if (kind > 31) - kind = 31; + if (kind > 32) + kind = 32; { jjCheckNAddTwoStates(8, 10); } break; case 8: @@ -614,8 +620,8 @@ else if (curChar == 51) case 9: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 31) - kind = 31; + if (kind > 32) + kind = 32; { jjCheckNAddTwoStates(9, 10); } break; case 11: @@ -623,35 +629,35 @@ else if (curChar == 51) { jjAddStates(16, 17); } break; case 12: - if (curChar == 48 && kind > 31) - kind = 31; + if (curChar == 48 && kind > 32) + kind = 32; break; case 13: if ((0x3fe000000000000L & l) == 0L) break; - if (kind > 31) - kind = 31; + if (kind > 32) + kind = 32; { jjCheckNAdd(14); } break; case 14: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 31) - kind = 31; + if (kind > 32) + kind = 32; { jjCheckNAdd(14); } break; case 15: if ((0x3fe000000000000L & l) == 0L) break; - if (kind > 31) - kind = 31; + if (kind > 32) + kind = 32; { jjCheckNAddStates(0, 2); } break; case 16: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 31) - kind = 31; + if (kind > 32) + kind = 32; { jjCheckNAddStates(0, 2); } break; case 17: @@ -664,8 +670,8 @@ else if (curChar == 51) { jjCheckNAddStates(11, 13); } break; case 19: - if (curChar == 39 && kind > 32) - kind = 32; + if (curChar == 39 && kind > 33) + kind = 33; break; case 21: if (curChar == 34) @@ -681,8 +687,8 @@ else if (curChar == 51) { jjCheckNAddStates(8, 10); } break; case 26: - if (curChar == 34 && kind > 32) - kind = 32; + if (curChar == 34 && kind > 33) + kind = 33; break; case 29: if (curChar == 39) @@ -692,8 +698,8 @@ else if (curChar == 51) { jjAddStates(18, 19); } break; case 41: - if (curChar == 50 && kind > 29) - kind = 29; + if (curChar == 50 && kind > 30) + kind = 30; break; case 42: case 61: @@ -703,8 +709,8 @@ else if (curChar == 51) { jjCheckNAdd(41); } break; case 47: - if (curChar == 52 && kind > 29) - kind = 29; + if (curChar == 52 && kind > 30) + kind = 30; break; case 48: case 65: @@ -809,8 +815,8 @@ else if (curChar < 128) case 55: if ((0x7fffffe87fffffeL & l) != 0L) { - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } } if (curChar == 116) @@ -821,21 +827,21 @@ else if (curChar < 128) case 96: if ((0x7fffffe87fffffeL & l) != 0L) { - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } } if (curChar == 108) { - if (kind > 29) - kind = 29; + if (kind > 30) + kind = 30; } break; case 5: if ((0x7fffffe87fffffeL & l) != 0L) { - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } } else if (curChar == 96) @@ -857,15 +863,15 @@ else if (curChar == 100) case 35: if ((0x7fffffe87fffffeL & l) == 0L) break; - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } break; case 40: if ((0x7fffffe87fffffeL & l) != 0L) { - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } } if (curChar == 105) @@ -878,8 +884,8 @@ else if (curChar == 108) case 97: if ((0x7fffffe87fffffeL & l) != 0L) { - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } } if (curChar == 111) @@ -888,8 +894,8 @@ else if (curChar == 108) case 73: if ((0x7fffffe87fffffeL & l) != 0L) { - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } } if (curChar == 116) @@ -906,8 +912,8 @@ else if (curChar == 105) case 98: if ((0x7fffffe87fffffeL & l) != 0L) { - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } } if (curChar == 121) @@ -918,8 +924,8 @@ else if (curChar == 111) case 56: if ((0x7fffffe87fffffeL & l) != 0L) { - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } } if (curChar == 110) @@ -928,8 +934,8 @@ else if (curChar == 111) jjstateSet[jjnewStateCnt++] = 55; break; case 0: - if (curChar == 101 && kind > 29) - kind = 29; + if (curChar == 101 && kind > 30) + kind = 30; break; case 1: if (curChar == 108) @@ -984,14 +990,14 @@ else if (curChar == 111) { jjCheckNAddTwoStates(32, 33); } break; case 33: - if (curChar == 96 && kind > 33) - kind = 33; + if (curChar == 96 && kind > 34) + kind = 34; break; case 34: if ((0x7fffffe87fffffeL & l) == 0L) break; - if (kind > 35) - kind = 35; + if (kind > 36) + kind = 36; { jjCheckNAdd(35); } break; case 36: @@ -999,8 +1005,8 @@ else if (curChar == 111) { jjAddStates(37, 39); } break; case 37: - if (curChar == 116 && kind > 29) - kind = 29; + if (curChar == 116 && kind > 30) + kind = 30; break; case 38: if (curChar == 97) @@ -1147,8 +1153,8 @@ else if (curChar == 111) jjstateSet[jjnewStateCnt++] = 88; break; case 90: - if (curChar == 103 && kind > 29) - kind = 29; + if (curChar == 103 && kind > 30) + kind = 30; break; case 91: if (curChar == 110) @@ -1171,8 +1177,8 @@ else if (curChar == 111) { jjAddStates(26, 27); } break; case 99: - if (curChar == 115 && kind > 29) - kind = 29; + if (curChar == 115 && kind > 30) + kind = 30; break; case 100: if (curChar == 101) @@ -1264,9 +1270,9 @@ else if (curChar == 111) "\164\162\141\156\163\151\145\156\164", "\157\160\164\151\157\156", "\145\170\164\145\156\144\163", "\141\142\163\164\162\141\143\164", "\162\145\163\145\162\166\145\144", "\164\157", "\155\141\170", "\164\162\165\145", "\146\141\154\163\145", "\156\165\154\154", "\151\156\164", -"\154\157\156\147", "\142\157\157\154\145\141\156", null, null, null, null, null, null, null, -"\75", "\73", "\173", "\175", "\100", "\50", "\51", "\133", "\54", "\135", "\74", -"\76", "\56", }; +"\154\157\156\147", "\142\157\157\154\145\141\156", "\152\163\157\156", null, null, null, null, +null, null, null, "\75", "\73", "\173", "\175", "\100", "\50", "\51", "\133", "\54", +"\135", "\74", "\76", "\56", }; protected Token jjFillToken() { final Token t; @@ -1511,10 +1517,10 @@ public void SwitchTo(int lexState) /** Lex State array. */ public static final int[] jjnewLexState = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, }; static final long[] jjtoToken = { - 0x1fffbbfffff01L, + 0x3fff77fffff01L, }; static final long[] jjtoSkip = { 0xfeL, diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/protobuf.jj b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/protobuf.jj index 6b015666..4600451e 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/protobuf.jj +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/protobuf.jj @@ -65,6 +65,7 @@ TOKEN : | < INT_TYPE : "int" > | < LONG_TYPE : "long" > | < BOOLEAN_TYPE : "boolean" > +| < JSON_TYPE : "json" > | < TYPE : "double" | "float" | @@ -452,6 +453,8 @@ PrimitiveType primitiveType() : { result = PrimitiveType.create().setKind(PrimitiveType.Kind.INT_64); } | t=< BOOLEAN_TYPE > { result = PrimitiveType.create().setKind(PrimitiveType.Kind.BOOL); } + | t=< JSON_TYPE > + { result = PrimitiveType.create().setKind(PrimitiveType.Kind.JSON); } ) { return result; } } @@ -513,6 +516,8 @@ String name() : { result = t.image; } | t = < MAX > { result = t.image; } + | t = < JSON_TYPE > + { result = t.image; } | t = < XNAME > { result = t.image.substring(1, t.image.length() - 1); } ) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java index 27fb53b9..9551bc4e 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java @@ -551,8 +551,11 @@ String fromStringSingle(de.haumacher.msgbuf.generator.ast.Type type, String valu case BYTES: return "java.util.Base64.getDecoder().decode(" + value + ");"; + + case JSON: + return "de.haumacher.msgbuf.json.JsonUtil.parseJsonValue(" + value + ")"; } - + throw new UnsupportedOperationException("Cannot read values of type: " + primitiveType); } @@ -593,8 +596,11 @@ String toStringSingle(de.haumacher.msgbuf.generator.ast.Type type, String value) case BYTES: return "java.util.Base64.getEncoder().encodeToString(" + value + ");"; + + case JSON: + return "de.haumacher.msgbuf.json.JsonUtil.jsonStringValue(" + value + ")"; } - + throw new UnsupportedOperationException("Cannot read values of type: " + primitiveType); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java index 95bb36a3..db070fb2 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContainer_Impl.java @@ -513,6 +513,18 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.endArray(); } out.name(CONTENT_MAP__ID); + { + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, getContentMap().size()); + for (java.util.Map.Entry entry : getContentMap().entrySet()) { + out.beginObject(); + out.name(1); + out.value(entry.getKey()); + out.name(2); + entry.getValue().writeTo(out); + out.endObject(); + } + out.endArray(); + } if (hasOther()) { out.name(OTHER__ID); getOther().writeTo(out); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java index ec8de9a7..eb4040bb 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContainer.java @@ -594,6 +594,18 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav out.endArray(); } out.name(CONTENT_MAP__ID); + { + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, getContentMap().size()); + for (java.util.Map.Entry entry : getContentMap().entrySet()) { + out.beginObject(); + out.name(1); + out.value(entry.getKey()); + out.name(2); + entry.getValue().writeTo(out); + out.endObject(); + } + out.endArray(); + } if (hasOther()) { out.name(OTHER__ID); getOther().writeTo(out); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/TestJsonBinary.java b/de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/TestJsonBinary.java new file mode 100644 index 00000000..f0881819 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/TestJsonBinary.java @@ -0,0 +1,124 @@ +package test.jsonbinary; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import de.haumacher.msgbuf.binary.OctetDataReader; +import de.haumacher.msgbuf.binary.OctetDataWriter; +import de.haumacher.msgbuf.io.StringR; +import de.haumacher.msgbuf.json.JsonReader; +import junit.framework.TestCase; +import test.jsonbinary.data.BinaryPatchEvent; + +/** + * Tests for the {@code json} field type with Binary serialization via JsonValue envelope. + */ +@SuppressWarnings("javadoc") +public class TestJsonBinary extends TestCase { + + public void testBinaryRoundtripObject() throws IOException { + Map patch = new LinkedHashMap<>(); + Map nodes = new LinkedHashMap<>(); + Map n1 = new LinkedHashMap<>(); + n1.put("x", Long.valueOf(100)); + n1.put("y", Long.valueOf(200)); + nodes.put("n1", n1); + patch.put("nodes", nodes); + + BinaryPatchEvent event = BinaryPatchEvent.create() + .setControlId("c1") + .setPatch(patch); + + BinaryPatchEvent copy = binaryRoundtrip(event); + assertEquals("c1", copy.getControlId()); + assertTrue(copy.hasPatch()); + assertTrue(copy.getPatch() instanceof Map); + + @SuppressWarnings("unchecked") + Map patchCopy = (Map) copy.getPatch(); + @SuppressWarnings("unchecked") + Map n1Copy = (Map) ((Map) patchCopy.get("nodes")).get("n1"); + assertEquals(Long.valueOf(100), n1Copy.get("x")); + assertEquals(Long.valueOf(200), n1Copy.get("y")); + } + + public void testBinaryRoundtripArray() throws IOException { + List patch = Arrays.asList("add", "/path", Long.valueOf(42)); + + BinaryPatchEvent event = BinaryPatchEvent.create() + .setControlId("c2") + .setPatch(patch); + + BinaryPatchEvent copy = binaryRoundtrip(event); + assertTrue(copy.getPatch() instanceof List); + + @SuppressWarnings("unchecked") + List patchCopy = (List) copy.getPatch(); + assertEquals("add", patchCopy.get(0)); + assertEquals("/path", patchCopy.get(1)); + assertEquals(Long.valueOf(42), patchCopy.get(2)); + } + + public void testBinaryRoundtripPrimitives() throws IOException { + // String + BinaryPatchEvent strEvent = BinaryPatchEvent.create().setControlId("s").setPatch("hello"); + BinaryPatchEvent strCopy = binaryRoundtrip(strEvent); + assertEquals("hello", strCopy.getPatch()); + + // Number (double) + BinaryPatchEvent dblEvent = BinaryPatchEvent.create().setControlId("d").setPatch(Double.valueOf(3.14)); + BinaryPatchEvent dblCopy = binaryRoundtrip(dblEvent); + assertEquals(3.14, ((Number) dblCopy.getPatch()).doubleValue(), 0.001); + + // Number (long) + BinaryPatchEvent longEvent = BinaryPatchEvent.create().setControlId("l").setPatch(Long.valueOf(42)); + BinaryPatchEvent longCopy = binaryRoundtrip(longEvent); + assertEquals(Long.valueOf(42), longCopy.getPatch()); + + // Boolean + BinaryPatchEvent boolEvent = BinaryPatchEvent.create().setControlId("b").setPatch(Boolean.TRUE); + BinaryPatchEvent boolCopy = binaryRoundtrip(boolEvent); + assertEquals(Boolean.TRUE, boolCopy.getPatch()); + } + + public void testBinaryRoundtripNull() throws IOException { + BinaryPatchEvent event = BinaryPatchEvent.create().setControlId("n"); + // patch is null by default + assertFalse(event.hasPatch()); + + BinaryPatchEvent copy = binaryRoundtrip(event); + assertEquals("n", copy.getControlId()); + assertFalse(copy.hasPatch()); + assertNull(copy.getPatch()); + } + + public void testJsonRoundtripStillWorks() throws IOException { + Map patch = new LinkedHashMap<>(); + patch.put("key", "value"); + + BinaryPatchEvent event = BinaryPatchEvent.create() + .setControlId("json-test") + .setPatch(patch); + + String json = event.toString(); + // Should be native JSON, not string-wrapped + assertTrue(json.contains("\"patch\":{")); + + BinaryPatchEvent copy = BinaryPatchEvent.readBinaryPatchEvent(new JsonReader(new StringR(json))); + assertEquals("json-test", copy.getControlId()); + @SuppressWarnings("unchecked") + Map patchCopy = (Map) copy.getPatch(); + assertEquals("value", patchCopy.get("key")); + } + + private BinaryPatchEvent binaryRoundtrip(BinaryPatchEvent event) throws IOException { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + event.writeTo(new OctetDataWriter(buffer)); + return BinaryPatchEvent.readBinaryPatchEvent(new OctetDataReader(new ByteArrayInputStream(buffer.toByteArray()))); + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/data/BinaryPatchEvent.java b/de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/data/BinaryPatchEvent.java new file mode 100644 index 00000000..9a927927 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/data/BinaryPatchEvent.java @@ -0,0 +1,67 @@ +package test.jsonbinary.data; + +/** + * A message with json fields, supporting both JSON and Binary serialization. + */ +public interface BinaryPatchEvent extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject { + + /** + * Creates a {@link test.jsonbinary.data.BinaryPatchEvent} instance. + */ + static test.jsonbinary.data.BinaryPatchEvent create() { + return new test.jsonbinary.data.impl.BinaryPatchEvent_Impl(); + } + + /** Identifier for the {@link test.jsonbinary.data.BinaryPatchEvent} type in JSON format. */ + String BINARY_PATCH_EVENT__TYPE = "BinaryPatchEvent"; + + /** @see #getControlId() */ + String CONTROL_ID__PROP = "controlId"; + + /** @see #getPatch() */ + String PATCH__PROP = "patch"; + + /** Identifier for the property {@link #getControlId()} in binary format. */ + static final int CONTROL_ID__ID = 1; + + /** Identifier for the property {@link #getPatch()} in binary format. */ + static final int PATCH__ID = 2; + + String getControlId(); + + /** + * @see #getControlId() + */ + test.jsonbinary.data.BinaryPatchEvent setControlId(String value); + + /** + * The patch data as a native JSON value. + */ + Object getPatch(); + + /** + * @see #getPatch() + */ + test.jsonbinary.data.BinaryPatchEvent setPatch(Object value); + + /** + * Checks, whether {@link #getPatch()} has a value. + */ + boolean hasPatch(); + + /** Reads a new instance from the given reader. */ + static test.jsonbinary.data.BinaryPatchEvent readBinaryPatchEvent(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.jsonbinary.data.impl.BinaryPatchEvent_Impl result = new test.jsonbinary.data.impl.BinaryPatchEvent_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.jsonbinary.data.BinaryPatchEvent readBinaryPatchEvent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.jsonbinary.data.BinaryPatchEvent result = test.jsonbinary.data.impl.BinaryPatchEvent_Impl.readBinaryPatchEvent_Content(in); + in.endObject(); + return result; + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/data/impl/BinaryPatchEvent_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/data/impl/BinaryPatchEvent_Impl.java new file mode 100644 index 00000000..eb4de2d9 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/data/impl/BinaryPatchEvent_Impl.java @@ -0,0 +1,130 @@ +package test.jsonbinary.data.impl; + +/** + * Implementation of {@link test.jsonbinary.data.BinaryPatchEvent}. + */ +public class BinaryPatchEvent_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.jsonbinary.data.BinaryPatchEvent { + + private String _controlId = ""; + + private Object _patch = null; + + /** + * Creates a {@link BinaryPatchEvent_Impl} instance. + * + * @see test.jsonbinary.data.BinaryPatchEvent#create() + */ + public BinaryPatchEvent_Impl() { + super(); + } + + @Override + public final String getControlId() { + return _controlId; + } + + @Override + public test.jsonbinary.data.BinaryPatchEvent setControlId(String value) { + internalSetControlId(value); + return this; + } + + /** Internal setter for {@link #getControlId()} without chain call utility. */ + protected final void internalSetControlId(String value) { + _controlId = value; + } + + @Override + public final Object getPatch() { + return _patch; + } + + @Override + public test.jsonbinary.data.BinaryPatchEvent setPatch(Object value) { + internalSetPatch(value); + return this; + } + + /** Internal setter for {@link #getPatch()} without chain call utility. */ + protected final void internalSetPatch(Object value) { + _patch = value; + } + + @Override + public final boolean hasPatch() { + return _patch != null; + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(CONTROL_ID__PROP); + out.value(getControlId()); + if (hasPatch()) { + out.name(PATCH__PROP); + de.haumacher.msgbuf.json.JsonUtil.writeJsonValue(out, getPatch()); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case CONTROL_ID__PROP: setControlId(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case PATCH__PROP: setPatch(de.haumacher.msgbuf.json.JsonUtil.nextJsonValue(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(CONTROL_ID__ID); + out.value(getControlId()); + if (hasPatch()) { + out.name(PATCH__ID); + de.haumacher.msgbuf.json.JsonUtil.toJsonValue(getPatch()).writeTo(out); + } + } + + /** Helper for creating an object of type {@link test.jsonbinary.data.BinaryPatchEvent} from a polymorphic composition. */ + public static test.jsonbinary.data.BinaryPatchEvent readBinaryPatchEvent_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.jsonbinary.data.impl.BinaryPatchEvent_Impl result = new BinaryPatchEvent_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case CONTROL_ID__ID: setControlId(in.nextString()); break; + case PATCH__ID: setPatch(de.haumacher.msgbuf.json.JsonUtil.fromJsonValue(de.haumacher.msgbuf.json.value.JsonValue.readJsonValue(in))); break; + default: in.skipValue(); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/data/jsonbinary.proto b/de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/data/jsonbinary.proto new file mode 100644 index 00000000..8d4046e7 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/jsonbinary/data/jsonbinary.proto @@ -0,0 +1,14 @@ +package test.jsonbinary.data; + +option NoXml; +option NoReflection; +option NoListener; +option NoVisitor; + +/** A message with json fields, supporting both JSON and Binary serialization. */ +message BinaryPatchEvent { + string controlId; + + /** The patch data as a native JSON value. */ + json patch; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/TestJsonValue.java b/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/TestJsonValue.java new file mode 100644 index 00000000..0ed47fb9 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/TestJsonValue.java @@ -0,0 +1,156 @@ +package test.jsonvalue; + +import java.io.IOException; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import de.haumacher.msgbuf.io.StringR; +import de.haumacher.msgbuf.json.JsonReader; +import junit.framework.TestCase; +import test.jsonvalue.data.DynamicConfig; +import test.jsonvalue.data.PatchEvent; + +/** + * Tests for the {@code json} field type. + */ +@SuppressWarnings("javadoc") +public class TestJsonValue extends TestCase { + + public void testObjectPatch() throws IOException { + Map patch = new LinkedHashMap<>(); + Map nodes = new LinkedHashMap<>(); + Map n1 = new LinkedHashMap<>(); + n1.put("x", Long.valueOf(100)); + n1.put("y", Long.valueOf(200)); + nodes.put("n1", n1); + patch.put("nodes", nodes); + + PatchEvent event = PatchEvent.create() + .setControlId("c1") + .setPatch(patch); + + String json = event.toString(); + + // Verify no double-serialization: patch should be a native JSON object, not a string + assertFalse("Patch should not be string-wrapped", json.contains("\"patch\":\"")); + assertTrue("Patch should be native JSON object", json.contains("\"patch\":{")); + + // Roundtrip + PatchEvent copy = PatchEvent.readPatchEvent(new JsonReader(new StringR(json))); + assertEquals("c1", copy.getControlId()); + assertTrue(copy.hasPatch()); + assertTrue(copy.getPatch() instanceof Map); + + @SuppressWarnings("unchecked") + Map patchCopy = (Map) copy.getPatch(); + assertNotNull(patchCopy.get("nodes")); + + @SuppressWarnings("unchecked") + Map n1Copy = (Map) ((Map) patchCopy.get("nodes")).get("n1"); + assertEquals(Long.valueOf(100), n1Copy.get("x")); + assertEquals(Long.valueOf(200), n1Copy.get("y")); + } + + public void testArrayPatch() throws IOException { + List patch = Arrays.asList("add", "/nodes/n2", Long.valueOf(42)); + + PatchEvent event = PatchEvent.create() + .setControlId("c2") + .setPatch(patch); + + String json = event.toString(); + assertTrue("Patch should be native JSON array", json.contains("\"patch\":[")); + + PatchEvent copy = PatchEvent.readPatchEvent(new JsonReader(new StringR(json))); + assertTrue(copy.getPatch() instanceof List); + + @SuppressWarnings("unchecked") + List patchCopy = (List) copy.getPatch(); + assertEquals("add", patchCopy.get(0)); + assertEquals("/nodes/n2", patchCopy.get(1)); + assertEquals(Long.valueOf(42), patchCopy.get(2)); + } + + public void testPrimitivePatchValues() throws IOException { + // String value + PatchEvent strEvent = PatchEvent.create().setControlId("s").setPatch("hello"); + PatchEvent strCopy = roundtrip(strEvent); + assertEquals("hello", strCopy.getPatch()); + + // Number value + PatchEvent numEvent = PatchEvent.create().setControlId("n").setPatch(Double.valueOf(3.14)); + PatchEvent numCopy = roundtrip(numEvent); + assertEquals(3.14, ((Number) numCopy.getPatch()).doubleValue(), 0.001); + + // Boolean value + PatchEvent boolEvent = PatchEvent.create().setControlId("b").setPatch(Boolean.TRUE); + PatchEvent boolCopy = roundtrip(boolEvent); + assertEquals(Boolean.TRUE, boolCopy.getPatch()); + } + + public void testNullPatch() throws IOException { + PatchEvent event = PatchEvent.create().setControlId("c3"); + // patch is null by default + assertFalse(event.hasPatch()); + assertNull(event.getPatch()); + + String json = event.toString(); + // null field should not be written + assertFalse(json.contains("patch")); + + PatchEvent copy = PatchEvent.readPatchEvent(new JsonReader(new StringR(json))); + assertEquals("c3", copy.getControlId()); + assertFalse(copy.hasPatch()); + assertNull(copy.getPatch()); + } + + public void testExplicitNullValue() throws IOException { + // JSON with explicit null value for patch + String json = "{\"controlId\":\"c4\",\"patch\":null}"; + PatchEvent copy = PatchEvent.readPatchEvent(new JsonReader(new StringR(json))); + assertEquals("c4", copy.getControlId()); + assertFalse(copy.hasPatch()); + assertNull(copy.getPatch()); + } + + public void testMultipleJsonFields() throws IOException { + Map config = new LinkedHashMap<>(); + config.put("debug", Boolean.TRUE); + config.put("maxRetries", Long.valueOf(3)); + + Map metadata = new LinkedHashMap<>(); + metadata.put("version", "1.0"); + metadata.put("tags", Arrays.asList("prod", "fast")); + + DynamicConfig dc = DynamicConfig.create() + .setName("app") + .setConfig(config) + .setMetadata(metadata); + + String json = dc.toString(); + + DynamicConfig copy = DynamicConfig.readDynamicConfig(new JsonReader(new StringR(json))); + assertEquals("app", copy.getName()); + + @SuppressWarnings("unchecked") + Map configCopy = (Map) copy.getConfig(); + assertEquals(Boolean.TRUE, configCopy.get("debug")); + assertEquals(Long.valueOf(3), configCopy.get("maxRetries")); + + @SuppressWarnings("unchecked") + Map metaCopy = (Map) copy.getMetadata(); + assertEquals("1.0", metaCopy.get("version")); + + @SuppressWarnings("unchecked") + List tags = (List) metaCopy.get("tags"); + assertEquals(2, tags.size()); + assertEquals("prod", tags.get(0)); + } + + private PatchEvent roundtrip(PatchEvent event) throws IOException { + String json = event.toString(); + return PatchEvent.readPatchEvent(new JsonReader(new StringR(json))); + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/DynamicConfig.java b/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/DynamicConfig.java new file mode 100644 index 00000000..4da1205f --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/DynamicConfig.java @@ -0,0 +1,71 @@ +package test.jsonvalue.data; + +/** + * A message with multiple json fields. + */ +public interface DynamicConfig extends de.haumacher.msgbuf.data.DataObject { + + /** + * Creates a {@link test.jsonvalue.data.DynamicConfig} instance. + */ + static test.jsonvalue.data.DynamicConfig create() { + return new test.jsonvalue.data.impl.DynamicConfig_Impl(); + } + + /** Identifier for the {@link test.jsonvalue.data.DynamicConfig} type in JSON format. */ + String DYNAMIC_CONFIG__TYPE = "DynamicConfig"; + + /** @see #getName() */ + String NAME__PROP = "name"; + + /** @see #getConfig() */ + String CONFIG__PROP = "config"; + + /** @see #getMetadata() */ + String METADATA__PROP = "metadata"; + + String getName(); + + /** + * @see #getName() + */ + test.jsonvalue.data.DynamicConfig setName(String value); + + /** + * Primary configuration (any JSON structure). + */ + Object getConfig(); + + /** + * @see #getConfig() + */ + test.jsonvalue.data.DynamicConfig setConfig(Object value); + + /** + * Checks, whether {@link #getConfig()} has a value. + */ + boolean hasConfig(); + + /** + * Optional metadata. + */ + Object getMetadata(); + + /** + * @see #getMetadata() + */ + test.jsonvalue.data.DynamicConfig setMetadata(Object value); + + /** + * Checks, whether {@link #getMetadata()} has a value. + */ + boolean hasMetadata(); + + /** Reads a new instance from the given reader. */ + static test.jsonvalue.data.DynamicConfig readDynamicConfig(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.jsonvalue.data.impl.DynamicConfig_Impl result = new test.jsonvalue.data.impl.DynamicConfig_Impl(); + result.readContent(in); + return result; + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/PatchEvent.java b/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/PatchEvent.java new file mode 100644 index 00000000..9ed06624 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/PatchEvent.java @@ -0,0 +1,56 @@ +package test.jsonvalue.data; + +/** + * A message carrying an opaque JSON payload. + */ +public interface PatchEvent extends de.haumacher.msgbuf.data.DataObject { + + /** + * Creates a {@link test.jsonvalue.data.PatchEvent} instance. + */ + static test.jsonvalue.data.PatchEvent create() { + return new test.jsonvalue.data.impl.PatchEvent_Impl(); + } + + /** Identifier for the {@link test.jsonvalue.data.PatchEvent} type in JSON format. */ + String PATCH_EVENT__TYPE = "PatchEvent"; + + /** @see #getControlId() */ + String CONTROL_ID__PROP = "controlId"; + + /** @see #getPatch() */ + String PATCH__PROP = "patch"; + + /** + * ID of the control being patched. + */ + String getControlId(); + + /** + * @see #getControlId() + */ + test.jsonvalue.data.PatchEvent setControlId(String value); + + /** + * The patch data as a native JSON value. + */ + Object getPatch(); + + /** + * @see #getPatch() + */ + test.jsonvalue.data.PatchEvent setPatch(Object value); + + /** + * Checks, whether {@link #getPatch()} has a value. + */ + boolean hasPatch(); + + /** Reads a new instance from the given reader. */ + static test.jsonvalue.data.PatchEvent readPatchEvent(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.jsonvalue.data.impl.PatchEvent_Impl result = new test.jsonvalue.data.impl.PatchEvent_Impl(); + result.readContent(in); + return result; + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/impl/DynamicConfig_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/impl/DynamicConfig_Impl.java new file mode 100644 index 00000000..81dbca71 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/impl/DynamicConfig_Impl.java @@ -0,0 +1,111 @@ +package test.jsonvalue.data.impl; + +/** + * Implementation of {@link test.jsonvalue.data.DynamicConfig}. + */ +public class DynamicConfig_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.jsonvalue.data.DynamicConfig { + + private String _name = ""; + + private Object _config = null; + + private Object _metadata = null; + + /** + * Creates a {@link DynamicConfig_Impl} instance. + * + * @see test.jsonvalue.data.DynamicConfig#create() + */ + public DynamicConfig_Impl() { + super(); + } + + @Override + public final String getName() { + return _name; + } + + @Override + public test.jsonvalue.data.DynamicConfig setName(String value) { + internalSetName(value); + return this; + } + + /** Internal setter for {@link #getName()} without chain call utility. */ + protected final void internalSetName(String value) { + _name = value; + } + + @Override + public final Object getConfig() { + return _config; + } + + @Override + public test.jsonvalue.data.DynamicConfig setConfig(Object value) { + internalSetConfig(value); + return this; + } + + /** Internal setter for {@link #getConfig()} without chain call utility. */ + protected final void internalSetConfig(Object value) { + _config = value; + } + + @Override + public final boolean hasConfig() { + return _config != null; + } + + @Override + public final Object getMetadata() { + return _metadata; + } + + @Override + public test.jsonvalue.data.DynamicConfig setMetadata(Object value) { + internalSetMetadata(value); + return this; + } + + /** Internal setter for {@link #getMetadata()} without chain call utility. */ + protected final void internalSetMetadata(Object value) { + _metadata = value; + } + + @Override + public final boolean hasMetadata() { + return _metadata != null; + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NAME__PROP); + out.value(getName()); + if (hasConfig()) { + out.name(CONFIG__PROP); + de.haumacher.msgbuf.json.JsonUtil.writeJsonValue(out, getConfig()); + } + if (hasMetadata()) { + out.name(METADATA__PROP); + de.haumacher.msgbuf.json.JsonUtil.writeJsonValue(out, getMetadata()); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case CONFIG__PROP: setConfig(de.haumacher.msgbuf.json.JsonUtil.nextJsonValue(in)); break; + case METADATA__PROP: setMetadata(de.haumacher.msgbuf.json.JsonUtil.nextJsonValue(in)); break; + default: super.readField(in, field); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/impl/PatchEvent_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/impl/PatchEvent_Impl.java new file mode 100644 index 00000000..1d95c0f2 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/impl/PatchEvent_Impl.java @@ -0,0 +1,83 @@ +package test.jsonvalue.data.impl; + +/** + * Implementation of {@link test.jsonvalue.data.PatchEvent}. + */ +public class PatchEvent_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.jsonvalue.data.PatchEvent { + + private String _controlId = ""; + + private Object _patch = null; + + /** + * Creates a {@link PatchEvent_Impl} instance. + * + * @see test.jsonvalue.data.PatchEvent#create() + */ + public PatchEvent_Impl() { + super(); + } + + @Override + public final String getControlId() { + return _controlId; + } + + @Override + public test.jsonvalue.data.PatchEvent setControlId(String value) { + internalSetControlId(value); + return this; + } + + /** Internal setter for {@link #getControlId()} without chain call utility. */ + protected final void internalSetControlId(String value) { + _controlId = value; + } + + @Override + public final Object getPatch() { + return _patch; + } + + @Override + public test.jsonvalue.data.PatchEvent setPatch(Object value) { + internalSetPatch(value); + return this; + } + + /** Internal setter for {@link #getPatch()} without chain call utility. */ + protected final void internalSetPatch(Object value) { + _patch = value; + } + + @Override + public final boolean hasPatch() { + return _patch != null; + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(CONTROL_ID__PROP); + out.value(getControlId()); + if (hasPatch()) { + out.name(PATCH__PROP); + de.haumacher.msgbuf.json.JsonUtil.writeJsonValue(out, getPatch()); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case CONTROL_ID__PROP: setControlId(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case PATCH__PROP: setPatch(de.haumacher.msgbuf.json.JsonUtil.nextJsonValue(in)); break; + default: super.readField(in, field); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/jsonvalue.proto b/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/jsonvalue.proto new file mode 100644 index 00000000..df384670 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/jsonvalue/data/jsonvalue.proto @@ -0,0 +1,27 @@ +package test.jsonvalue.data; + +option NoBinary; +option NoXml; +option NoReflection; +option NoListener; +option NoVisitor; + +/** A message carrying an opaque JSON payload. */ +message PatchEvent { + /** ID of the control being patched. */ + string controlId; + + /** The patch data as a native JSON value. */ + json patch; +} + +/** A message with multiple json fields. */ +message DynamicConfig { + string name; + + /** Primary configuration (any JSON structure). */ + json config; + + /** Optional metadata. */ + json metadata; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java index 8f6d657f..e9904d7b 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/maptype/data/impl/MyMessage_Impl.java @@ -274,7 +274,31 @@ public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java */ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { out.name(PROJECTS__ID); + { + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, getProjects().size()); + for (java.util.Map.Entry entry : getProjects().entrySet()) { + out.beginObject(); + out.name(1); + out.value(entry.getKey()); + out.name(2); + entry.getValue().writeTo(out); + out.endObject(); + } + out.endArray(); + } out.name(RATING__ID); + { + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, getRating().size()); + for (java.util.Map.Entry entry : getRating().entrySet()) { + out.beginObject(); + out.name(1); + out.value(entry.getKey()); + out.name(2); + out.value(entry.getValue()); + out.endObject(); + } + out.endArray(); + } } /** Helper for creating an object of type {@link test.maptype.data.MyMessage} from a polymorphic composition. */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java index 3ef0f87f..d17ac7b8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nullable/data/impl/NullableValues_Impl.java @@ -479,6 +479,18 @@ protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws jav } if (hasStringIntMap()) { out.name(STRING_INT_MAP__ID); + { + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, getStringIntMap().size()); + for (java.util.Map.Entry entry : getStringIntMap().entrySet()) { + out.beginObject(); + out.name(1); + out.value(entry.getKey()); + out.name(2); + out.value(entry.getValue()); + out.endObject(); + } + out.endArray(); + } } if (hasOptionalDecision()) { out.name(OPTIONAL_DECISION__ID); diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/JsonUtil.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/JsonUtil.java index cf89bf8a..c2276bc8 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/JsonUtil.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/JsonUtil.java @@ -4,6 +4,21 @@ package de.haumacher.msgbuf.json; import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import de.haumacher.msgbuf.io.StringR; +import de.haumacher.msgbuf.io.StringW; +import de.haumacher.msgbuf.json.value.JsonArray; +import de.haumacher.msgbuf.json.value.JsonBoolean; +import de.haumacher.msgbuf.json.value.JsonDouble; +import de.haumacher.msgbuf.json.value.JsonLong; +import de.haumacher.msgbuf.json.value.JsonNull; +import de.haumacher.msgbuf.json.value.JsonObject; +import de.haumacher.msgbuf.json.value.JsonString; +import de.haumacher.msgbuf.json.value.JsonValue; /** * Utilities for reading and writing JSON. @@ -46,5 +61,212 @@ public static void writeBinaryOptional(JsonWriter out, byte[] value) throws IOEx out.value(Base64Utils.toBase64(value)); } } - + + /** + * Reads any JSON value and returns it as a Java object. + * + *
    + *
  • JSON object → {@link Map}<String, Object>
  • + *
  • JSON array → {@link List}<Object>
  • + *
  • JSON string → {@link String}
  • + *
  • JSON number → {@link Long} or {@link Double}
  • + *
  • JSON boolean → {@link Boolean}
  • + *
  • JSON null → {@code null}
  • + *
+ */ + @SuppressWarnings("unchecked") + public static Object nextJsonValue(JsonReader in) throws IOException { + JsonToken token = in.peek(); + switch (token) { + case BEGIN_OBJECT: { + Map map = new LinkedHashMap<>(); + in.beginObject(); + while (in.hasNext()) { + String key = in.nextName(); + Object value = nextJsonValue(in); + map.put(key, value); + } + in.endObject(); + return map; + } + case BEGIN_ARRAY: { + List list = new ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + list.add(nextJsonValue(in)); + } + in.endArray(); + return list; + } + case STRING: + return in.nextString(); + case NUMBER: { + String raw = in.nextString(); + if (raw.indexOf('.') >= 0 || raw.indexOf('e') >= 0 || raw.indexOf('E') >= 0) { + return Double.valueOf(raw); + } + try { + return Long.valueOf(raw); + } catch (NumberFormatException e) { + return Double.valueOf(raw); + } + } + case BOOLEAN: + return Boolean.valueOf(in.nextBoolean()); + case NULL: + in.nextNull(); + return null; + default: + throw new IOException("Unexpected JSON token: " + token); + } + } + + /** + * Writes a Java object as a JSON value. + * + * @param out The JSON writer. + * @param value The value to write (may be {@code null}, {@link Map}, {@link List}, {@link String}, + * {@link Number}, or {@link Boolean}). + */ + @SuppressWarnings("unchecked") + public static void writeJsonValue(JsonWriter out, Object value) throws IOException { + if (value == null) { + out.nullValue(); + } else if (value instanceof Map) { + out.beginObject(); + for (Map.Entry entry : ((Map) value).entrySet()) { + out.name(entry.getKey()); + writeJsonValue(out, entry.getValue()); + } + out.endObject(); + } else if (value instanceof List) { + out.beginArray(); + for (Object element : (List) value) { + writeJsonValue(out, element); + } + out.endArray(); + } else if (value instanceof String) { + out.value((String) value); + } else if (value instanceof Boolean) { + out.value(((Boolean) value).booleanValue()); + } else if (value instanceof Number) { + out.value((Number) value); + } else { + throw new IOException("Cannot serialize to JSON: " + value.getClass().getName()); + } + } + + /** + * Converts a plain Java object to a {@link JsonValue} envelope for binary/XML serialization. + * + * @param value A Java object ({@code null}, {@link Map}, {@link List}, {@link String}, + * {@link Number}, or {@link Boolean}). + * @return The corresponding {@link JsonValue} envelope. + */ + @SuppressWarnings("unchecked") + public static JsonValue toJsonValue(Object value) { + if (value == null) { + return JsonNull.create(); + } else if (value instanceof Map) { + JsonObject obj = JsonObject.create(); + for (Map.Entry entry : ((Map) value).entrySet()) { + obj.putEntry(entry.getKey(), toJsonValue(entry.getValue())); + } + return obj; + } else if (value instanceof List) { + JsonArray arr = JsonArray.create(); + for (Object element : (List) value) { + arr.addElement(toJsonValue(element)); + } + return arr; + } else if (value instanceof String) { + return JsonString.create().setValue((String) value); + } else if (value instanceof Boolean) { + return JsonBoolean.create().setValue(((Boolean) value).booleanValue()); + } else if (value instanceof Long || value instanceof Integer || value instanceof Short || value instanceof Byte) { + return JsonLong.create().setValue(((Number) value).longValue()); + } else if (value instanceof Number) { + return JsonDouble.create().setValue(((Number) value).doubleValue()); + } else { + throw new IllegalArgumentException("Cannot convert to JsonValue: " + value.getClass().getName()); + } + } + + /** + * Converts a {@link JsonValue} envelope back to a plain Java object. + * + * @param value The {@link JsonValue} envelope. + * @return The corresponding Java object ({@code null}, {@link Map}, {@link List}, {@link String}, + * {@link Long}, {@link Double}, or {@link Boolean}). + */ + public static Object fromJsonValue(JsonValue value) { + if (value == null) { + return null; + } + switch (value.kind()) { + case JSON_NULL: + return null; + case JSON_STRING: + return ((JsonString) value).getValue(); + case JSON_LONG: + return Long.valueOf(((JsonLong) value).getValue()); + case JSON_DOUBLE: + return Double.valueOf(((JsonDouble) value).getValue()); + case JSON_BOOLEAN: + return Boolean.valueOf(((JsonBoolean) value).isValue()); + case JSON_ARRAY: { + List list = new ArrayList<>(); + for (JsonValue element : ((JsonArray) value).getElements()) { + list.add(fromJsonValue(element)); + } + return list; + } + case JSON_OBJECT: { + Map map = new LinkedHashMap<>(); + for (Map.Entry entry : ((JsonObject) value).getEntries().entrySet()) { + map.put(entry.getKey(), fromJsonValue(entry.getValue())); + } + return map; + } + default: + throw new IllegalArgumentException("Unknown JsonValue kind: " + value.kind()); + } + } + + /** + * Converts a Java object to its JSON string representation. + * Used for encoding JSON values in binary and XML formats. + */ + public static String jsonStringValue(Object value) { + if (value == null) { + return "null"; + } + try { + StringW buffer = new StringW(); + JsonWriter writer = new JsonWriter(buffer); + writer.setLenient(true); + writeJsonValue(writer, value); + return buffer.toString(); + } catch (IOException e) { + throw new RuntimeException("Failed to serialize JSON value.", e); + } + } + + /** + * Parses a JSON string into a Java object. + * Used for decoding JSON values from binary and XML formats. + */ + public static Object parseJsonValue(String json) { + if (json == null) { + return null; + } + try { + JsonReader reader = new JsonReader(new StringR(json)); + reader.setLenient(true); + return nextJsonValue(reader); + } catch (IOException e) { + throw new RuntimeException("Failed to parse JSON value: " + json, e); + } + } + } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonArray.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonArray.java new file mode 100644 index 00000000..05687234 --- /dev/null +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonArray.java @@ -0,0 +1,245 @@ +package de.haumacher.msgbuf.json.value; + +/** + * A JSON array value. + */ +public class JsonArray extends de.haumacher.msgbuf.json.value.JsonValue { + + /** + * Creates a {@link de.haumacher.msgbuf.json.value.JsonArray} instance. + */ + public static de.haumacher.msgbuf.json.value.JsonArray create() { + return new de.haumacher.msgbuf.json.value.JsonArray(); + } + + /** Identifier for the {@link de.haumacher.msgbuf.json.value.JsonArray} type in JSON format. */ + public static final String JSON_ARRAY__TYPE = "JsonArray"; + + /** @see #getElements() */ + private static final String ELEMENTS__PROP = "elements"; + + /** Identifier for the {@link de.haumacher.msgbuf.json.value.JsonArray} type in binary format. */ + static final int JSON_ARRAY__TYPE_ID = 6; + + /** Identifier for the property {@link #getElements()} in binary format. */ + static final int ELEMENTS__ID = 1; + + private final java.util.List _elements = new java.util.ArrayList<>(); + + /** + * Creates a {@link JsonArray} instance. + * + * @see de.haumacher.msgbuf.json.value.JsonArray#create() + */ + protected JsonArray() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.JSON_ARRAY; + } + + public final java.util.List getElements() { + return _elements; + } + + /** + * @see #getElements() + */ + public de.haumacher.msgbuf.json.value.JsonArray setElements(java.util.List value) { + internalSetElements(value); + return this; + } + + /** Internal setter for {@link #getElements()} without chain call utility. */ + protected final void internalSetElements(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'elements' cannot be null."); + _elements.clear(); + _elements.addAll(value); + } + + /** + * Adds a value to the {@link #getElements()} list. + */ + public de.haumacher.msgbuf.json.value.JsonArray addElement(de.haumacher.msgbuf.json.value.JsonValue value) { + internalAddElement(value); + return this; + } + + /** Implementation of {@link #addElement(de.haumacher.msgbuf.json.value.JsonValue)} without chain call utility. */ + protected final void internalAddElement(de.haumacher.msgbuf.json.value.JsonValue value) { + _elements.add(value); + } + + /** + * Removes a value from the {@link #getElements()} list. + */ + public final void removeElement(de.haumacher.msgbuf.json.value.JsonValue value) { + _elements.remove(value); + } + + @Override + public String jsonType() { + return JSON_ARRAY__TYPE; + } + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonArray readJsonArray(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.json.value.JsonArray result = new de.haumacher.msgbuf.json.value.JsonArray(); + result.readContent(in); + return result; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(ELEMENTS__PROP); + out.beginArray(); + for (de.haumacher.msgbuf.json.value.JsonValue x : getElements()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case ELEMENTS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(de.haumacher.msgbuf.json.value.JsonValue.readJsonValue(in)); + } + in.endArray(); + setElements(newValue); + } + break; + default: super.readField(in, field); + } + } + + /** The binary identifier for this concrete type in the polymorphic {@link de.haumacher.msgbuf.json.value.JsonArray} hierarchy. */ + public int typeId() { + return JSON_ARRAY__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(ELEMENTS__ID); + { + java.util.List values = getElements(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (de.haumacher.msgbuf.json.value.JsonValue x : values) { + x.writeTo(out); + } + out.endArray(); + } + } + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonArray readJsonArray(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + de.haumacher.msgbuf.json.value.JsonArray result = de.haumacher.msgbuf.json.value.JsonArray.readJsonArray_Content(in); + in.endObject(); + return result; + } + + /** Helper for creating an object of type {@link de.haumacher.msgbuf.json.value.JsonArray} from a polymorphic composition. */ + public static de.haumacher.msgbuf.json.value.JsonArray readJsonArray_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + de.haumacher.msgbuf.json.value.JsonArray result = new JsonArray(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case ELEMENTS__ID: { + in.beginArray(); + while (in.hasNext()) { + addElement(de.haumacher.msgbuf.json.value.JsonValue.readJsonValue(in)); + } + in.endArray(); + } + break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonArray} type. */ + public static final String JSON_ARRAY__XML_ELEMENT = "json-array"; + + /** XML attribute or element name of a {@link #getElements} property. */ + private static final String ELEMENTS__XML_ATTR = "elements"; + + @Override + public String getXmlTagName() { + return JSON_ARRAY__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + out.writeStartElement(ELEMENTS__XML_ATTR); + for (de.haumacher.msgbuf.json.value.JsonValue element : getElements()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonArray} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonArray readJsonArray_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + JsonArray result = new JsonArray(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case ELEMENTS__XML_ATTR: { + internalReadElementsListXml(in); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + private void internalReadElementsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addElement(de.haumacher.msgbuf.json.value.JsonValue.readJsonValue_XmlContent(in)); + } + } + + /** Creates a new {@link JsonArray} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonArray readJsonArray(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return de.haumacher.msgbuf.json.value.JsonArray.readJsonArray_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonBoolean.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonBoolean.java new file mode 100644 index 00000000..1f9a4c24 --- /dev/null +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonBoolean.java @@ -0,0 +1,186 @@ +package de.haumacher.msgbuf.json.value; + +/** + * A JSON boolean value. + */ +public class JsonBoolean extends de.haumacher.msgbuf.json.value.JsonValue { + + /** + * Creates a {@link de.haumacher.msgbuf.json.value.JsonBoolean} instance. + */ + public static de.haumacher.msgbuf.json.value.JsonBoolean create() { + return new de.haumacher.msgbuf.json.value.JsonBoolean(); + } + + /** Identifier for the {@link de.haumacher.msgbuf.json.value.JsonBoolean} type in JSON format. */ + public static final String JSON_BOOLEAN__TYPE = "JsonBoolean"; + + /** @see #isValue() */ + private static final String VALUE__PROP = "value"; + + /** Identifier for the {@link de.haumacher.msgbuf.json.value.JsonBoolean} type in binary format. */ + static final int JSON_BOOLEAN__TYPE_ID = 4; + + /** Identifier for the property {@link #isValue()} in binary format. */ + static final int VALUE__ID = 1; + + private boolean _value = false; + + /** + * Creates a {@link JsonBoolean} instance. + * + * @see de.haumacher.msgbuf.json.value.JsonBoolean#create() + */ + protected JsonBoolean() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.JSON_BOOLEAN; + } + + public final boolean isValue() { + return _value; + } + + /** + * @see #isValue() + */ + public de.haumacher.msgbuf.json.value.JsonBoolean setValue(boolean value) { + internalSetValue(value); + return this; + } + + /** Internal setter for {@link #isValue()} without chain call utility. */ + protected final void internalSetValue(boolean value) { + _value = value; + } + + @Override + public String jsonType() { + return JSON_BOOLEAN__TYPE; + } + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonBoolean readJsonBoolean(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.json.value.JsonBoolean result = new de.haumacher.msgbuf.json.value.JsonBoolean(); + result.readContent(in); + return result; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(VALUE__PROP); + out.value(isValue()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case VALUE__PROP: setValue(in.nextBoolean()); break; + default: super.readField(in, field); + } + } + + /** The binary identifier for this concrete type in the polymorphic {@link de.haumacher.msgbuf.json.value.JsonBoolean} hierarchy. */ + public int typeId() { + return JSON_BOOLEAN__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(VALUE__ID); + out.value(isValue()); + } + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonBoolean readJsonBoolean(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + de.haumacher.msgbuf.json.value.JsonBoolean result = de.haumacher.msgbuf.json.value.JsonBoolean.readJsonBoolean_Content(in); + in.endObject(); + return result; + } + + /** Helper for creating an object of type {@link de.haumacher.msgbuf.json.value.JsonBoolean} from a polymorphic composition. */ + public static de.haumacher.msgbuf.json.value.JsonBoolean readJsonBoolean_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + de.haumacher.msgbuf.json.value.JsonBoolean result = new JsonBoolean(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case VALUE__ID: setValue(in.nextBoolean()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonBoolean} type. */ + public static final String JSON_BOOLEAN__XML_ELEMENT = "json-boolean"; + + /** XML attribute or element name of a {@link #isValue} property. */ + private static final String VALUE__XML_ATTR = "value"; + + @Override + public String getXmlTagName() { + return JSON_BOOLEAN__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(VALUE__XML_ATTR, Boolean.toString(isValue())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonBoolean} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonBoolean readJsonBoolean_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + JsonBoolean result = new JsonBoolean(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case VALUE__XML_ATTR: { + setValue(Boolean.parseBoolean(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case VALUE__XML_ATTR: { + setValue(Boolean.parseBoolean(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + /** Creates a new {@link JsonBoolean} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonBoolean readJsonBoolean(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return de.haumacher.msgbuf.json.value.JsonBoolean.readJsonBoolean_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonDouble.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonDouble.java new file mode 100644 index 00000000..4a725d2a --- /dev/null +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonDouble.java @@ -0,0 +1,186 @@ +package de.haumacher.msgbuf.json.value; + +/** + * A JSON floating-point number value. + */ +public class JsonDouble extends de.haumacher.msgbuf.json.value.JsonValue { + + /** + * Creates a {@link de.haumacher.msgbuf.json.value.JsonDouble} instance. + */ + public static de.haumacher.msgbuf.json.value.JsonDouble create() { + return new de.haumacher.msgbuf.json.value.JsonDouble(); + } + + /** Identifier for the {@link de.haumacher.msgbuf.json.value.JsonDouble} type in JSON format. */ + public static final String JSON_DOUBLE__TYPE = "JsonDouble"; + + /** @see #getValue() */ + private static final String VALUE__PROP = "value"; + + /** Identifier for the {@link de.haumacher.msgbuf.json.value.JsonDouble} type in binary format. */ + static final int JSON_DOUBLE__TYPE_ID = 3; + + /** Identifier for the property {@link #getValue()} in binary format. */ + static final int VALUE__ID = 1; + + private double _value = 0.0d; + + /** + * Creates a {@link JsonDouble} instance. + * + * @see de.haumacher.msgbuf.json.value.JsonDouble#create() + */ + protected JsonDouble() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.JSON_DOUBLE; + } + + public final double getValue() { + return _value; + } + + /** + * @see #getValue() + */ + public de.haumacher.msgbuf.json.value.JsonDouble setValue(double value) { + internalSetValue(value); + return this; + } + + /** Internal setter for {@link #getValue()} without chain call utility. */ + protected final void internalSetValue(double value) { + _value = value; + } + + @Override + public String jsonType() { + return JSON_DOUBLE__TYPE; + } + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonDouble readJsonDouble(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.json.value.JsonDouble result = new de.haumacher.msgbuf.json.value.JsonDouble(); + result.readContent(in); + return result; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(VALUE__PROP); + out.value(getValue()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case VALUE__PROP: setValue(in.nextDouble()); break; + default: super.readField(in, field); + } + } + + /** The binary identifier for this concrete type in the polymorphic {@link de.haumacher.msgbuf.json.value.JsonDouble} hierarchy. */ + public int typeId() { + return JSON_DOUBLE__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(VALUE__ID); + out.value(getValue()); + } + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonDouble readJsonDouble(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + de.haumacher.msgbuf.json.value.JsonDouble result = de.haumacher.msgbuf.json.value.JsonDouble.readJsonDouble_Content(in); + in.endObject(); + return result; + } + + /** Helper for creating an object of type {@link de.haumacher.msgbuf.json.value.JsonDouble} from a polymorphic composition. */ + public static de.haumacher.msgbuf.json.value.JsonDouble readJsonDouble_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + de.haumacher.msgbuf.json.value.JsonDouble result = new JsonDouble(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case VALUE__ID: setValue(in.nextDouble()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonDouble} type. */ + public static final String JSON_DOUBLE__XML_ELEMENT = "json-double"; + + /** XML attribute or element name of a {@link #getValue} property. */ + private static final String VALUE__XML_ATTR = "value"; + + @Override + public String getXmlTagName() { + return JSON_DOUBLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(VALUE__XML_ATTR, Double.toString(getValue())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonDouble} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonDouble readJsonDouble_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + JsonDouble result = new JsonDouble(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case VALUE__XML_ATTR: { + setValue(Double.parseDouble(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case VALUE__XML_ATTR: { + setValue(Double.parseDouble(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + /** Creates a new {@link JsonDouble} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonDouble readJsonDouble(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return de.haumacher.msgbuf.json.value.JsonDouble.readJsonDouble_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonLong.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonLong.java new file mode 100644 index 00000000..45bcc79a --- /dev/null +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonLong.java @@ -0,0 +1,186 @@ +package de.haumacher.msgbuf.json.value; + +/** + * A JSON integer number value (fits in a long). + */ +public class JsonLong extends de.haumacher.msgbuf.json.value.JsonValue { + + /** + * Creates a {@link de.haumacher.msgbuf.json.value.JsonLong} instance. + */ + public static de.haumacher.msgbuf.json.value.JsonLong create() { + return new de.haumacher.msgbuf.json.value.JsonLong(); + } + + /** Identifier for the {@link de.haumacher.msgbuf.json.value.JsonLong} type in JSON format. */ + public static final String JSON_LONG__TYPE = "JsonLong"; + + /** @see #getValue() */ + private static final String VALUE__PROP = "value"; + + /** Identifier for the {@link de.haumacher.msgbuf.json.value.JsonLong} type in binary format. */ + static final int JSON_LONG__TYPE_ID = 2; + + /** Identifier for the property {@link #getValue()} in binary format. */ + static final int VALUE__ID = 1; + + private long _value = 0L; + + /** + * Creates a {@link JsonLong} instance. + * + * @see de.haumacher.msgbuf.json.value.JsonLong#create() + */ + protected JsonLong() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.JSON_LONG; + } + + public final long getValue() { + return _value; + } + + /** + * @see #getValue() + */ + public de.haumacher.msgbuf.json.value.JsonLong setValue(long value) { + internalSetValue(value); + return this; + } + + /** Internal setter for {@link #getValue()} without chain call utility. */ + protected final void internalSetValue(long value) { + _value = value; + } + + @Override + public String jsonType() { + return JSON_LONG__TYPE; + } + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonLong readJsonLong(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.json.value.JsonLong result = new de.haumacher.msgbuf.json.value.JsonLong(); + result.readContent(in); + return result; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(VALUE__PROP); + out.value(getValue()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case VALUE__PROP: setValue(in.nextLong()); break; + default: super.readField(in, field); + } + } + + /** The binary identifier for this concrete type in the polymorphic {@link de.haumacher.msgbuf.json.value.JsonLong} hierarchy. */ + public int typeId() { + return JSON_LONG__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(VALUE__ID); + out.value(getValue()); + } + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonLong readJsonLong(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + de.haumacher.msgbuf.json.value.JsonLong result = de.haumacher.msgbuf.json.value.JsonLong.readJsonLong_Content(in); + in.endObject(); + return result; + } + + /** Helper for creating an object of type {@link de.haumacher.msgbuf.json.value.JsonLong} from a polymorphic composition. */ + public static de.haumacher.msgbuf.json.value.JsonLong readJsonLong_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + de.haumacher.msgbuf.json.value.JsonLong result = new JsonLong(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case VALUE__ID: setValue(in.nextLong()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonLong} type. */ + public static final String JSON_LONG__XML_ELEMENT = "json-long"; + + /** XML attribute or element name of a {@link #getValue} property. */ + private static final String VALUE__XML_ATTR = "value"; + + @Override + public String getXmlTagName() { + return JSON_LONG__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(VALUE__XML_ATTR, Long.toString(getValue())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonLong} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonLong readJsonLong_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + JsonLong result = new JsonLong(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case VALUE__XML_ATTR: { + setValue(Long.parseLong(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case VALUE__XML_ATTR: { + setValue(Long.parseLong(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + /** Creates a new {@link JsonLong} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonLong readJsonLong(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return de.haumacher.msgbuf.json.value.JsonLong.readJsonLong_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonNull.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonNull.java new file mode 100644 index 00000000..0aaef7b5 --- /dev/null +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonNull.java @@ -0,0 +1,119 @@ +package de.haumacher.msgbuf.json.value; + +/** + * A JSON null value. + */ +public class JsonNull extends de.haumacher.msgbuf.json.value.JsonValue { + + /** + * Creates a {@link de.haumacher.msgbuf.json.value.JsonNull} instance. + */ + public static de.haumacher.msgbuf.json.value.JsonNull create() { + return new de.haumacher.msgbuf.json.value.JsonNull(); + } + + /** Identifier for the {@link de.haumacher.msgbuf.json.value.JsonNull} type in JSON format. */ + public static final String JSON_NULL__TYPE = "JsonNull"; + + /** Identifier for the {@link de.haumacher.msgbuf.json.value.JsonNull} type in binary format. */ + static final int JSON_NULL__TYPE_ID = 5; + + /** + * Creates a {@link JsonNull} instance. + * + * @see de.haumacher.msgbuf.json.value.JsonNull#create() + */ + protected JsonNull() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.JSON_NULL; + } + + @Override + public String jsonType() { + return JSON_NULL__TYPE; + } + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonNull readJsonNull(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.json.value.JsonNull result = new de.haumacher.msgbuf.json.value.JsonNull(); + result.readContent(in); + return result; + } + + /** The binary identifier for this concrete type in the polymorphic {@link de.haumacher.msgbuf.json.value.JsonNull} hierarchy. */ + public int typeId() { + return JSON_NULL__TYPE_ID; + } + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonNull readJsonNull(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + de.haumacher.msgbuf.json.value.JsonNull result = de.haumacher.msgbuf.json.value.JsonNull.readJsonNull_Content(in); + in.endObject(); + return result; + } + + /** Helper for creating an object of type {@link de.haumacher.msgbuf.json.value.JsonNull} from a polymorphic composition. */ + public static de.haumacher.msgbuf.json.value.JsonNull readJsonNull_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + de.haumacher.msgbuf.json.value.JsonNull result = new JsonNull(); + result.readContent(in); + return result; + } + + /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonNull} type. */ + public static final String JSON_NULL__XML_ELEMENT = "json-null"; + + @Override + public String getXmlTagName() { + return JSON_NULL__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonNull} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonNull readJsonNull_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + JsonNull result = new JsonNull(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + /** Creates a new {@link JsonNull} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonNull readJsonNull(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return de.haumacher.msgbuf.json.value.JsonNull.readJsonNull_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonObject.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonObject.java new file mode 100644 index 00000000..8ffc6757 --- /dev/null +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonObject.java @@ -0,0 +1,245 @@ +package de.haumacher.msgbuf.json.value; + +/** + * A JSON object value (ordered map of string keys to JSON values). + */ +public class JsonObject extends de.haumacher.msgbuf.json.value.JsonValue { + + /** + * Creates a {@link de.haumacher.msgbuf.json.value.JsonObject} instance. + */ + public static de.haumacher.msgbuf.json.value.JsonObject create() { + return new de.haumacher.msgbuf.json.value.JsonObject(); + } + + /** Identifier for the {@link de.haumacher.msgbuf.json.value.JsonObject} type in JSON format. */ + public static final String JSON_OBJECT__TYPE = "JsonObject"; + + /** @see #getEntries() */ + private static final String ENTRIES__PROP = "entries"; + + /** Identifier for the {@link de.haumacher.msgbuf.json.value.JsonObject} type in binary format. */ + static final int JSON_OBJECT__TYPE_ID = 7; + + /** Identifier for the property {@link #getEntries()} in binary format. */ + static final int ENTRIES__ID = 1; + + private final java.util.Map _entries = new java.util.LinkedHashMap<>(); + + /** + * Creates a {@link JsonObject} instance. + * + * @see de.haumacher.msgbuf.json.value.JsonObject#create() + */ + protected JsonObject() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.JSON_OBJECT; + } + + public final java.util.Map getEntries() { + return _entries; + } + + /** + * @see #getEntries() + */ + public de.haumacher.msgbuf.json.value.JsonObject setEntries(java.util.Map value) { + internalSetEntries(value); + return this; + } + + /** Internal setter for {@link #getEntries()} without chain call utility. */ + protected final void internalSetEntries(java.util.Map value) { + if (value == null) throw new IllegalArgumentException("Property 'entries' cannot be null."); + _entries.clear(); + _entries.putAll(value); + } + + /** + * Adds a key value pair to the {@link #getEntries()} map. + */ + public de.haumacher.msgbuf.json.value.JsonObject putEntry(String key, de.haumacher.msgbuf.json.value.JsonValue value) { + internalPutEntry(key, value); + return this; + } + + /** Implementation of {@link #putEntry(String, de.haumacher.msgbuf.json.value.JsonValue)} without chain call utility. */ + protected final void internalPutEntry(String key, de.haumacher.msgbuf.json.value.JsonValue value) { + if (_entries.containsKey(key)) { + throw new IllegalArgumentException("Property 'entries' already contains a value for key '" + key + "'."); + } + _entries.put(key, value); + } + + /** + * Removes a key from the {@link #getEntries()} map. + */ + public final void removeEntry(String key) { + _entries.remove(key); + } + + @Override + public String jsonType() { + return JSON_OBJECT__TYPE; + } + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonObject readJsonObject(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.json.value.JsonObject result = new de.haumacher.msgbuf.json.value.JsonObject(); + result.readContent(in); + return result; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(ENTRIES__PROP); + out.beginObject(); + for (java.util.Map.Entry entry : getEntries().entrySet()) { + out.name(entry.getKey()); + entry.getValue().writeTo(out); + } + out.endObject(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case ENTRIES__PROP: { + java.util.Map newValue = new java.util.LinkedHashMap<>(); + in.beginObject(); + while (in.hasNext()) { + newValue.put(in.nextName(), de.haumacher.msgbuf.json.value.JsonValue.readJsonValue(in)); + } + in.endObject(); + setEntries(newValue); + break; + } + default: super.readField(in, field); + } + } + + /** The binary identifier for this concrete type in the polymorphic {@link de.haumacher.msgbuf.json.value.JsonObject} hierarchy. */ + public int typeId() { + return JSON_OBJECT__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(ENTRIES__ID); + { + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, getEntries().size()); + for (java.util.Map.Entry entry : getEntries().entrySet()) { + out.beginObject(); + out.name(1); + out.value(entry.getKey()); + out.name(2); + entry.getValue().writeTo(out); + out.endObject(); + } + out.endArray(); + } + } + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonObject readJsonObject(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + de.haumacher.msgbuf.json.value.JsonObject result = de.haumacher.msgbuf.json.value.JsonObject.readJsonObject_Content(in); + in.endObject(); + return result; + } + + /** Helper for creating an object of type {@link de.haumacher.msgbuf.json.value.JsonObject} from a polymorphic composition. */ + public static de.haumacher.msgbuf.json.value.JsonObject readJsonObject_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + de.haumacher.msgbuf.json.value.JsonObject result = new JsonObject(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case ENTRIES__ID: { + in.beginArray(); + while (in.hasNext()) { + in.beginObject(); + String key = ""; + de.haumacher.msgbuf.json.value.JsonValue value = null; + while (in.hasNext()) { + switch (in.nextName()) { + case 1: key = in.nextString(); break; + case 2: value = de.haumacher.msgbuf.json.value.JsonValue.readJsonValue(in); break; + default: in.skipValue(); break; + } + } + putEntry(key, value); + in.endObject(); + } + in.endArray(); + break; + } + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonObject} type. */ + public static final String JSON_OBJECT__XML_ELEMENT = "json-object"; + + /** XML attribute or element name of a {@link #getEntries} property. */ + private static final String ENTRIES__XML_ATTR = "entries"; + + @Override + public String getXmlTagName() { + return JSON_OBJECT__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonObject} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonObject readJsonObject_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + JsonObject result = new JsonObject(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + /** Creates a new {@link JsonObject} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonObject readJsonObject(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return de.haumacher.msgbuf.json.value.JsonObject.readJsonObject_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonString.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonString.java new file mode 100644 index 00000000..ea9b83ac --- /dev/null +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonString.java @@ -0,0 +1,186 @@ +package de.haumacher.msgbuf.json.value; + +/** + * A JSON string value. + */ +public class JsonString extends de.haumacher.msgbuf.json.value.JsonValue { + + /** + * Creates a {@link de.haumacher.msgbuf.json.value.JsonString} instance. + */ + public static de.haumacher.msgbuf.json.value.JsonString create() { + return new de.haumacher.msgbuf.json.value.JsonString(); + } + + /** Identifier for the {@link de.haumacher.msgbuf.json.value.JsonString} type in JSON format. */ + public static final String JSON_STRING__TYPE = "JsonString"; + + /** @see #getValue() */ + private static final String VALUE__PROP = "value"; + + /** Identifier for the {@link de.haumacher.msgbuf.json.value.JsonString} type in binary format. */ + static final int JSON_STRING__TYPE_ID = 1; + + /** Identifier for the property {@link #getValue()} in binary format. */ + static final int VALUE__ID = 1; + + private String _value = ""; + + /** + * Creates a {@link JsonString} instance. + * + * @see de.haumacher.msgbuf.json.value.JsonString#create() + */ + protected JsonString() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.JSON_STRING; + } + + public final String getValue() { + return _value; + } + + /** + * @see #getValue() + */ + public de.haumacher.msgbuf.json.value.JsonString setValue(String value) { + internalSetValue(value); + return this; + } + + /** Internal setter for {@link #getValue()} without chain call utility. */ + protected final void internalSetValue(String value) { + _value = value; + } + + @Override + public String jsonType() { + return JSON_STRING__TYPE; + } + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonString readJsonString(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.json.value.JsonString result = new de.haumacher.msgbuf.json.value.JsonString(); + result.readContent(in); + return result; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(VALUE__PROP); + out.value(getValue()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case VALUE__PROP: setValue(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + /** The binary identifier for this concrete type in the polymorphic {@link de.haumacher.msgbuf.json.value.JsonString} hierarchy. */ + public int typeId() { + return JSON_STRING__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(VALUE__ID); + out.value(getValue()); + } + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonString readJsonString(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + de.haumacher.msgbuf.json.value.JsonString result = de.haumacher.msgbuf.json.value.JsonString.readJsonString_Content(in); + in.endObject(); + return result; + } + + /** Helper for creating an object of type {@link de.haumacher.msgbuf.json.value.JsonString} from a polymorphic composition. */ + public static de.haumacher.msgbuf.json.value.JsonString readJsonString_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + de.haumacher.msgbuf.json.value.JsonString result = new JsonString(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case VALUE__ID: setValue(in.nextString()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonString} type. */ + public static final String JSON_STRING__XML_ELEMENT = "json-string"; + + /** XML attribute or element name of a {@link #getValue} property. */ + private static final String VALUE__XML_ATTR = "value"; + + @Override + public String getXmlTagName() { + return JSON_STRING__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(VALUE__XML_ATTR, getValue()); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonString} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonString readJsonString_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + JsonString result = new JsonString(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case VALUE__XML_ATTR: { + setValue(value); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case VALUE__XML_ATTR: { + setValue(in.getElementText()); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + /** Creates a new {@link JsonString} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonString readJsonString(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return de.haumacher.msgbuf.json.value.JsonString.readJsonString_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonValue.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonValue.java new file mode 100644 index 00000000..adbeef15 --- /dev/null +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonValue.java @@ -0,0 +1,244 @@ +package de.haumacher.msgbuf.json.value; + +/** + * Envelope type representing any JSON value for binary and XML serialization. + */ +public abstract class JsonValue extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.xml.XmlSerializable { + + /** Type codes for the {@link de.haumacher.msgbuf.json.value.JsonValue} hierarchy. */ + public enum TypeKind { + + /** Type literal for {@link de.haumacher.msgbuf.json.value.JsonString}. */ + JSON_STRING, + + /** Type literal for {@link de.haumacher.msgbuf.json.value.JsonLong}. */ + JSON_LONG, + + /** Type literal for {@link de.haumacher.msgbuf.json.value.JsonDouble}. */ + JSON_DOUBLE, + + /** Type literal for {@link de.haumacher.msgbuf.json.value.JsonBoolean}. */ + JSON_BOOLEAN, + + /** Type literal for {@link de.haumacher.msgbuf.json.value.JsonNull}. */ + JSON_NULL, + + /** Type literal for {@link de.haumacher.msgbuf.json.value.JsonArray}. */ + JSON_ARRAY, + + /** Type literal for {@link de.haumacher.msgbuf.json.value.JsonObject}. */ + JSON_OBJECT, + ; + + } + + /** + * Creates a {@link JsonValue} instance. + */ + protected JsonValue() { + super(); + } + + /** The type code of this instance. */ + public abstract TypeKind kind(); + + /** The type identifier for this concrete subtype. */ + public abstract String jsonType(); + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonValue readJsonValue(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + de.haumacher.msgbuf.json.value.JsonValue result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case JsonString.JSON_STRING__TYPE: result = de.haumacher.msgbuf.json.value.JsonString.readJsonString(in); break; + case JsonLong.JSON_LONG__TYPE: result = de.haumacher.msgbuf.json.value.JsonLong.readJsonLong(in); break; + case JsonDouble.JSON_DOUBLE__TYPE: result = de.haumacher.msgbuf.json.value.JsonDouble.readJsonDouble(in); break; + case JsonBoolean.JSON_BOOLEAN__TYPE: result = de.haumacher.msgbuf.json.value.JsonBoolean.readJsonBoolean(in); break; + case JsonNull.JSON_NULL__TYPE: result = de.haumacher.msgbuf.json.value.JsonNull.readJsonNull(in); break; + case JsonArray.JSON_ARRAY__TYPE: result = de.haumacher.msgbuf.json.value.JsonArray.readJsonArray(in); break; + case JsonObject.JSON_OBJECT__TYPE: result = de.haumacher.msgbuf.json.value.JsonObject.readJsonObject(in); break; + default: in.skipValue(); result = null; break; + } + in.endArray(); + return result; + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.beginArray(); + out.value(jsonType()); + writeContent(out); + out.endArray(); + } + + /** The binary identifier for this concrete type in the polymorphic {@link de.haumacher.msgbuf.json.value.JsonValue} hierarchy. */ + abstract int typeId(); + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + out.name(0); + out.value(typeId()); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + // No fields to write, hook for subclasses. + } + + /** Reads a new instance from the given reader. */ + public static de.haumacher.msgbuf.json.value.JsonValue readJsonValue(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + int typeField = in.nextName(); + assert typeField == 0; + int type = in.nextInt(); + de.haumacher.msgbuf.json.value.JsonValue result; + switch (type) { + case de.haumacher.msgbuf.json.value.JsonString.JSON_STRING__TYPE_ID: result = de.haumacher.msgbuf.json.value.JsonString.readJsonString_Content(in); break; + case de.haumacher.msgbuf.json.value.JsonLong.JSON_LONG__TYPE_ID: result = de.haumacher.msgbuf.json.value.JsonLong.readJsonLong_Content(in); break; + case de.haumacher.msgbuf.json.value.JsonDouble.JSON_DOUBLE__TYPE_ID: result = de.haumacher.msgbuf.json.value.JsonDouble.readJsonDouble_Content(in); break; + case de.haumacher.msgbuf.json.value.JsonBoolean.JSON_BOOLEAN__TYPE_ID: result = de.haumacher.msgbuf.json.value.JsonBoolean.readJsonBoolean_Content(in); break; + case de.haumacher.msgbuf.json.value.JsonNull.JSON_NULL__TYPE_ID: result = de.haumacher.msgbuf.json.value.JsonNull.readJsonNull_Content(in); break; + case de.haumacher.msgbuf.json.value.JsonArray.JSON_ARRAY__TYPE_ID: result = de.haumacher.msgbuf.json.value.JsonArray.readJsonArray_Content(in); break; + case de.haumacher.msgbuf.json.value.JsonObject.JSON_OBJECT__TYPE_ID: result = de.haumacher.msgbuf.json.value.JsonObject.readJsonObject_Content(in); break; + default: result = null; while (in.hasNext()) {in.skipValue(); } + } + in.endObject(); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + default: in.skipValue(); + } + } + + /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonValue} type. */ + public static final String JSON_VALUE__XML_ELEMENT = "json-value"; + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonValue} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonValue readJsonValue_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case JsonString.JSON_STRING__XML_ELEMENT: { + return de.haumacher.msgbuf.json.value.JsonString.readJsonString_XmlContent(in); + } + + case JsonLong.JSON_LONG__XML_ELEMENT: { + return de.haumacher.msgbuf.json.value.JsonLong.readJsonLong_XmlContent(in); + } + + case JsonDouble.JSON_DOUBLE__XML_ELEMENT: { + return de.haumacher.msgbuf.json.value.JsonDouble.readJsonDouble_XmlContent(in); + } + + case JsonBoolean.JSON_BOOLEAN__XML_ELEMENT: { + return de.haumacher.msgbuf.json.value.JsonBoolean.readJsonBoolean_XmlContent(in); + } + + case JsonNull.JSON_NULL__XML_ELEMENT: { + return de.haumacher.msgbuf.json.value.JsonNull.readJsonNull_XmlContent(in); + } + + case JsonArray.JSON_ARRAY__XML_ELEMENT: { + return de.haumacher.msgbuf.json.value.JsonArray.readJsonArray_XmlContent(in); + } + + case JsonObject.JSON_OBJECT__XML_ELEMENT: { + return de.haumacher.msgbuf.json.value.JsonObject.readJsonObject_XmlContent(in); + } + + default: { + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + /** Creates a new {@link JsonValue} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static JsonValue readJsonValue(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return de.haumacher.msgbuf.json.value.JsonValue.readJsonValue_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/jsonvalue.proto b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/jsonvalue.proto new file mode 100644 index 00000000..3e8d9dd2 --- /dev/null +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/jsonvalue.proto @@ -0,0 +1,44 @@ +package de.haumacher.msgbuf.json.value; + +option NoInterfaces; +option NoReflection; +option NoListener; +option NoVisitor; + +/** Envelope type representing any JSON value for binary and XML serialization. */ +abstract message JsonValue { +} + +/** A JSON string value. */ +message JsonString extends JsonValue { + string value; +} + +/** A JSON integer number value (fits in a long). */ +message JsonLong extends JsonValue { + long value; +} + +/** A JSON floating-point number value. */ +message JsonDouble extends JsonValue { + double value; +} + +/** A JSON boolean value. */ +message JsonBoolean extends JsonValue { + boolean value; +} + +/** A JSON null value. */ +message JsonNull extends JsonValue { +} + +/** A JSON array value. */ +message JsonArray extends JsonValue { + repeated JsonValue elements; +} + +/** A JSON object value (ordered map of string keys to JSON values). */ +message JsonObject extends JsonValue { + map entries; +} From df7e81317d45cc1b0ab77dc44f002376d535450e Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 25 Mar 2026 11:52:16 +0100 Subject: [PATCH 171/207] chore: bump version to 1.2.0-SNAPSHOT and document json type in README Bump all module versions from 1.1.13-SNAPSHOT to 1.2.0-SNAPSHOT. Update README with json field type documentation and version references. Co-Authored-By: Claude Opus 4.6 (1M context) --- README.md | 36 +++++++++++++++++++++++++-- de.haumacher.msgbuf.generator/pom.xml | 4 +-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 +-- pom.xml | 2 +- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 82966570..f404620e 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ In contrast to `protobuf`, `msgbuf` supports: de.haumacher.msgbuf msgbuf-api - 1.1.11 + 1.2.0 ``` @@ -32,7 +32,7 @@ To the `build/plugins` section add: de.haumacher.msgbuf msgbuf-generator-maven-plugin - 1.1.11 + 1.2.0 @@ -161,6 +161,38 @@ In addition to the protobuf type names, `msgbuf` supports shorter aliases: - `long` for `int64` - `boolean` for `bool` +### Native JSON value type (`json`) + +The `json` type represents an opaque JSON value — any valid JSON structure (object, array, string, number, boolean, or null). This avoids double-serialization when a message needs to carry dynamically-typed data: + +```protobuf +message PatchEvent { + string controlId; + json patch; +} +``` + +In JSON format, the value is written natively without string-wrapping: + +```json +{"controlId":"c1","patch":{"nodes":{"n1":{"x":100}}}} +``` + +The generated Java API uses `Object` as the field type. Supported value types are `Map`, `List`, `String`, `Long`, `Double`, `Boolean`, and `null`: + +```java +Map patch = new LinkedHashMap<>(); +patch.put("nodes", ...); +PatchEvent event = PatchEvent.create() + .setControlId("c1") + .setPatch(patch); + +// Reading back: +Object value = event.getPatch(); // Map, List, String, Number, Boolean, or null +``` + +For binary serialization, json values are wrapped in a `JsonValue` message envelope (defined in `de.haumacher.msgbuf.json.value`). For XML, json values are encoded as JSON strings in element text. + ## Global protocol options ### `option NoJson` diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 2cd67510..e0ef6ede 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.13-SNAPSHOT + 1.2.0-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.1.13-SNAPSHOT + 1.2.0-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 098cc308..59bc8896 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.13-SNAPSHOT + 1.2.0-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index e32596ba..80548645 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.13-SNAPSHOT + 1.2.0-SNAPSHOT msgbuf-generator-maven-plugin @@ -33,7 +33,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.1.13-SNAPSHOT + 1.2.0-SNAPSHOT diff --git a/pom.xml b/pom.xml index 2eefeda2..b793da89 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.1.13-SNAPSHOT + 1.2.0-SNAPSHOT pom From 13c0663b3102be3fe5fc707ab43d15f96fb86045 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 25 Mar 2026 12:05:28 +0100 Subject: [PATCH 172/207] docs: add CHANGELOG.md Co-Authored-By: Claude Opus 4.6 (1M context) --- CHANGELOG.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..a35f173b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,26 @@ +# Changelog + +## 1.2.0 + +### New Features +- **`json` field type**: Native JSON value type for carrying opaque JSON data without double-serialization. In JSON format, values are written inline; for binary, a `JsonValue` envelope hierarchy is used. Java API uses `Object` (Map, List, String, Number, Boolean, null). +- **`option OpenWorld`**: Cross-file protocol extension for abstract type hierarchies. Subtypes can be defined in separate `.proto` files and modules using `import` and `extends`. Extension types are discovered at runtime via `ServiceLoader`. +- **Classpath-based import resolution**: Imports are resolved from compile-scope dependency JARs, so no file system paths to base modules are needed. +- **Cross-file message embedding**: Import mechanism supports using messages from one protocol as field types in another (not just `extends`). +- **`-resources` CLI argument**: Configure output directory for generated `META-INF/services` descriptors. +- **`-cp` CLI argument**: Specify JARs to search for imported `.proto` files. +- **Maven plugin `includePaths` parameter**: Configure additional include paths for proto file resolution. + +### Bug Fixes +- **Binary map serialization**: Fix missing write implementation for `map` fields in binary format. + +## 1.1.11 + +### New Features +- **`option UnorderedMaps`**: Use `HashMap` instead of `LinkedHashMap` for map properties when insertion order is not important. +- **`@Singular("item")` annotation**: Specify singular form for repeated fields, overriding automatic pluralization heuristics. +- **Default field values**: Fields can specify inline default values using `= value` syntax. +- **Backtick-quoted identifiers**: Use backticks to escape identifiers that clash with msgbuf keywords. +- **Primitive type aliases**: `int` for `int32`, `long` for `int64`, `boolean` for `bool`. +- **`@Operations("ClassName")` annotation**: Mix-in interfaces with operations on data classes. +- **Dart code generation**: `option DartLib` generates Dart data classes with JSON serialization. From 5f96a4d55d7724bf9daa2ccd72d977aa3da87186 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 25 Mar 2026 12:34:21 +0100 Subject: [PATCH 173/207] [maven-release-plugin] prepare release msgbuf-api-1.2.0 --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index e0ef6ede..db989526 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.0-SNAPSHOT + 1.2.0 msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.2.0-SNAPSHOT + 1.2.0 diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 59bc8896..2e062243 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.0-SNAPSHOT + 1.2.0 msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 80548645..976fd301 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.0-SNAPSHOT + 1.2.0 msgbuf-generator-maven-plugin @@ -33,7 +33,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.2.0-SNAPSHOT + 1.2.0 diff --git a/pom.xml b/pom.xml index b793da89..a457c835 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.0-SNAPSHOT + 1.2.0 pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - HEAD + msgbuf-api-1.2.0 From 77d9309fcf6cd6b8305e3a22c9b8e572770ddce1 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Wed, 25 Mar 2026 12:34:23 +0100 Subject: [PATCH 174/207] [maven-release-plugin] prepare for next development iteration --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index db989526..21ec4c97 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.0 + 1.2.1-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.2.0 + 1.2.1-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 2e062243..b0be8d07 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.0 + 1.2.1-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 976fd301..ce7afb21 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.0 + 1.2.1-SNAPSHOT msgbuf-generator-maven-plugin @@ -33,7 +33,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.2.0 + 1.2.1-SNAPSHOT diff --git a/pom.xml b/pom.xml index a457c835..577ea76c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.0 + 1.2.1-SNAPSHOT pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - msgbuf-api-1.2.0 + HEAD From 3718ba07b072e67ccfe8043fa7cabb8b060ca2d0 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Thu, 26 Mar 2026 08:57:53 +0100 Subject: [PATCH 175/207] fix: remove XML serialization from JsonValue classes for GWT compatibility The JsonValue envelope types in msgbuf-api must not reference javax.xml.stream.* (StAX API) since it is unavailable in GWT. Added NoXml option to jsonvalue.proto and regenerated all classes. JSON fields are serialized as text strings in XML via JsonUtil instead. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../generator/plugins/XmlStreamingPlugin.java | 4 + .../msgbuf/json/value/JsonArray.java | 74 ------------ .../msgbuf/json/value/JsonBoolean.java | 64 ---------- .../msgbuf/json/value/JsonDouble.java | 64 ---------- .../haumacher/msgbuf/json/value/JsonLong.java | 64 ---------- .../haumacher/msgbuf/json/value/JsonNull.java | 52 -------- .../msgbuf/json/value/JsonObject.java | 55 --------- .../msgbuf/json/value/JsonString.java | 64 ---------- .../msgbuf/json/value/JsonValue.java | 114 +----------------- .../msgbuf/json/value/jsonvalue.proto | 13 +- 10 files changed, 18 insertions(+), 550 deletions(-) diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java index 9551bc4e..29ab65c0 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java @@ -553,6 +553,9 @@ String fromStringSingle(de.haumacher.msgbuf.generator.ast.Type type, String valu return "java.util.Base64.getDecoder().decode(" + value + ");"; case JSON: + // JSON values are encoded as JSON text strings in XML instead of using the JsonValue + // envelope types. The JsonValue classes (in msgbuf-api) cannot have XML serialization + // because msgbuf-api must be GWT-compatible, and GWT does not support javax.xml.stream. return "de.haumacher.msgbuf.json.JsonUtil.parseJsonValue(" + value + ")"; } @@ -598,6 +601,7 @@ String toStringSingle(de.haumacher.msgbuf.generator.ast.Type type, String value) return "java.util.Base64.getEncoder().encodeToString(" + value + ");"; case JSON: + // See fromStringSingle(): JSON values are transmitted as JSON text strings in XML. return "de.haumacher.msgbuf.json.JsonUtil.jsonStringValue(" + value + ")"; } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonArray.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonArray.java index 05687234..e9bf4233 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonArray.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonArray.java @@ -168,78 +168,4 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonArray} type. */ - public static final String JSON_ARRAY__XML_ELEMENT = "json-array"; - - /** XML attribute or element name of a {@link #getElements} property. */ - private static final String ELEMENTS__XML_ATTR = "elements"; - - @Override - public String getXmlTagName() { - return JSON_ARRAY__XML_ELEMENT; - } - - /** Serializes all fields that are written as XML attributes. */ - @Override - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeAttributes(out); - } - - /** Serializes all fields that are written as XML elements. */ - @Override - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeElements(out); - out.writeStartElement(ELEMENTS__XML_ATTR); - for (de.haumacher.msgbuf.json.value.JsonValue element : getElements()) { - element.writeTo(out); - } - out.writeEndElement(); - } - - /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonArray} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonArray readJsonArray_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - JsonArray result = new JsonArray(); - result.readContentXml(in); - return result; - } - - @Override - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - default: { - super.readFieldXmlAttribute(name, value); - } - } - } - - @Override - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - case ELEMENTS__XML_ATTR: { - internalReadElementsListXml(in); - break; - } - default: { - super.readFieldXmlElement(in, localName); - } - } - } - - private void internalReadElementsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - while (true) { - int event = in.nextTag(); - if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { - break; - } - - addElement(de.haumacher.msgbuf.json.value.JsonValue.readJsonValue_XmlContent(in)); - } - } - - /** Creates a new {@link JsonArray} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonArray readJsonArray(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - in.nextTag(); - return de.haumacher.msgbuf.json.value.JsonArray.readJsonArray_XmlContent(in); - } - } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonBoolean.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonBoolean.java index 1f9a4c24..2618288a 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonBoolean.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonBoolean.java @@ -119,68 +119,4 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonBoolean} type. */ - public static final String JSON_BOOLEAN__XML_ELEMENT = "json-boolean"; - - /** XML attribute or element name of a {@link #isValue} property. */ - private static final String VALUE__XML_ATTR = "value"; - - @Override - public String getXmlTagName() { - return JSON_BOOLEAN__XML_ELEMENT; - } - - /** Serializes all fields that are written as XML attributes. */ - @Override - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeAttributes(out); - out.writeAttribute(VALUE__XML_ATTR, Boolean.toString(isValue())); - } - - /** Serializes all fields that are written as XML elements. */ - @Override - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeElements(out); - // No element fields. - } - - /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonBoolean} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonBoolean readJsonBoolean_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - JsonBoolean result = new JsonBoolean(); - result.readContentXml(in); - return result; - } - - @Override - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - case VALUE__XML_ATTR: { - setValue(Boolean.parseBoolean(value)); - break; - } - default: { - super.readFieldXmlAttribute(name, value); - } - } - } - - @Override - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - case VALUE__XML_ATTR: { - setValue(Boolean.parseBoolean(in.getElementText())); - break; - } - default: { - super.readFieldXmlElement(in, localName); - } - } - } - - /** Creates a new {@link JsonBoolean} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonBoolean readJsonBoolean(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - in.nextTag(); - return de.haumacher.msgbuf.json.value.JsonBoolean.readJsonBoolean_XmlContent(in); - } - } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonDouble.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonDouble.java index 4a725d2a..3ff34b70 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonDouble.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonDouble.java @@ -119,68 +119,4 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonDouble} type. */ - public static final String JSON_DOUBLE__XML_ELEMENT = "json-double"; - - /** XML attribute or element name of a {@link #getValue} property. */ - private static final String VALUE__XML_ATTR = "value"; - - @Override - public String getXmlTagName() { - return JSON_DOUBLE__XML_ELEMENT; - } - - /** Serializes all fields that are written as XML attributes. */ - @Override - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeAttributes(out); - out.writeAttribute(VALUE__XML_ATTR, Double.toString(getValue())); - } - - /** Serializes all fields that are written as XML elements. */ - @Override - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeElements(out); - // No element fields. - } - - /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonDouble} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonDouble readJsonDouble_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - JsonDouble result = new JsonDouble(); - result.readContentXml(in); - return result; - } - - @Override - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - case VALUE__XML_ATTR: { - setValue(Double.parseDouble(value)); - break; - } - default: { - super.readFieldXmlAttribute(name, value); - } - } - } - - @Override - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - case VALUE__XML_ATTR: { - setValue(Double.parseDouble(in.getElementText())); - break; - } - default: { - super.readFieldXmlElement(in, localName); - } - } - } - - /** Creates a new {@link JsonDouble} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonDouble readJsonDouble(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - in.nextTag(); - return de.haumacher.msgbuf.json.value.JsonDouble.readJsonDouble_XmlContent(in); - } - } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonLong.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonLong.java index 45bcc79a..44191be5 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonLong.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonLong.java @@ -119,68 +119,4 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonLong} type. */ - public static final String JSON_LONG__XML_ELEMENT = "json-long"; - - /** XML attribute or element name of a {@link #getValue} property. */ - private static final String VALUE__XML_ATTR = "value"; - - @Override - public String getXmlTagName() { - return JSON_LONG__XML_ELEMENT; - } - - /** Serializes all fields that are written as XML attributes. */ - @Override - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeAttributes(out); - out.writeAttribute(VALUE__XML_ATTR, Long.toString(getValue())); - } - - /** Serializes all fields that are written as XML elements. */ - @Override - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeElements(out); - // No element fields. - } - - /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonLong} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonLong readJsonLong_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - JsonLong result = new JsonLong(); - result.readContentXml(in); - return result; - } - - @Override - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - case VALUE__XML_ATTR: { - setValue(Long.parseLong(value)); - break; - } - default: { - super.readFieldXmlAttribute(name, value); - } - } - } - - @Override - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - case VALUE__XML_ATTR: { - setValue(Long.parseLong(in.getElementText())); - break; - } - default: { - super.readFieldXmlElement(in, localName); - } - } - } - - /** Creates a new {@link JsonLong} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonLong readJsonLong(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - in.nextTag(); - return de.haumacher.msgbuf.json.value.JsonLong.readJsonLong_XmlContent(in); - } - } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonNull.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonNull.java index 0aaef7b5..255dfda5 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonNull.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonNull.java @@ -64,56 +64,4 @@ public static de.haumacher.msgbuf.json.value.JsonNull readJsonNull_Content(de.ha return result; } - /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonNull} type. */ - public static final String JSON_NULL__XML_ELEMENT = "json-null"; - - @Override - public String getXmlTagName() { - return JSON_NULL__XML_ELEMENT; - } - - /** Serializes all fields that are written as XML attributes. */ - @Override - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeAttributes(out); - } - - /** Serializes all fields that are written as XML elements. */ - @Override - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeElements(out); - // No element fields. - } - - /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonNull} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonNull readJsonNull_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - JsonNull result = new JsonNull(); - result.readContentXml(in); - return result; - } - - @Override - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - default: { - super.readFieldXmlAttribute(name, value); - } - } - } - - @Override - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - default: { - super.readFieldXmlElement(in, localName); - } - } - } - - /** Creates a new {@link JsonNull} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonNull readJsonNull(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - in.nextTag(); - return de.haumacher.msgbuf.json.value.JsonNull.readJsonNull_XmlContent(in); - } - } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonObject.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonObject.java index 8ffc6757..f960fc70 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonObject.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonObject.java @@ -187,59 +187,4 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonObject} type. */ - public static final String JSON_OBJECT__XML_ELEMENT = "json-object"; - - /** XML attribute or element name of a {@link #getEntries} property. */ - private static final String ENTRIES__XML_ATTR = "entries"; - - @Override - public String getXmlTagName() { - return JSON_OBJECT__XML_ELEMENT; - } - - /** Serializes all fields that are written as XML attributes. */ - @Override - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeAttributes(out); - } - - /** Serializes all fields that are written as XML elements. */ - @Override - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeElements(out); - // No element fields. - } - - /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonObject} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonObject readJsonObject_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - JsonObject result = new JsonObject(); - result.readContentXml(in); - return result; - } - - @Override - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - default: { - super.readFieldXmlAttribute(name, value); - } - } - } - - @Override - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - default: { - super.readFieldXmlElement(in, localName); - } - } - } - - /** Creates a new {@link JsonObject} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonObject readJsonObject(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - in.nextTag(); - return de.haumacher.msgbuf.json.value.JsonObject.readJsonObject_XmlContent(in); - } - } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonString.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonString.java index ea9b83ac..6f6ab9ad 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonString.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonString.java @@ -119,68 +119,4 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonString} type. */ - public static final String JSON_STRING__XML_ELEMENT = "json-string"; - - /** XML attribute or element name of a {@link #getValue} property. */ - private static final String VALUE__XML_ATTR = "value"; - - @Override - public String getXmlTagName() { - return JSON_STRING__XML_ELEMENT; - } - - /** Serializes all fields that are written as XML attributes. */ - @Override - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeAttributes(out); - out.writeAttribute(VALUE__XML_ATTR, getValue()); - } - - /** Serializes all fields that are written as XML elements. */ - @Override - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - super.writeElements(out); - // No element fields. - } - - /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonString} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonString readJsonString_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - JsonString result = new JsonString(); - result.readContentXml(in); - return result; - } - - @Override - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - case VALUE__XML_ATTR: { - setValue(value); - break; - } - default: { - super.readFieldXmlAttribute(name, value); - } - } - } - - @Override - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - case VALUE__XML_ATTR: { - setValue(in.getElementText()); - break; - } - default: { - super.readFieldXmlElement(in, localName); - } - } - } - - /** Creates a new {@link JsonString} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonString readJsonString(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - in.nextTag(); - return de.haumacher.msgbuf.json.value.JsonString.readJsonString_XmlContent(in); - } - } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonValue.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonValue.java index adbeef15..f4645fc0 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonValue.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/JsonValue.java @@ -1,9 +1,9 @@ package de.haumacher.msgbuf.json.value; /** - * Envelope type representing any JSON value for binary and XML serialization. + * Envelope type representing any JSON value for binary serialization. */ -public abstract class JsonValue extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.xml.XmlSerializable { +public abstract class JsonValue extends de.haumacher.msgbuf.data.AbstractDataObject implements de.haumacher.msgbuf.binary.BinaryDataObject { /** Type codes for the {@link de.haumacher.msgbuf.json.value.JsonValue} hierarchy. */ public enum TypeKind { @@ -131,114 +131,4 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th } } - /** XML element name representing a {@link de.haumacher.msgbuf.json.value.JsonValue} type. */ - public static final String JSON_VALUE__XML_ELEMENT = "json-value"; - - @Override - public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - writeAttributes(out); - writeElements(out); - } - - /** Serializes all fields that are written as XML attributes. */ - protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - } - - /** Serializes all fields that are written as XML elements. */ - protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - // No element fields. - } - - /** Creates a new {@link de.haumacher.msgbuf.json.value.JsonValue} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonValue readJsonValue_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - switch (in.getLocalName()) { - case JsonString.JSON_STRING__XML_ELEMENT: { - return de.haumacher.msgbuf.json.value.JsonString.readJsonString_XmlContent(in); - } - - case JsonLong.JSON_LONG__XML_ELEMENT: { - return de.haumacher.msgbuf.json.value.JsonLong.readJsonLong_XmlContent(in); - } - - case JsonDouble.JSON_DOUBLE__XML_ELEMENT: { - return de.haumacher.msgbuf.json.value.JsonDouble.readJsonDouble_XmlContent(in); - } - - case JsonBoolean.JSON_BOOLEAN__XML_ELEMENT: { - return de.haumacher.msgbuf.json.value.JsonBoolean.readJsonBoolean_XmlContent(in); - } - - case JsonNull.JSON_NULL__XML_ELEMENT: { - return de.haumacher.msgbuf.json.value.JsonNull.readJsonNull_XmlContent(in); - } - - case JsonArray.JSON_ARRAY__XML_ELEMENT: { - return de.haumacher.msgbuf.json.value.JsonArray.readJsonArray_XmlContent(in); - } - - case JsonObject.JSON_OBJECT__XML_ELEMENT: { - return de.haumacher.msgbuf.json.value.JsonObject.readJsonObject_XmlContent(in); - } - - default: { - internalSkipUntilMatchingEndElement(in); - return null; - } - } - } - - /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { - String name = in.getAttributeLocalName(n); - String value = in.getAttributeValue(n); - - readFieldXmlAttribute(name, value); - } - while (true) { - int event = in.nextTag(); - if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { - break; - } - assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; - - String localName = in.getLocalName(); - readFieldXmlElement(in, localName); - } - } - - /** Parses the given attribute value and assigns it to the field with the given name. */ - protected void readFieldXmlAttribute(String name, String value) { - switch (name) { - default: { - // Skip unknown attribute. - } - } - } - - /** Reads the element under the cursor and assigns its contents to the field with the given name. */ - protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { - switch (localName) { - default: { - internalSkipUntilMatchingEndElement(in); - } - } - } - - protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - int level = 0; - while (true) { - switch (in.next()) { - case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; - case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } - } - } - } - - /** Creates a new {@link JsonValue} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ - public static JsonValue readJsonValue(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - in.nextTag(); - return de.haumacher.msgbuf.json.value.JsonValue.readJsonValue_XmlContent(in); - } - } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/jsonvalue.proto b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/jsonvalue.proto index 3e8d9dd2..55d92154 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/jsonvalue.proto +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/json/value/jsonvalue.proto @@ -1,11 +1,22 @@ package de.haumacher.msgbuf.json.value; option NoInterfaces; +option NoXml; option NoReflection; option NoListener; option NoVisitor; -/** Envelope type representing any JSON value for binary and XML serialization. */ +/** + * Envelope type representing any JSON value for binary serialization. + * + *

+ * Note: XML serialization is intentionally disabled (NoXml) because these classes are part of the + * msgbuf-api runtime library, which must be GWT-compatible. XML serialization would pull in + * {@code javax.xml.stream.*} (StAX API), which is not available in GWT environments. When JSON + * fields are serialized over XML, they are encoded as JSON text strings instead (see + * {@code XmlStreamingPlugin} in the generator). + *

+ */ abstract message JsonValue { } From f1a69403185b2e1695d525bcb63b6e48a635d29b Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Thu, 26 Mar 2026 08:58:20 +0100 Subject: [PATCH 176/207] chore: add Claude Code sandbox settings for Maven builds Allow writing to ~/.m2/repository and network access to Maven Central and Nexus repository for builds within the Claude Code sandbox. Co-Authored-By: Claude Opus 4.6 (1M context) --- .claude/settings.json | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .claude/settings.json diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 00000000..1f372d4e --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,21 @@ +{ + "permissions": { + "allow": [ + "Bash(mvn *)" + ], + "deny": [] + }, + "sandbox": { + "filesystem": { + "allowWrite": [ + "~/.m2/repository" + ] + }, + "network": { + "allowedHosts": [ + "repo.maven.apache.org", + "dev.top-logic.com" + ] + } + } +} From bfd9e612770b55fea0bc980efa09b1eec0d4909e Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Thu, 26 Mar 2026 08:58:59 +0100 Subject: [PATCH 177/207] docs: add changelog entry for 1.2.1 GWT compatibility fix Co-Authored-By: Claude Opus 4.6 (1M context) --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a35f173b..45695664 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 1.2.1 + +### Bug Fixes +- **GWT compatibility for `json` field type**: Remove XML serialization (`javax.xml.stream.*`) from `JsonValue` envelope classes in `msgbuf-api`, which broke GWT compilation. JSON fields in XML format are serialized as JSON text strings instead. + ## 1.2.0 ### New Features From 5cfbc14a7b2cbb2beacd5a99e12a20ea18df9151 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Thu, 26 Mar 2026 08:59:58 +0100 Subject: [PATCH 178/207] [maven-release-plugin] prepare release msgbuf-api-1.2.1 --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 21ec4c97..f0d72efc 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.1-SNAPSHOT + 1.2.1 msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.2.1-SNAPSHOT + 1.2.1 diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index b0be8d07..a4ce11a7 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.1-SNAPSHOT + 1.2.1 msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index ce7afb21..f1097d15 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.1-SNAPSHOT + 1.2.1 msgbuf-generator-maven-plugin @@ -33,7 +33,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.2.1-SNAPSHOT + 1.2.1 diff --git a/pom.xml b/pom.xml index 577ea76c..a785b697 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.1-SNAPSHOT + 1.2.1 pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - HEAD + msgbuf-api-1.2.1 From 47a4771589c3b3dca1c91a6ff627e4232a7b16ac Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Thu, 26 Mar 2026 09:00:00 +0100 Subject: [PATCH 179/207] [maven-release-plugin] prepare for next development iteration --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index f0d72efc..d045876a 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.1 + 1.2.2-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.2.1 + 1.2.2-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index a4ce11a7..5e535668 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.1 + 1.2.2-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index f1097d15..bd722cce 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.1 + 1.2.2-SNAPSHOT msgbuf-generator-maven-plugin @@ -33,7 +33,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.2.1 + 1.2.2-SNAPSHOT diff --git a/pom.xml b/pom.xml index a785b697..c0526012 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.1 + 1.2.2-SNAPSHOT pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - msgbuf-api-1.2.1 + HEAD From 4ad59191fc1273e943098891e9fca8774aeff920 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Thu, 26 Mar 2026 09:04:30 +0100 Subject: [PATCH 180/207] Updated readme for 1.2.1. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f404620e..296fc6b0 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ In contrast to `protobuf`, `msgbuf` supports: de.haumacher.msgbuf msgbuf-api - 1.2.0 + 1.2.1 ``` @@ -32,7 +32,7 @@ To the `build/plugins` section add: de.haumacher.msgbuf msgbuf-generator-maven-plugin - 1.2.0 + 1.2.1 From 216434ec60454fd6773daddafacfa3155598deef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20H=C3=BCsing?= Date: Thu, 21 May 2026 12:06:40 +0200 Subject: [PATCH 181/207] fix: add GWT super-source for TypeRegistryLoader TypeRegistryLoader uses java.util.ServiceLoader which is not available in GWT's JRE emulation. This causes GWT compilation to fail for any project inheriting the MsgBuf GWT module. Provide a no-op super-source replacement so that GWT compilation succeeds. On GWT, type registration must happen via explicit init() calls on generated registration classes. --- .../de/haumacher/msgbuf/MsgBuf.gwt.xml | 4 ++++ .../msgbuf/data/TypeRegistryLoader.java | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 de.haumacher.msgbuf/src/main/resources/de/haumacher/msgbuf/super/de/haumacher/msgbuf/data/TypeRegistryLoader.java diff --git a/de.haumacher.msgbuf/src/main/resources/de/haumacher/msgbuf/MsgBuf.gwt.xml b/de.haumacher.msgbuf/src/main/resources/de/haumacher/msgbuf/MsgBuf.gwt.xml index e9d4478e..195eef58 100644 --- a/de.haumacher.msgbuf/src/main/resources/de/haumacher/msgbuf/MsgBuf.gwt.xml +++ b/de.haumacher.msgbuf/src/main/resources/de/haumacher/msgbuf/MsgBuf.gwt.xml @@ -7,6 +7,10 @@ "../../../dtd/gwt-module-2.9.0.dtd"> + + + diff --git a/de.haumacher.msgbuf/src/main/resources/de/haumacher/msgbuf/super/de/haumacher/msgbuf/data/TypeRegistryLoader.java b/de.haumacher.msgbuf/src/main/resources/de/haumacher/msgbuf/super/de/haumacher/msgbuf/data/TypeRegistryLoader.java new file mode 100644 index 00000000..5dc55ed0 --- /dev/null +++ b/de.haumacher.msgbuf/src/main/resources/de/haumacher/msgbuf/super/de/haumacher/msgbuf/data/TypeRegistryLoader.java @@ -0,0 +1,21 @@ +package de.haumacher.msgbuf.data; + +/** + * GWT super-source replacement for {@code TypeRegistryLoader}. + * + *

+ * The original uses {@link java.util.ServiceLoader} which is not available in GWT. + * In GWT, registration happens via explicit {@code init()} calls on generated + * registration classes. + *

+ */ +public class TypeRegistryLoader { + + /** + * No-op in GWT. Registration must happen via explicit init() calls. + */ + public static void ensureLoaded() { + // No ServiceLoader available in GWT. + } + +} From 2c1c5478889644d148b2a387c00b16ad1ff843ee Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Thu, 21 May 2026 15:38:35 +0200 Subject: [PATCH 182/207] Removed invalid key. --- pom.xml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index c0526012..ffb2a143 100644 --- a/pom.xml +++ b/pom.xml @@ -90,9 +90,6 @@ org.apache.maven.plugins maven-gpg-plugin 1.5 - - 401FE46033F5589B53443B0CBD126C2FB1395E37 - sign-artifacts @@ -156,4 +153,4 @@ - \ No newline at end of file + From 9e52e75ca34b6e8589ebdc4ca7cddf3a75f49f18 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Thu, 21 May 2026 16:07:38 +0200 Subject: [PATCH 183/207] [maven-release-plugin] prepare release msgbuf-api-1.2.2 --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index d045876a..dd6a980a 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.2-SNAPSHOT + 1.2.2 msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.2.2-SNAPSHOT + 1.2.2 diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 5e535668..514ad634 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.2-SNAPSHOT + 1.2.2 msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index bd722cce..a6024df5 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.2-SNAPSHOT + 1.2.2 msgbuf-generator-maven-plugin @@ -33,7 +33,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.2.2-SNAPSHOT + 1.2.2 diff --git a/pom.xml b/pom.xml index ffb2a143..953237db 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.2-SNAPSHOT + 1.2.2 pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - HEAD + msgbuf-api-1.2.2 From a4735da79cb8251264c062dbb4faa1f04ee9f145 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Thu, 21 May 2026 16:07:41 +0200 Subject: [PATCH 184/207] [maven-release-plugin] prepare for next development iteration --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index dd6a980a..059fc0bb 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.2 + 1.2.3-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.2.2 + 1.2.3-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 514ad634..75f89722 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.2 + 1.2.3-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index a6024df5..22bbe1fc 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.2 + 1.2.3-SNAPSHOT msgbuf-generator-maven-plugin @@ -33,7 +33,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.2.2 + 1.2.3-SNAPSHOT diff --git a/pom.xml b/pom.xml index 953237db..4e70850f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.2 + 1.2.3-SNAPSHOT pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - msgbuf-api-1.2.2 + HEAD From 73a85a19f063261e0fd957596b73d1abea2c6212 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 13:44:04 +0200 Subject: [PATCH 185/207] Sign artifacts only in the ossrh release profile. GPG signing ran in every build's verify phase, so a local install failed on machines without a signing key. The maven-release-plugin already activates the ossrh profile (releaseProfiles) during release:perform, so a release still signs; a manual deployment uses -Possrh. Co-Authored-By: Claude Opus 5.5 --- HOWTO-RELEASE.md | 11 +++++++++++ pom.xml | 45 +++++++++++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/HOWTO-RELEASE.md b/HOWTO-RELEASE.md index 95cdcbcc..060c13d9 100644 --- a/HOWTO-RELEASE.md +++ b/HOWTO-RELEASE.md @@ -11,3 +11,14 @@ mvn release:clean release:prepare ``` mvn release:perform ``` + + +## Signing + +Artifacts are GPG signed only in the `ossrh` profile. `release:perform` activates it automatically (see +`releaseProfiles` of the `maven-release-plugin`), so a regular `mvn install` does not require a GPG key. +For a manual deployment to Maven Central, activate the profile explicitly: + +``` +mvn deploy -Possrh +``` diff --git a/pom.xml b/pom.xml index 4e70850f..385d0512 100644 --- a/pom.xml +++ b/pom.xml @@ -85,22 +85,6 @@
- - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - verify - - sign - - - - - org.apache.maven.plugins maven-release-plugin @@ -153,4 +137,33 @@ + + + + + ossrh + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + + + + From b53d2652607a27c32c168d1aa7e84d9350386ed1 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 13:44:04 +0200 Subject: [PATCH 186/207] Add a types-only TypeScript target (#10). Generates one TypeScript module per .proto file that describes its JSON format: interfaces for messages, string-literal unions for enums (honouring @Name), type-tagged tuple unions for polymorphic values, and namespaces for nested types. Property names are the JSON names of the Java *__PROP constants. Doc comments are translated to TSDoc ({@link #field} -> {@link Owner.field}, {@code x} -> `x`); a doc comment before syntax/package becomes the module documentation (DefinitionFile.comment). Enabled with the Maven plugin parameter typeScriptOutputDirectory, the CLI argument -ts , or per file with option TypeScript = "path.ts". Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 10 + CLAUDE.md | 1 + README.md | 83 +++ .../haumacher/msgbuf/generator/Generator.java | 114 ++- .../haumacher/msgbuf/generator/NameTable.java | 18 +- .../msgbuf/generator/ast/DefinitionFile.java | 33 + .../msgbuf/generator/ast/proto.proto | 3 + .../msgbuf/generator/common/DocTags.java | 87 +++ .../generator/parser/ProtobufParser.java | 9 +- .../msgbuf/generator/parser/protobuf.jj | 15 +- .../generator/ts/TypeScriptGenerator.java | 681 ++++++++++++++++++ .../util/AbstractTypeScriptGenerator.java | 22 + .../generator/ts/TestTypeScriptGenerator.java | 113 +++ .../ts/expected/custom/explicit-types.ts | 20 + .../ts/expected/test/ts/common/common.ts | 78 ++ .../ts/expected/test/ts/shapes/shapes.ts | 242 +++++++ .../ts/proto/test/ts/common/common.proto | 50 ++ .../ts/proto/test/ts/explicit/explicit.proto | 16 + .../ts/proto/test/ts/shapes/shapes.proto | 160 ++++ .../maven/GenerateMessageClasses.java | 16 + 20 files changed, 1765 insertions(+), 6 deletions(-) create mode 100644 de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/DocTags.java create mode 100644 de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java create mode 100644 de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/util/AbstractTypeScriptGenerator.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/de/haumacher/msgbuf/generator/ts/TestTypeScriptGenerator.java create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/ts/expected/custom/explicit-types.ts create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/common/common.ts create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/shapes/shapes.ts create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/common/common.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/explicit/explicit.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/shapes/shapes.proto diff --git a/CHANGELOG.md b/CHANGELOG.md index 45695664..0969f6ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 1.2.3 + +### New Features +- **TypeScript type definitions**: Generate a types-only TypeScript module per `.proto` file describing its JSON + format (interfaces for messages, string-literal unions for enums, type-tagged tuple unions for polymorphic values). + Enabled for all files with the Maven plugin parameter `typeScriptOutputDirectory` or the `-ts ` CLI argument, + or per file with `option TypeScript = "path/to/module.ts";`. +- **File documentation comment**: A doc comment before the `syntax` or `package` declaration is kept as the documentation + of the `.proto` file (`DefinitionFile.comment`) and emitted as TSDoc `@packageDocumentation` of the TypeScript module. + ## 1.2.1 ### Bug Fixes diff --git a/CLAUDE.md b/CLAUDE.md index 5ec1a5f1..f5276c1b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -52,6 +52,7 @@ The code generation follows a 4-stage pipeline in `Generator.main()`: Key source locations: - Generator entry point: `de.haumacher.msgbuf.generator.Generator` - Code generators: `de.haumacher.msgbuf.generator.MessageGenerator`, `EnumGenerator` +- Other targets: Dart (`generator.dart.DartLibGenerator`, `option DartLib`), TypeScript types (`generator.ts.TypeScriptGenerator`, `-ts ` / Maven `typeScriptOutputDirectory` / `option TypeScript`; golden-file test `TestTypeScriptGenerator`, update expected files with `-Dmsgbuf.ts.update=true`) - JavaCC grammar: `de.haumacher.msgbuf.generator/src/main/javacc/protobuf.jj` - AST proto definition: `de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto` diff --git a/README.md b/README.md index 296fc6b0..3c30ef4b 100644 --- a/README.md +++ b/README.md @@ -444,6 +444,89 @@ message MyMessage { } ``` +### TypeScript type definitions + +The generator can create a TypeScript module with type definitions for the JSON format of each `.proto` file. The +modules contain types only (no readers, writers or other runtime code) and let a TypeScript client share the protocol +contract with the Java side. + +TypeScript output is enabled in one of the following ways: + +* **Output directory for all files**: Set the Maven plugin parameter `typeScriptOutputDirectory` (user property + `typeScriptOutputDir`), or pass `-ts ` on the command line. A module is generated for each `.proto` file. + The module for a file `name.proto` with `package a.b.c;` is written to `a/b/c/name.ts` within that directory. +* **Per file**: `option TypeScript = "path/to/module.ts";` in a `.proto` file. The path is relative to the generator + output directory (like `option DartLib`) and takes precedence over the output directory. + +```xml + + de.haumacher.msgbuf + msgbuf-generator-maven-plugin + ... + + ${project.basedir}/src/main/ts/protocol + + ... + +``` + +Mapping of protocol definitions: + +| Protocol definition | TypeScript | +|---|---| +| `message M { ... }` | `export interface M { ... }` with the JSON property names of the fields (`@Name` is honored) | +| `message M extends B` | `export interface M extends B` | +| `abstract message A` | `export interface A`, plus `export type AnyA = ['TypeIdOfC1', C1] \| ...` if the hierarchy root is abstract (see below) | +| `enum E { ... }` | `export type E = 'A' \| 'B';` with the protocol names of the constants (`@Name` is honored) | +| `string`, `bytes` | `string` (bytes are Base64 encoded) | +| `bool` | `boolean` | +| `int32`, `int64`, `float`, `double`, ... | `number` | +| `json` | `unknown` | +| `repeated T` | `T[]` | +| `map` | `Record` | +| `map` (other key types) | `Array<{ key: K; value: V }>` | +| Nested definitions | Declarations in a namespace named after the outer message, e.g. `Outer.Inner` | +| Types from imported `.proto` files | `import type { ... } from '';` | + +Details: + +* **Optional properties**: All properties are optional (`name?: T`). The JSON reader accepts any subset of properties + and uses the field's default value for a missing one. Fields that are unset and nullable (`@Nullable`, references + to messages) are omitted from the JSON output instead of being written as `null`. Explicit default values of fields + are documented with a `@defaultValue` tag. +* **Enum values**: An enum constant is written as its name exactly as spelled in the `.proto` file (e.g. `ICON_ONLY`), + unless a custom name is given with `@Name`: + + ```protobuf + enum DisplayMode { + @Name("icon-only") + ICON_ONLY; + @Name("label-only") + LABEL_ONLY; + } + ``` + + generates `export type DisplayMode = | 'icon-only' | 'label-only';`. +* **Polymorphism**: A value of an abstract message type in a hierarchy with an abstract root is written as a tuple + of its type ID and its properties, `["Circle", {"r": 5}]` (see [Polymorphic JSON serialization](#polymorphic-json-serialization)). + For each such abstract message `A`, a union type `AnyA` of the tuples of all known concrete specializations is + generated and used as type of fields referencing `A`. For `option OpenWorld` hierarchies, the union additionally + contains `[string, A]` for extension types from other modules. References to concrete messages (and all messages + in a hierarchy with a concrete root) are written without type information and use the interface directly. +* **Documentation**: Doc comments become TSDoc comments. JavaDoc inline tags are translated: `{@code x}` becomes + `` `x` ``, `{@link Type}`, `{@link #field}` and `{@link Type#field label}` become links to the TypeScript type or + property (`{@link Type.prop label}`, using the JSON property name), a link to an enum constant becomes its protocol + name in back ticks, and an unresolvable link becomes its label or the target in back ticks. The doc comment + (`/** ... */`) before the `syntax` or `package` declaration of a `.proto` file becomes the module's + `@packageDocumentation` comment. +* **Module paths**: Imports use relative module specifiers without file extension (e.g. `'../common/common'`), as + resolved by bundlers and `moduleResolution: "bundler"`. An imported `.proto` file is expected to have its module + at the location the same generator configuration would produce for it (its `option TypeScript`, or its package + path within the TypeScript output directory). +* **Limitations**: The JSON format of `option SharedGraph` protocols (objects as `[type, id, {...}]`, references as + IDs, incremental updates) is not described by the generated types. A generated `AnyA` union type may clash with a + message of the same name. + ## Installation in Eclipse There is an Eclipse plugin providing a project builder that automatically generates corresponding Java files whenever you create or modify a `*.proto` definition file. To install and enable the plugin with the following steps: diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java index b8dde37b..bac207a2 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java @@ -14,6 +14,7 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -40,6 +41,7 @@ import de.haumacher.msgbuf.generator.parser.ProtobufParser; import de.haumacher.msgbuf.generator.parser.ProtobufParserConstants; import de.haumacher.msgbuf.generator.parser.Token; +import de.haumacher.msgbuf.generator.ts.TypeScriptGenerator; import de.haumacher.msgbuf.generator.util.FileGenerator; /** @@ -57,9 +59,37 @@ public class Generator { */ public static final String RESOURCE_DIR_ARG = "-resources"; + /** + * Argument giving the output directory for TypeScript type definitions. + * + *

+ * If given, a TypeScript module is generated for each .proto file, see + * {@link #setTypeScriptOut(File)}. + *

+ */ + public static final String TYPESCRIPT_DIR_ARG = "-ts"; + + /** + * File option giving the location of the TypeScript module to generate for a + * .proto file (relative to the output directory). + */ + public static final String TYPESCRIPT_OPTION = "TypeScript"; + + /** + * File extension of generated TypeScript modules. + */ + private static final String TS_EXTENSION = ".ts"; + + /** + * Module name for a .proto file whose file name is unknown. + */ + private static final String DEFAULT_MODULE_NAME = "index"; + private NameTable _table = new NameTable(); private File _out = new File("."); private File _resourceOut; + private File _tsOut; + private Map _sourceNames = new HashMap<>(); private List _files = new ArrayList<>(); private List _includePaths = new ArrayList<>(); private ClassLoader _importClassLoader; @@ -74,6 +104,20 @@ public void setResourceOut(File resourceOut) { _resourceOut = resourceOut; } + /** + * Sets the root directory for TypeScript type definitions. + * + *

+ * If set, a TypeScript module with type definitions for the JSON format is generated for each + * .proto file. The module for a file name.proto with + * package a.b.c; is written to a/b/c/name.ts within the given + * directory. + *

+ */ + public void setTypeScriptOut(File tsOut) { + _tsOut = tsOut; + } + public void addIncludePath(File path) { _includePaths.add(path); } @@ -97,6 +141,7 @@ public DefinitionFile load(File file) try (InputStream in = new FileInputStream(file)) { content = load(parse(in)); } + _sourceNames.put(content, file.getName()); resolveImports(content, file); return content; } @@ -167,6 +212,12 @@ public void generate(GeneratorPlugin plugin) { if (dartLib != null) { new DartLibGenerator(new File(_out, ((StringOption) dartLib).getValue()), file).run(); } + + if (_tsOut != null || file.getOptions().get(TYPESCRIPT_OPTION) != null) { + File tsFile = typeScriptModule(file); + new TypeScriptGenerator(tsFile, file, sourceDescription(file), + other -> moduleSpecifier(tsFile, typeScriptModule(other)), _table).run(); + } } // Generate registration classes and service loader descriptors for extension modules @@ -186,6 +237,62 @@ public void generate(GeneratorPlugin plugin) { } } + /** + * The TypeScript module file for the given definitions. + * + *

+ * An explicit {@link #TYPESCRIPT_OPTION} is resolved against the output directory. Otherwise, + * the module is placed in the directory of the file's package (within the TypeScript output + * directory, or the output directory, if none is set) and named after the .proto + * file. + *

+ */ + private File typeScriptModule(DefinitionFile file) { + Option explicit = file.getOptions().get(TYPESCRIPT_OPTION); + if (explicit != null) { + return new File(_out, ((StringOption) explicit).getValue()).toPath().normalize().toFile(); + } + File result = _tsOut != null ? _tsOut : _out; + if (file.getPackage() != null) { + for (String name : file.getPackage().getNames()) { + result = new File(result, name); + } + } + return new File(result, moduleName(file) + TS_EXTENSION); + } + + private String moduleName(DefinitionFile file) { + String sourceName = _sourceNames.get(file); + if (sourceName == null) { + return DEFAULT_MODULE_NAME; + } + int dot = sourceName.lastIndexOf('.'); + return dot > 0 ? sourceName.substring(0, dot) : sourceName; + } + + private String sourceDescription(DefinitionFile file) { + String sourceName = _sourceNames.get(file); + if (file.getPackage() == null) { + return sourceName == null ? "" : sourceName; + } + String packagePath = String.join("/", file.getPackage().getNames()); + return sourceName == null ? packagePath : packagePath + "/" + sourceName; + } + + /** + * The relative module specifier (without file extension) to reference the given target module + * from the given module. + */ + private static String moduleSpecifier(File from, File to) { + java.nio.file.Path fromDir = from.getAbsoluteFile().toPath().normalize().getParent(); + java.nio.file.Path target = to.getAbsoluteFile().toPath().normalize(); + String relative = fromDir.relativize(target).toString().replace(File.separatorChar, '/'); + if (relative.endsWith(TS_EXTENSION)) { + relative = relative.substring(0, relative.length() - TS_EXTENSION.length()); + } + return relative.startsWith("../") ? relative : "./" + relative; + } + private void validateOpenWorld(DefinitionFile file) { boolean openWorld = Util.getFlag(file, "OpenWorld"); if (!openWorld) { @@ -232,6 +339,7 @@ private void resolveImports(DefinitionFile file, File sourceFile) throws IOExcep try (InputStream in = new FileInputStream(resolved)) { imported = parse(in); } + _sourceNames.put(imported, resolved.getName()); _files.add(imported); _table.enter(imported); _importedFiles.add(imported); @@ -252,6 +360,7 @@ private void resolveImports(DefinitionFile file, File sourceFile) throws IOExcep try (InputStream in = classpathStream) { imported = parse(in); } + _sourceNames.put(imported, new File(importPath).getName()); _files.add(imported); _table.enter(imported); _importedFiles.add(imported); @@ -280,6 +389,7 @@ private void resolveImportsFromClasspath(DefinitionFile file) throws IOException try (InputStream in = classpathStream) { imported = parse(in); } + _sourceNames.put(imported, new File(importPath).getName()); _files.add(imported); _table.enter(imported); _importedFiles.add(imported); @@ -565,6 +675,8 @@ public static void main(String... args) throws ParseException, IOException, Inst out = new File(args[n++]); } else if (arg.equals(RESOURCE_DIR_ARG)) { generator.setResourceOut(new File(args[n++])); + } else if (arg.equals(TYPESCRIPT_DIR_ARG)) { + generator.setTypeScriptOut(new File(args[n++])); } else if (arg.equals("-h")) { printHelp(); return; @@ -606,7 +718,7 @@ public static GeneratorPlugin loadPlugins() { } private static void printHelp() { - System.err.println("Usage: java -jar " + Generator.class.getName() + " -out *"); + System.err.println("Usage: java -jar " + Generator.class.getName() + " -out [-resources ] [-ts ] [-I ]* [-cp ] *"); } private static File findBase(File protoFile, DefinitionFile content) { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java index 2aea25a0..0b74a64c 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java @@ -117,6 +117,23 @@ public void error(String message) { * TODO */ public Definition lookup(MessageDef context, QName name) { + Definition result = resolve(context, name); + if (result == null) { + error("Name cannot be resolved" + (context == null ? "" : " in '" + context.getName() + "'") + ": " + CodeConvention.qTypeName(name)); + } + return result; + } + + /** + * Resolves the given name in the given context without reporting an error. + * + * @param context + * The message in which the name is used, null for top-level usage. + * @param name + * The name to resolve. + * @return The resolved definition, or null if the name cannot be resolved. + */ + public Definition resolve(MessageDef context, QName name) { String baseName = name.getNames().get(0); Definition base = lookupBase(context, baseName); @@ -158,7 +175,6 @@ public Definition lookup(MessageDef context, QName name) { } } - error("Name cannot be resolved" + (context == null ? "" : " in '" + context.getName() + "'") + ": " + CodeConvention.qTypeName(name)); return null; } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java index 1b6894dd..7e65b900 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/DefinitionFile.java @@ -17,6 +17,9 @@ public static de.haumacher.msgbuf.generator.ast.DefinitionFile create() { /** Identifier for the {@link de.haumacher.msgbuf.generator.ast.DefinitionFile} type in JSON format. */ public static final String DEFINITION_FILE__TYPE = "DefinitionFile"; + /** @see #getComment() */ + public static final String COMMENT__PROP = "comment"; + /** @see #getPackage() */ public static final String PACKAGE__PROP = "package"; @@ -26,6 +29,8 @@ public static de.haumacher.msgbuf.generator.ast.DefinitionFile create() { /** @see #getDefinitions() */ public static final String DEFINITIONS__PROP = "definitions"; + private String _comment = ""; + private de.haumacher.msgbuf.generator.ast.QName _package = null; private final java.util.List _imports = new de.haumacher.msgbuf.util.ReferenceList() { @@ -76,6 +81,28 @@ public TypeKind kind() { return TypeKind.DEFINITION_FILE; } + /** + * The documentation comment of the file (the doc comment before the syntax or package declaration). + */ + public final String getComment() { + return _comment; + } + + /** + * @see #getComment() + */ + public de.haumacher.msgbuf.generator.ast.DefinitionFile setComment(String value) { + internalSetComment(value); + return this; + } + + /** Internal setter for {@link #getComment()} without chain call utility. */ + protected final void internalSetComment(String value) { + _listener.beforeSet(this, COMMENT__PROP, value); + _comment = value; + _listener.afterChanged(this, COMMENT__PROP); + } + /** * The package name for all types in this file. */ @@ -209,6 +236,7 @@ public String jsonType() { static final java.util.List PROPERTIES; static { java.util.List local = java.util.Arrays.asList( + COMMENT__PROP, PACKAGE__PROP, IMPORTS__PROP, DEFINITIONS__PROP); @@ -241,6 +269,7 @@ public java.util.Set transientProperties() { @Override public Object get(String field) { switch (field) { + case COMMENT__PROP: return getComment(); case PACKAGE__PROP: return getPackage(); case IMPORTS__PROP: return getImports(); case DEFINITIONS__PROP: return getDefinitions(); @@ -251,6 +280,7 @@ public Object get(String field) { @Override public void set(String field, Object value) { switch (field) { + case COMMENT__PROP: internalSetComment((String) value); break; case PACKAGE__PROP: internalSetPackage((de.haumacher.msgbuf.generator.ast.QName) value); break; case IMPORTS__PROP: internalSetImports(de.haumacher.msgbuf.util.Conversions.asList(String.class, value)); break; case DEFINITIONS__PROP: internalSetDefinitions(de.haumacher.msgbuf.util.Conversions.asList(de.haumacher.msgbuf.generator.ast.Definition.class, value)); break; @@ -268,6 +298,8 @@ public static de.haumacher.msgbuf.generator.ast.DefinitionFile readDefinitionFil @Override protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { super.writeFields(out); + out.name(COMMENT__PROP); + out.value(getComment()); if (hasPackage()) { out.name(PACKAGE__PROP); getPackage().writeTo(out); @@ -289,6 +321,7 @@ protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java. @Override protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { switch (field) { + case COMMENT__PROP: setComment(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; case PACKAGE__PROP: setPackage(de.haumacher.msgbuf.generator.ast.QName.readQName(in)); break; case IMPORTS__PROP: { java.util.List newValue = new java.util.ArrayList<>(); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto index c4c5d3d8..79982609 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto @@ -51,6 +51,9 @@ message Constant extends Part { * @see #definitions */ message DefinitionFile extends WithOptions { + /** The documentation comment of the file (the doc comment before the syntax or package declaration). */ + string comment; + /** The package name for all types in this file. */ QName `package`; diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/DocTags.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/DocTags.java new file mode 100644 index 00000000..1e8b1d96 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/DocTags.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2026 Bernhard Haumacher et al. All Rights Reserved. + */ +package de.haumacher.msgbuf.generator.common; + +/** + * Utility for processing JavaDoc-style inline tags ({@literal {@tag content}}) in + * documentation comments of protocol definitions. + */ +public class DocTags { + + /** + * Callback computing the replacement of an inline tag. + */ + public interface TagReplacement { + + /** + * Computes the replacement text for an inline tag. + * + * @param tag + * The tag name without @, e.g. link. + * @param content + * The text after the tag name, with surrounding white space removed. + * @return The replacement text, or null to keep the tag unchanged. + */ + String replace(String tag, String content); + } + + /** + * Replaces all inline tags in the given comment. + * + *

+ * Braces within the tag content are matched, so {@literal {@code {a: 1}}} is a + * single tag. An unterminated tag is kept unchanged. + *

+ */ + public static String replaceInlineTags(String comment, TagReplacement replacement) { + if (comment == null || comment.indexOf("{@") < 0) { + return comment; + } + StringBuilder result = new StringBuilder(); + int pos = 0; + int length = comment.length(); + while (pos < length) { + int start = comment.indexOf("{@", pos); + if (start < 0) { + break; + } + int end = closingBrace(comment, start); + if (end < 0) { + break; + } + result.append(comment, pos, start); + + int nameStart = start + 2; + int nameEnd = nameStart; + while (nameEnd < end && Character.isLetterOrDigit(comment.charAt(nameEnd))) { + nameEnd++; + } + String tag = comment.substring(nameStart, nameEnd); + String content = comment.substring(nameEnd, end).trim(); + String replaced = tag.isEmpty() ? null : replacement.replace(tag, content); + result.append(replaced == null ? comment.substring(start, end + 1) : replaced); + + pos = end + 1; + } + result.append(comment, pos, length); + return result.toString(); + } + + private static int closingBrace(String comment, int start) { + int depth = 0; + for (int n = start, cnt = comment.length(); n < cnt; n++) { + char ch = comment.charAt(n); + if (ch == '{') { + depth++; + } else if (ch == '}') { + depth--; + if (depth == 0) { + return n; + } + } + } + return -1; + } + +} diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParser.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParser.java index 34bd1245..df08f344 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParser.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/ProtobufParser.java @@ -13,12 +13,14 @@ public class ProtobufParser implements ProtobufParserConstants { final public DefinitionFile file() throws ParseException {DefinitionFile result = DefinitionFile.create(); QName pkgName; Definition def; + Token t; switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case SYNTAX:{ - jj_consume_token(SYNTAX); + t = jj_consume_token(SYNTAX); jj_consume_token(37); jj_consume_token(STRING); jj_consume_token(38); +result.setComment(Util.stripComment(t)); break; } default: @@ -27,7 +29,10 @@ public class ProtobufParser implements ProtobufParserConstants { } switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { case PACKAGE:{ - jj_consume_token(PACKAGE); + t = jj_consume_token(PACKAGE); +if (result.getComment().isEmpty()) { + result.setComment(Util.stripComment(t)); + } pkgName = qName(); jj_consume_token(38); result.setPackage(pkgName); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/protobuf.jj b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/protobuf.jj index 4600451e..644d89b2 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/protobuf.jj +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/protobuf.jj @@ -96,13 +96,24 @@ DefinitionFile file() : DefinitionFile result = DefinitionFile.create(); QName pkgName; Definition def; + Token t; } { - ( < SYNTAX > "=" < STRING > ";" + ( + t=< SYNTAX > "=" < STRING > ";" + { + result.setComment(Util.stripComment(t)); + } )? ( - < PACKAGE > pkgName = qName() ";" + t=< PACKAGE > + { + if (result.getComment().isEmpty()) { + result.setComment(Util.stripComment(t)); + } + } + pkgName = qName() ";" { result.setPackage(pkgName); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java new file mode 100644 index 00000000..fb13a754 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java @@ -0,0 +1,681 @@ +/* + * Copyright (c) 2026 Bernhard Haumacher et al. All Rights Reserved. + */ +package de.haumacher.msgbuf.generator.ts; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOError; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.regex.Pattern; + +import de.haumacher.msgbuf.generator.NameTable; +import de.haumacher.msgbuf.generator.ast.Constant; +import de.haumacher.msgbuf.generator.ast.CustomType; +import de.haumacher.msgbuf.generator.ast.Definition; +import de.haumacher.msgbuf.generator.ast.DefinitionFile; +import de.haumacher.msgbuf.generator.ast.EnumDef; +import de.haumacher.msgbuf.generator.ast.Field; +import de.haumacher.msgbuf.generator.ast.MapType; +import de.haumacher.msgbuf.generator.ast.MessageDef; +import de.haumacher.msgbuf.generator.ast.PrimitiveType; +import de.haumacher.msgbuf.generator.ast.QName; +import de.haumacher.msgbuf.generator.ast.Type; +import de.haumacher.msgbuf.generator.common.DocTags; +import de.haumacher.msgbuf.generator.common.MsgBufJsonProtocol; +import de.haumacher.msgbuf.generator.common.Util; +import de.haumacher.msgbuf.generator.util.AbstractTypeScriptGenerator; + +/** + * Generator for a TypeScript module with type definitions describing the msgbuf JSON + * format of all messages and enums of a .proto file. + * + *

+ * The module contains types only (no runtime code): + *

+ *
    + *
  • A message becomes an interface whose properties are named with the JSON + * property names of the message's fields. All properties are optional, since the msgbuf + * JSON reader accepts any subset of properties and uses the field default for a missing one.
  • + *
  • A message that inherits from another message extends the interface of its + * generalization.
  • + *
  • An abstract message in a hierarchy with an abstract root is serialized polymorphically as + * [typeId, {...}]. For such message, an additional union type + * Any<Name> of type-tagged tuples of all known concrete specializations is + * generated and used for fields referencing the abstract message.
  • + *
  • An enum becomes a union of string literal types with the protocol names of its constants.
  • + *
  • Nested definitions are placed in a namespace named after the outer message.
  • + *
  • Types from other .proto files are imported with import type.
  • + *
+ */ +public class TypeScriptGenerator extends AbstractTypeScriptGenerator { + + /** + * Prefix of the name of the union type describing polymorphic values of an abstract message. + */ + public static final String POLYMORPHIC_PREFIX = "Any"; + + private static final Pattern IDENTIFIER = Pattern.compile("[A-Za-z_$][A-Za-z0-9_$]*"); + + private final File _file; + + private final DefinitionFile _proto; + + private final String _source; + + private final Function _moduleSpecifier; + + private final NameTable _table; + + /** + * Local names bound per imported file (by top-level name in that file). + */ + private final Map> _imports = new LinkedHashMap<>(); + + /** + * All names bound at the top level of the generated module. + */ + private final Set _topLevelNames = new HashSet<>(); + + /** + * Top-level aliases for references that are shadowed by nested declarations, alias name to + * referenced type. + */ + private final Map _aliases = new LinkedHashMap<>(); + + /** + * Whether the next block of declarations must be separated by an empty line. + */ + private boolean _separate; + + /** + * Creates a {@link TypeScriptGenerator}. + * + * @param file + * The TypeScript module file to create. + * @param proto + * The definitions to generate types for. + * @param source + * A description of the source of the definitions for the header comment. + * @param moduleSpecifier + * Function computing the module specifier (relative to the module being generated) of + * the TypeScript module for another {@link DefinitionFile}. + * @param table + * The {@link NameTable} for resolving type names in links of documentation comments. + */ + public TypeScriptGenerator(File file, DefinitionFile proto, String source, Function moduleSpecifier, NameTable table) { + _file = file; + _proto = proto; + _source = source; + _moduleSpecifier = moduleSpecifier; + _table = table; + } + + /** + * Runs the generation. + */ + public void run() { + System.out.println("Generating '" + _file + "'."); + File dir = _file.getParentFile(); + if (dir != null) { + dir.mkdirs(); + } + try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(_file), "utf-8")) { + generate(out, 0); + } catch (IOException ex) { + throw new IOError(ex); + } + } + + @Override + protected void generate() { + resolveReferences(); + + line("// Generated by msgbuf from '" + _source + "'. Do not edit."); + line("//"); + line("// Type definitions for the msgbuf JSON format of the protocol (types only, no runtime code)."); + if (Util.getFlag(_proto, "SharedGraph")) { + line("//"); + line("// Note: The protocol uses 'option SharedGraph'. Its JSON format (objects as [type, id, {...}],"); + line("// references as object IDs, incremental updates) is not described by these types."); + } + _separate = true; + + String fileComment = fileComment(); + if (!fileComment.isEmpty()) { + separate(); + docComment(fileComment); + } + + if (!_imports.isEmpty()) { + separate(); + } + for (Map.Entry> entry : _imports.entrySet()) { + List names = new ArrayList<>(); + for (Map.Entry binding : entry.getValue().entrySet()) { + String name = binding.getKey(); + String local = binding.getValue(); + names.add(name.equals(local) ? name : name + " as " + local); + } + line("import type { " + String.join(", ", names) + " } from " + stringLiteral(_moduleSpecifier.apply(entry.getKey())) + ";"); + } + for (Definition def : _proto.getDefinitions()) { + generateDefinition(def); + } + + for (Map.Entry alias : _aliases.entrySet()) { + separate(); + line("type " + alias.getKey() + " = " + alias.getValue() + ";"); + } + } + + /** + * Starts a new block of declarations separated by an empty line from a preceding one in the + * same scope. + */ + private void separate() { + if (_separate) { + nl(); + } + _separate = true; + } + + /** + * Computes all type references in advance to be able to create the import statements and + * aliases before the definitions. + */ + private void resolveReferences() { + for (Definition def : _proto.getDefinitions()) { + _topLevelNames.add(def.getName()); + if (hasPolymorphicType(def)) { + _topLevelNames.add(polymorphicName(def)); + } + } + for (Definition def : _proto.getDefinitions()) { + resolveReferences(def); + } + // Links in documentation comments may require further imports. + fileComment(); + for (Definition def : _proto.getDefinitions()) { + resolveDocReferences(def); + } + } + + private void resolveDocReferences(Definition def) { + if (def instanceof EnumDef) { + EnumDef enumDef = (EnumDef) def; + doc(enumDef.getComment(), enumDef); + for (Constant constant : enumDef.getConstants()) { + doc(constant.getComment(), enumDef); + } + } else { + MessageDef message = (MessageDef) def; + messageComment(message); + for (Field field : jsonFields(message)) { + fieldComment(field, message); + } + for (Definition inner : message.getDefinitions()) { + resolveDocReferences(inner); + } + } + } + + private void resolveReferences(Definition def) { + if (def instanceof MessageDef) { + MessageDef message = (MessageDef) def; + MessageDef extendedDef = message.getExtendedDef(); + if (extendedDef != null) { + ref(extendedDef, message); + } + for (Field field : jsonFields(message)) { + typeExpr(field, message); + } + if (hasPolymorphicType(message)) { + polymorphicType(message); + } + for (Definition inner : message.getDefinitions()) { + resolveReferences(inner); + } + } + } + + private void generateDefinition(Definition def) { + if (def instanceof EnumDef) { + generateEnum((EnumDef) def); + } else { + generateMessage((MessageDef) def); + } + } + + private void generateEnum(EnumDef def) { + separate(); + docComment(doc(def.getComment(), def)); + List constants = def.getConstants(); + if (constants.isEmpty()) { + line("export type " + def.getName() + " = never;"); + } else { + line("export type " + def.getName() + " ="); + for (int n = 0, cnt = constants.size(); n < cnt; n++) { + Constant constant = constants.get(n); + indentedDocComment(doc(constant.getComment(), def)); + line("\t| " + stringLiteral(MsgBufJsonProtocol.classifierId(constant)) + (n == cnt - 1 ? ";" : "")); + } + } + } + + private void indentedDocComment(String comment) { + if (comment != null && !comment.isEmpty()) { + line("\t/**"); + for (String line : comment.split("\n")) { + line("\t *" + (line.isEmpty() ? "" : " " + line)); + } + line("\t */"); + } + } + + private void generateMessage(MessageDef def) { + separate(); + docComment(messageComment(def)); + MessageDef extendedDef = def.getExtendedDef(); + String extendsClause = extendedDef == null ? "" : " extends " + ref(extendedDef, def); + List fields = jsonFields(def); + if (fields.isEmpty()) { + line("export interface " + def.getName() + extendsClause + " {}"); + } else { + line("export interface " + def.getName() + extendsClause + " {"); + boolean first = true; + for (Field field : fields) { + if (first) { + first = false; + } else { + nl(); + } + docComment(fieldComment(field, def)); + line(propertyName(field) + "?: " + typeExpr(field, def) + ";"); + } + line("}"); + } + + if (hasPolymorphicType(def)) { + separate(); + docComment("Polymorphic JSON representation of a {@link " + def.getName() + "}: a tuple of the type ID and the properties of a concrete type."); + line("export type " + polymorphicName(def) + " = " + polymorphicType(def) + ";"); + } + + if (!def.getDefinitions().isEmpty()) { + separate(); + line("export namespace " + def.getName() + " {"); + _separate = false; + for (Definition inner : def.getDefinitions()) { + generateDefinition(inner); + } + line("}"); + _separate = true; + } + } + + private String fileComment() { + String comment = doc(_proto.getComment(), null); + return comment == null || comment.isEmpty() ? "" : comment + "\n\n@packageDocumentation"; + } + + private String messageComment(MessageDef def) { + String comment = doc(def.getComment(), def); + if (def.isAbstract()) { + String note = "Abstract type, the properties are only present in the JSON of its concrete specializations."; + comment = comment == null || comment.isEmpty() ? note : comment + "\n\n" + note; + } + return comment; + } + + private String fieldComment(Field field, MessageDef owner) { + String comment = doc(field.getComment(), owner); + String defaultValue = field.getDefaultValue(); + if (defaultValue != null) { + String tag = "@defaultValue " + defaultValue; + comment = comment == null || comment.isEmpty() ? tag : comment + "\n\n" + tag; + } + return comment; + } + + /** + * Translates JavaDoc inline tags in the given documentation comment to TSDoc. + * + *
    + *
  • {@literal {@code x}} becomes `x`, {@literal {@literal x}} + * becomes x.
  • + *
  • {@literal {@link Type}} and {@literal {@link Type#field label}} + * become links to the TypeScript type and its property, e.g. {@literal {@link Type.prop label}}. + * A reference to an enum constant becomes its protocol name in back ticks. A target that cannot + * be resolved becomes its label, or the target name in back ticks.
  • + *
+ * + * @param comment + * The comment to translate. + * @param owner + * The message or enum whose members are referenced by #member, and whose + * declaration contains the comment. null for the comment of the module. + */ + private String doc(String comment, Definition owner) { + return DocTags.replaceInlineTags(comment, (tag, content) -> { + switch (tag) { + case "code": + return "`" + content + "`"; + case "literal": + return content; + case "link": + case "linkplain": + return link(content, owner); + default: + return null; + } + }); + } + + private String link(String content, Definition owner) { + int space = indexOfWhitespace(content); + String target = space < 0 ? content : content.substring(0, space); + String label = space < 0 ? null : content.substring(space).trim(); + + int hash = target.indexOf('#'); + String typeName = hash < 0 ? target : target.substring(0, hash); + String member = hash < 0 ? null : target.substring(hash + 1); + + Definition type; + if (typeName.isEmpty()) { + type = owner; + } else { + MessageDef lookupContext = owner instanceof MessageDef ? (MessageDef) owner : owner == null ? null : owner.getOuter(); + type = _table.resolve(lookupContext, QName.create().setNames(Arrays.asList(typeName.split("\\.")))); + } + + if (type != null) { + if (member == null) { + return "{@link " + ref(type, owner) + (label == null ? "" : " " + label) + "}"; + } + if (type instanceof MessageDef) { + MessageDef declaring = (MessageDef) type; + Field field = null; + while (declaring != null && (field = localField(declaring, member)) == null) { + declaring = declaring.getExtendedDef(); + } + if (field != null && !field.isTransient() && !field.isDerived()) { + String property = MsgBufJsonProtocol.fieldId(field); + if (IDENTIFIER.matcher(property).matches()) { + return "{@link " + ref(declaring, owner) + "." + property + (label == null ? "" : " " + label) + "}"; + } + return label != null ? label : "`" + property + "`"; + } + } else { + for (Constant constant : ((EnumDef) type).getConstants()) { + if (constant.getName().equals(member)) { + return label != null ? label : "`" + stringLiteral(MsgBufJsonProtocol.classifierId(constant)) + "`"; + } + } + } + } + + // Not resolvable. + if (label != null) { + return label; + } + String text = typeName.isEmpty() ? member : member == null ? typeName : typeName + "." + member; + return "`" + text + "`"; + } + + private static Field localField(MessageDef def, String name) { + for (Field field : def.getFields()) { + if (field.getName().equals(name)) { + return field; + } + } + return null; + } + + private static int indexOfWhitespace(String text) { + for (int n = 0, cnt = text.length(); n < cnt; n++) { + if (Character.isWhitespace(text.charAt(n))) { + return n; + } + } + return -1; + } + + /** + * The fields of the given message that are part of its JSON serialization. + */ + private static List jsonFields(MessageDef def) { + List result = new ArrayList<>(); + for (Field field : def.getFields()) { + if (field.isTransient() || field.isDerived()) { + continue; + } + result.add(field); + } + return result; + } + + private static String propertyName(Field field) { + String name = MsgBufJsonProtocol.fieldId(field); + return IDENTIFIER.matcher(name).matches() ? name : stringLiteral(name); + } + + /** + * Whether values of the given definition are serialized with a type tag + * ([typeId, {...}]). + * + *

+ * This is the case for an abstract message whose hierarchy root is abstract. A concrete message + * with a generalization is written without type information when referenced by its own type, and + * a message in a hierarchy with a concrete root is always written without type information. + *

+ */ + private static boolean hasPolymorphicType(Definition def) { + if (!(def instanceof MessageDef)) { + return false; + } + MessageDef message = (MessageDef) def; + return message.isAbstract() && root(message).isAbstract(); + } + + private static MessageDef root(MessageDef def) { + MessageDef result = def; + while (result.getExtendedDef() != null) { + result = result.getExtendedDef(); + } + return result; + } + + private static String polymorphicName(Definition def) { + return POLYMORPHIC_PREFIX + def.getName(); + } + + private String polymorphicType(MessageDef def) { + List alternatives = new ArrayList<>(); + for (MessageDef specialization : Util.concreteTransitiveSpecializations(def)) { + alternatives.add("[" + stringLiteral(MsgBufJsonProtocol.typeId(specialization)) + ", " + ref(specialization, def) + "]"); + } + if (Util.getFlag(fileOf(root(def)), "OpenWorld")) { + // Extension types from other modules. + alternatives.add("[string, " + ref(def, def) + "]"); + } + return alternatives.isEmpty() ? "never" : String.join(" | ", alternatives); + } + + private String typeExpr(Field field, MessageDef context) { + String elementType = typeExpr(field.getType(), context); + if (field.isRepeated()) { + return elementType.matches("[\\w$.]+") ? elementType + "[]" : "Array<" + elementType + ">"; + } + return elementType; + } + + private String typeExpr(Type type, MessageDef context) { + if (type instanceof PrimitiveType) { + return primitiveType(((PrimitiveType) type).getKind()); + } else if (type instanceof MapType) { + MapType mapType = (MapType) type; + Type keyType = mapType.getKeyType(); + String valueType = typeExpr(mapType.getValueType(), context); + if (keyType instanceof PrimitiveType && ((PrimitiveType) keyType).getKind() == PrimitiveType.Kind.STRING) { + return "Record"; + } else { + return "Array<{ key: " + typeExpr(keyType, context) + "; value: " + valueType + " }>"; + } + } else if (type instanceof CustomType) { + Definition definition = ((CustomType) type).getDefinition(); + if (definition == null) { + System.err.println("ERROR: No definition found for type '" + type + "'."); + return "unknown"; + } + if (hasPolymorphicType(definition)) { + return polymorphicRef((MessageDef) definition, context); + } + return ref(definition, context); + } + throw new IllegalArgumentException("Unsupported type: " + type); + } + + private static String primitiveType(PrimitiveType.Kind kind) { + switch (kind) { + case BOOL: + return "boolean"; + + case FLOAT: + case DOUBLE: + case INT_32: + case UINT_32: + case SINT_32: + case FIXED_32: + case SFIXED_32: + case INT_64: + case UINT_64: + case SINT_64: + case FIXED_64: + case SFIXED_64: + return "number"; + + case STRING: + return "string"; + + case BYTES: + // Base64 encoded. + return "string"; + + case JSON: + return "unknown"; + } + throw new IllegalArgumentException("No such type: " + kind); + } + + /** + * Reference to the given definition from within the given declaration. + * + * @param context + * The declaration containing the reference (determines the namespace scope of the + * reference), null for a reference at the top level of the module. + */ + private String ref(Definition target, Definition context) { + List path = path(target); + return ref(fileOf(target), path, context); + } + + private String polymorphicRef(MessageDef target, Definition context) { + List path = path(target); + path.set(path.size() - 1, polymorphicName(target)); + return ref(fileOf(target), path, context); + } + + private String ref(DefinitionFile file, List path, Definition context) { + String topLevel = path.get(0); + String binding = file == _proto ? topLevel : importBinding(file, topLevel); + StringBuilder buffer = new StringBuilder(binding); + for (String name : path.subList(1, path.size())) { + buffer.append('.').append(name); + } + String result = buffer.toString(); + if (isShadowed(binding, context)) { + String alias = "__" + result.replace('.', '_'); + _aliases.put(alias, result); + return alias; + } + return result; + } + + /** + * Whether the given top-level name is hidden by a declaration in the namespace scopes in which + * the given declaration is placed. + */ + private static boolean isShadowed(String topLevelName, Definition context) { + if (context == null) { + return false; + } + for (MessageDef scope = context.getOuter(); scope != null; scope = scope.getOuter()) { + for (Definition inner : scope.getDefinitions()) { + if (inner.getName().equals(topLevelName)) { + return true; + } + if (hasPolymorphicType(inner) && polymorphicName(inner).equals(topLevelName)) { + return true; + } + } + } + return false; + } + + private String importBinding(DefinitionFile file, String name) { + Map bindings = _imports.computeIfAbsent(file, x -> new LinkedHashMap<>()); + String binding = bindings.get(name); + if (binding == null) { + binding = name; + if (_topLevelNames.contains(binding)) { + String prefix = file.getPackage() == null ? "" : Util.last(file.getPackage()) + "_"; + binding = prefix + name; + int n = 2; + while (_topLevelNames.contains(binding)) { + binding = prefix + name + "_" + n++; + } + } + _topLevelNames.add(binding); + bindings.put(name, binding); + } + return binding; + } + + /** + * The file containing the given definition. + * + *

+ * Only top-level definitions have a direct reference to their file. + *

+ */ + private static DefinitionFile fileOf(Definition def) { + Definition current = def; + while (current.getOuter() != null) { + current = current.getOuter(); + } + return current.getFile(); + } + + private static List path(Definition def) { + List result = new ArrayList<>(); + for (Definition current = def; current != null; current = current.getOuter()) { + result.add(0, current.getName()); + } + return result; + } + + private static String stringLiteral(String value) { + return "'" + value.replace("\\", "\\\\").replace("'", "\\'") + "'"; + } + +} diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/util/AbstractTypeScriptGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/util/AbstractTypeScriptGenerator.java new file mode 100644 index 00000000..84a9a7b7 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/util/AbstractTypeScriptGenerator.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2026 Bernhard Haumacher et al. All Rights Reserved. + */ +package de.haumacher.msgbuf.generator.util; + +/** + * Base class for generators creating TypeScript code. + */ +public abstract class AbstractTypeScriptGenerator extends AbstractFileGenerator { + + @Override + protected void docComment(String comment) { + if (comment != null && !comment.isEmpty()) { + line("/**"); + for (String line : comment.split("\n")) { + line(" *" + (line.isEmpty() ? "" : " " + line)); + } + line(" */"); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/de/haumacher/msgbuf/generator/ts/TestTypeScriptGenerator.java b/de.haumacher.msgbuf.generator/src/test/java/de/haumacher/msgbuf/generator/ts/TestTypeScriptGenerator.java new file mode 100644 index 00000000..22057caa --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/de/haumacher/msgbuf/generator/ts/TestTypeScriptGenerator.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2026 Bernhard Haumacher et al. All Rights Reserved. + */ +package de.haumacher.msgbuf.generator.ts; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import de.haumacher.msgbuf.generator.Generator; +import de.haumacher.msgbuf.generator.GeneratorPlugin; +import junit.framework.TestCase; + +/** + * Golden-file test for {@link TypeScriptGenerator}. + * + *

+ * Generates the .proto files in src/test/resources/ts/proto and compares + * the TypeScript output with the files in src/test/resources/ts/expected. Run with + * -Dmsgbuf.ts.update=true to replace the expected files with the current output. + *

+ */ +@SuppressWarnings("javadoc") +public class TestTypeScriptGenerator extends TestCase { + + private static final File BASE = new File("src/test/resources/ts"); + + private static final File PROTO_DIR = new File(BASE, "proto"); + + private static final File EXPECTED_DIR = new File(BASE, "expected"); + + public void testGolden() throws Exception { + File outDir = new File("target/ts-test"); + deleteRecursively(outDir.toPath()); + + File javaOut = new File(outDir, "java"); + File tsOut = new File(outDir, "ts"); + + Generator generator = new Generator(); + generator.setOut(javaOut); + generator.setTypeScriptOut(tsOut); + for (File proto : protoFiles()) { + generator.load(proto); + } + generator.generate(GeneratorPlugin.none()); + + Set actual = tsFiles(tsOut.toPath()); + assertFalse("No TypeScript files generated.", actual.isEmpty()); + + if (Boolean.getBoolean("msgbuf.ts.update")) { + deleteRecursively(EXPECTED_DIR.toPath()); + for (String name : actual) { + Path target = EXPECTED_DIR.toPath().resolve(name); + Files.createDirectories(target.getParent()); + Files.copy(tsOut.toPath().resolve(name), target); + } + return; + } + + Set expected = tsFiles(EXPECTED_DIR.toPath()); + assertEquals("Generated TypeScript modules.", expected, actual); + for (String name : expected) { + assertEquals("Content of '" + name + "'.", + read(EXPECTED_DIR.toPath().resolve(name)), + read(tsOut.toPath().resolve(name))); + } + } + + private static List protoFiles() throws IOException { + try (Stream files = Files.walk(PROTO_DIR.toPath())) { + return files + .filter(p -> p.toString().endsWith(".proto")) + .sorted() + .map(Path::toFile) + .collect(Collectors.toList()); + } + } + + private static Set tsFiles(Path dir) throws IOException { + if (!Files.isDirectory(dir)) { + return new TreeSet<>(); + } + try (Stream files = Files.walk(dir)) { + return files + .filter(p -> p.toString().endsWith(".ts")) + .map(p -> dir.relativize(p).toString().replace(File.separatorChar, '/')) + .collect(Collectors.toCollection(TreeSet::new)); + } + } + + private static String read(Path file) throws IOException { + return new String(Files.readAllBytes(file), StandardCharsets.UTF_8).replace("\r\n", "\n"); + } + + private static void deleteRecursively(Path dir) throws IOException { + if (!Files.exists(dir)) { + return; + } + try (Stream files = Files.walk(dir)) { + for (Path p : files.sorted((a, b) -> b.compareTo(a)).collect(Collectors.toList())) { + Files.delete(p); + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/custom/explicit-types.ts b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/custom/explicit-types.ts new file mode 100644 index 00000000..05e842a2 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/custom/explicit-types.ts @@ -0,0 +1,20 @@ +// Generated by msgbuf from 'test/ts/explicit/explicit.proto'. Do not edit. +// +// Type definitions for the msgbuf JSON format of the protocol (types only, no runtime code). + +import type { DisplayMode, Leaf } from '../test/ts/common/common'; + +/** + * A message placed in an explicitly configured module. + */ +export interface Explicit { + /** + * Mode. + */ + mode?: DisplayMode; + + /** + * Leaves. + */ + leaves?: Leaf[]; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/common/common.ts b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/common/common.ts new file mode 100644 index 00000000..2181ceae --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/common/common.ts @@ -0,0 +1,78 @@ +// Generated by msgbuf from 'test/ts/common/common.proto'. Do not edit. +// +// Type definitions for the msgbuf JSON format of the protocol (types only, no runtime code). + +/** + * Common types, documented at the package declaration. + * + * @packageDocumentation + */ + +/** + * Display modes of a button. + */ +export type DisplayMode = + /** + * Only the icon is shown. + */ + | 'icon-only' + /** + * Only the label is shown. + */ + | 'label-only' + /** + * Constant without custom name, combines `'icon-only'` and `'label-only'`. + */ + | 'BOTH'; + +/** + * A point in the plane. + */ +export interface Point { + /** + * The X coordinate. + */ + x?: number; + + /** + * The Y coordinate. + */ + y?: number; +} + +/** + * Abstract base of a polymorphic hierarchy with an abstract root. + * + * Abstract type, the properties are only present in the JSON of its concrete specializations. + */ +export interface Node { + /** + * The node ID. + */ + id?: string; +} + +/** + * Polymorphic JSON representation of a {@link Node}: a tuple of the type ID and the properties of a concrete type. + */ +export type AnyNode = ['Leaf', Leaf] | ['Inner', Inner]; + +/** + * A leaf node. + */ +export interface Leaf extends Node { + /** + * The value. + */ + value?: number; +} + +/** + * An inner node. + */ +export interface Inner extends Node { + /** + * The children, written as type-tagged tuples. + */ + children?: AnyNode[]; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/shapes/shapes.ts b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/shapes/shapes.ts new file mode 100644 index 00000000..f1206087 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/shapes/shapes.ts @@ -0,0 +1,242 @@ +// Generated by msgbuf from 'test/ts/shapes/shapes.proto'. Do not edit. +// +// Type definitions for the msgbuf JSON format of the protocol (types only, no runtime code). + +/** + * Shapes and button states for testing the TypeScript generator. + * + *

See {@link ButtonState}, {@link Group.shapes the shapes of a group} and `nothing`.

+ * + * @packageDocumentation + */ + +import type { Point as common_Point, DisplayMode, AnyNode } from '../common/common'; + +/** + * A local point clashing with the imported one. + */ +export interface Point { + /** + * A coordinate pair. + */ + value?: common_Point; +} + +/** + * A label. + */ +export interface Label { + text?: string; +} + +/** + * State of a button. + * + *

Refers to {@link Label}.

+ */ +export interface ButtonState { + /** + * The label. + */ + label?: string; + + /** + * Whether the button is disabled, see {@link ButtonState.label} and {@link ButtonState.label the label}. + * + * Code: `if (x) { y(); }`, literal: a; + + /** + * Ratings by number. + */ + ratings?: Array<{ key: number; value: string }>; + + /** + * A polymorphic reference to another file. + */ + root?: AnyNode; + + /** + * Local points, see {@link Point.value} and {@link common_Point.x}, inherited {@link Shape.origin}. + */ + points?: Point[]; +} + +/** + * Concrete base class: JSON has no type information. + */ +export interface Base { + name?: string; +} + +/** + * Specialization of a concrete base. + */ +export interface Derived extends Base { + extra?: number; +} + +/** + * Abstract shape. + * + * Abstract type, the properties are only present in the JSON of its concrete specializations. + */ +export interface Shape { + /** + * The origin. + */ + origin?: common_Point; +} + +/** + * Polymorphic JSON representation of a {@link Shape}: a tuple of the type ID and the properties of a concrete type. + */ +export type AnyShape = ['Rectangle', Rectangle] | ['Group', Group] | ['circle', Circle]; + +/** + * Abstract intermediate class. + * + * Abstract type, the properties are only present in the JSON of its concrete specializations. + */ +export interface Rounded extends Shape {} + +/** + * Polymorphic JSON representation of a {@link Rounded}: a tuple of the type ID and the properties of a concrete type. + */ +export type AnyRounded = ['circle', Circle]; + +/** + * A circle. + */ +export interface Circle extends Rounded { + /** + * The radius. + */ + r?: number; +} + +/** + * A rectangle. + */ +export interface Rectangle extends Shape { + width?: number; + + height?: number; +} + +/** + * A group of shapes. + */ +export interface Group extends Shape { + /** + * Contents written polymorphically. + */ + shapes?: AnyShape[]; + + /** + * Monomorphic reference to a concrete type in a hierarchy. + */ + main?: Circle; + + /** + * Reference to an abstract intermediate type. + */ + rounded?: AnyRounded; + + info?: Group.Info; +} + +export namespace Group { + /** + * A label local to groups. + */ + export interface Label { + kind?: Group.Label.Kind; + } + + export namespace Label { + /** + * Group label kind. + */ + export type Kind = + | 'PRIMARY' + | 'SECONDARY'; + } + + /** + * Nested message referencing the shadowed top-level type {@link __Label} and {@link Group.Label}. + */ + export interface Info { + /** + * The top-level label. + */ + global?: __Label; + + /** + * The nested label. + */ + local?: Group.Label; + } +} + +/** + * An empty enum. + */ +export type Nothing = never; + +type __Label = Label; diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/common/common.proto b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/common/common.proto new file mode 100644 index 00000000..03bde1c4 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/common/common.proto @@ -0,0 +1,50 @@ +/* Plain block comment, not a documentation comment. */ +syntax = "msgbuf"; + +/** + * Common types, documented at the package declaration. + */ +package test.ts.common; + +/** Display modes of a button. */ +enum DisplayMode { + /** Only the icon is shown. */ + @Name("icon-only") + ICON_ONLY; + + /** Only the label is shown. */ + @Name("label-only") + LABEL_ONLY; + + /** Constant without custom name, combines {@link #ICON_ONLY} and {@link #LABEL_ONLY}. */ + BOTH; +} + +/** A point in the plane. */ +message Point { + /** The X coordinate. */ + @Name("x") + int32 xCoordinate; + + /** The Y coordinate. */ + @Name("y") + int32 yCoordinate; +} + +/** Abstract base of a polymorphic hierarchy with an abstract root. */ +abstract message Node { + /** The node ID. */ + string id; +} + +/** A leaf node. */ +message Leaf extends Node { + /** The value. */ + double value; +} + +/** An inner node. */ +message Inner extends Node { + /** The children, written as type-tagged tuples. */ + repeated Node children; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/explicit/explicit.proto b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/explicit/explicit.proto new file mode 100644 index 00000000..07b16f76 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/explicit/explicit.proto @@ -0,0 +1,16 @@ +syntax = "msgbuf"; + +package test.ts.explicit; + +import "../common/common.proto"; + +option TypeScript = "../ts/custom/explicit-types.ts"; + +/** A message placed in an explicitly configured module. */ +message Explicit { + /** Mode. */ + test.ts.common.DisplayMode mode; + + /** Leaves. */ + repeated test.ts.common.Leaf leaves; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/shapes/shapes.proto b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/shapes/shapes.proto new file mode 100644 index 00000000..448fe0ba --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/shapes/shapes.proto @@ -0,0 +1,160 @@ +/** + * Shapes and button states for testing the TypeScript generator. + * + *

See {@link ButtonState}, {@link Group#shapes the shapes of a group} and {@link #nothing}.

+ */ +syntax = "msgbuf"; + +package test.ts.shapes; + +import "../common/common.proto"; + +/** A local point clashing with the imported one. */ +message Point { + /** A coordinate pair. */ + test.ts.common.Point value; +} + +/** A label. */ +message Label { + string text; +} + +/** + * State of a button. + * + *

Refers to {@link Label}.

+ */ +message ButtonState { + /** The label. */ + string label; + + /** + * Whether the button is disabled, see {@link #label} and {@link #label the label}. + * + * Code: {@code if (x) { y(); }}, literal: {@literal a labels; + + /** Ratings by number. */ + map ratings; + + /** A polymorphic reference to another file. */ + test.ts.common.Node root; + + /** Local points, see {@link Point#value} and {@link test.ts.common.Point#xCoordinate}, inherited {@link Circle#origin}. */ + repeated Point points; +} + +/** Concrete base class: JSON has no type information. */ +message Base { + string name; +} + +/** Specialization of a concrete base. */ +message Derived extends Base { + int32 extra; +} + +/** Abstract shape. */ +abstract message Shape { + /** The origin. */ + test.ts.common.Point origin; +} + +/** Abstract intermediate class. */ +abstract message Rounded extends Shape { +} + +/** A circle. */ +@Name("circle") +message Circle extends Rounded { + /** The radius. */ + @Name("r") + double radius; +} + +/** A rectangle. */ +message Rectangle extends Shape { + double width; + double height; +} + +/** A group of shapes. */ +message Group extends Shape { + /** Contents written polymorphically. */ + repeated Shape shapes; + + /** Monomorphic reference to a concrete type in a hierarchy. */ + Circle main; + + /** Reference to an abstract intermediate type. */ + Rounded rounded; + + /** A label local to groups. */ + message Label { + /** Group label kind. */ + enum Kind { + PRIMARY; + SECONDARY; + } + + Kind kind; + } + + /** Nested message referencing the shadowed top-level type {@link test.ts.shapes.Label} and {@link Label}. */ + message Info { + /** The top-level label. */ + test.ts.shapes.Label global; + + /** The nested label. */ + Label local; + } + + Info info; +} + +/** An empty enum. */ +enum Nothing { +} diff --git a/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java b/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java index c291c1d0..544bcf1e 100644 --- a/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java +++ b/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java @@ -53,6 +53,19 @@ public class GenerateMessageClasses extends AbstractMojo { @Parameter(defaultValue = "${project.basedir}/src/main/resources", property = "resourceOutputDir") private File _resourceOutputDirectory; + /** + * Directory where to generate TypeScript type definitions for the JSON format to. + * + *

+ * If set, a TypeScript module is generated for each .proto file. The module for a + * file name.proto with package a.b.c; is written to + * a/b/c/name.ts within this directory. If not set, TypeScript modules are only + * generated for .proto files with an explicit option TypeScript. + *

+ */ + @Parameter(alias = "typeScriptOutputDirectory", property = "typeScriptOutputDir") + private File _typeScriptOutputDirectory; + @Parameter(defaultValue = "${project}", readonly = true, required = true) private MavenProject _project; @@ -84,6 +97,9 @@ public void execute() throws MojoExecutionException { if (_resourceOutputDirectory != null) { generator.setResourceOut(_resourceOutputDirectory); } + if (_typeScriptOutputDirectory != null) { + generator.setTypeScriptOut(_typeScriptOutputDirectory); + } if (_includePaths != null) { for (File includePath : _includePaths) { generator.addIncludePath(includePath); From 780887d10c6f963e21c575d59750bf5b2185aa17 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 14:51:09 +0200 Subject: [PATCH 187/207] TypeScript: Required properties and Json suffix for type names. Properties the Java JSON writer always emits are now required; only fields omitted when null (@Nullable, non-repeated message references, json) stay optional. A non-nullable bytes field is typed 'string | null', since it defaults to null and is written as null. Top-level types get the suffix 'Json' (ShapeJson, AnyShapeJson, DisplayModeJson), since they describe the JSON format, not the data itself. This keeps the plain names free for types with runtime representation. Nested types keep their names within the suffixed namespace (GroupJson.Info). Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 2 + README.md | 38 +++--- .../generator/ts/TypeScriptGenerator.java | 79 +++++++++--- .../ts/expected/custom/explicit-types.ts | 8 +- .../ts/expected/test/ts/common/common.ts | 24 ++-- .../ts/expected/test/ts/shapes/shapes.ts | 116 ++++++++++-------- .../ts/proto/test/ts/shapes/shapes.proto | 8 ++ 7 files changed, 175 insertions(+), 100 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0969f6ec..236509e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ ### New Features - **TypeScript type definitions**: Generate a types-only TypeScript module per `.proto` file describing its JSON format (interfaces for messages, string-literal unions for enums, type-tagged tuple unions for polymorphic values). + Top-level types are named with the suffix `Json` (e.g. `ShapeJson`, `AnyShapeJson`), since they describe the JSON + format, not the data itself. Properties the Java writer always emits are required, only nullable fields are optional. Enabled for all files with the Maven plugin parameter `typeScriptOutputDirectory` or the `-ts ` CLI argument, or per file with `option TypeScript = "path/to/module.ts";`. - **File documentation comment**: A doc comment before the `syntax` or `package` declaration is kept as the documentation diff --git a/README.md b/README.md index 3c30ef4b..fe703035 100644 --- a/README.md +++ b/README.md @@ -450,6 +450,10 @@ The generator can create a TypeScript module with type definitions for the JSON modules contain types only (no readers, writers or other runtime code) and let a TypeScript client share the protocol contract with the Java side. +Since the types describe the JSON format and not the data itself, a top-level type is named after its definition with +the suffix `Json`, e.g. `ShapeJson` for `message Shape`. This keeps the plain names free for types representing the +data in the TypeScript application. + TypeScript output is enabled in one of the following ways: * **Output directory for all files**: Set the Maven plugin parameter `typeScriptOutputDirectory` (user property @@ -474,26 +478,30 @@ Mapping of protocol definitions: | Protocol definition | TypeScript | |---|---| -| `message M { ... }` | `export interface M { ... }` with the JSON property names of the fields (`@Name` is honored) | -| `message M extends B` | `export interface M extends B` | -| `abstract message A` | `export interface A`, plus `export type AnyA = ['TypeIdOfC1', C1] \| ...` if the hierarchy root is abstract (see below) | -| `enum E { ... }` | `export type E = 'A' \| 'B';` with the protocol names of the constants (`@Name` is honored) | -| `string`, `bytes` | `string` (bytes are Base64 encoded) | +| `message M { ... }` | `export interface MJson { ... }` with the JSON property names of the fields (`@Name` is honored) | +| `message M extends B` | `export interface MJson extends BJson` | +| `abstract message A` | `export interface AJson`, plus `export type AnyAJson = ['TypeIdOfC1', C1Json] \| ...` if the hierarchy root is abstract (see below) | +| `enum E { ... }` | `export type EJson = 'A' \| 'B';` with the protocol names of the constants (`@Name` is honored) | +| `string` | `string` | +| `bytes` | `string \| null` (Base64 encoded, see below) | | `bool` | `boolean` | | `int32`, `int64`, `float`, `double`, ... | `number` | | `json` | `unknown` | | `repeated T` | `T[]` | | `map` | `Record` | | `map` (other key types) | `Array<{ key: K; value: V }>` | -| Nested definitions | Declarations in a namespace named after the outer message, e.g. `Outer.Inner` | +| Nested definitions | Declarations in a namespace named after the outer message, keeping their names, e.g. `OuterJson.Inner` | | Types from imported `.proto` files | `import type { ... } from '';` | Details: -* **Optional properties**: All properties are optional (`name?: T`). The JSON reader accepts any subset of properties - and uses the field's default value for a missing one. Fields that are unset and nullable (`@Nullable`, references - to messages) are omitted from the JSON output instead of being written as `null`. Explicit default values of fields - are documented with a `@defaultValue` tag. +* **Required and optional properties**: The types describe the JSON the Java side writes. A property is required + (`name: T`), if it is always written. Fields that are nullable (`@Nullable`, non-repeated references to messages, + `json`) are omitted from the JSON output when unset instead of being written as `null`, their properties are + optional (`name?: T`). A non-nullable `bytes` field has no value by default and is written as `null` then, it is + typed `string | null`. Note that the JSON reader is more lenient: it accepts any subset of properties and uses the + field's default value for a missing one. Explicit default values of fields are documented with a `@defaultValue` + tag. * **Enum values**: An enum constant is written as its name exactly as spelled in the `.proto` file (e.g. `ICON_ONLY`), unless a custom name is given with `@Name`: @@ -506,12 +514,12 @@ Details: } ``` - generates `export type DisplayMode = | 'icon-only' | 'label-only';`. + generates `export type DisplayModeJson = | 'icon-only' | 'label-only';`. * **Polymorphism**: A value of an abstract message type in a hierarchy with an abstract root is written as a tuple of its type ID and its properties, `["Circle", {"r": 5}]` (see [Polymorphic JSON serialization](#polymorphic-json-serialization)). - For each such abstract message `A`, a union type `AnyA` of the tuples of all known concrete specializations is + For each such abstract message `A`, a union type `AnyAJson` of the tuples of all known concrete specializations is generated and used as type of fields referencing `A`. For `option OpenWorld` hierarchies, the union additionally - contains `[string, A]` for extension types from other modules. References to concrete messages (and all messages + contains `[string, AJson]` for extension types from other modules. References to concrete messages (and all messages in a hierarchy with a concrete root) are written without type information and use the interface directly. * **Documentation**: Doc comments become TSDoc comments. JavaDoc inline tags are translated: `{@code x}` becomes `` `x` ``, `{@link Type}`, `{@link #field}` and `{@link Type#field label}` become links to the TypeScript type or @@ -524,8 +532,8 @@ Details: at the location the same generator configuration would produce for it (its `option TypeScript`, or its package path within the TypeScript output directory). * **Limitations**: The JSON format of `option SharedGraph` protocols (objects as `[type, id, {...}]`, references as - IDs, incremental updates) is not described by the generated types. A generated `AnyA` union type may clash with a - message of the same name. + IDs, incremental updates) is not described by the generated types. A generated `AnyAJson` union type may clash with + a message named `AnyA`. ## Installation in Eclipse diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java index fb13a754..16bca762 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java @@ -40,20 +40,28 @@ * format of all messages and enums of a .proto file. * *

- * The module contains types only (no runtime code): + * The module contains types only (no runtime code). Since the types describe the JSON format and + * not the data itself, the name of a top-level type is the name of its definition with the suffix + * {@value #JSON_SUFFIX}, e.g. ShapeJson for message Shape: *

*
    *
  • A message becomes an interface whose properties are named with the JSON - * property names of the message's fields. All properties are optional, since the msgbuf - * JSON reader accepts any subset of properties and uses the field default for a missing one.
  • + * property names of the message's fields. A property is required, if the Java writer always emits + * it, and optional (?), if the Java writer omits it when the value is + * null (fields marked @Nullable and non-repeated fields with message or + * json type). A non-nullable bytes field is written as null + * when it has no value and is therefore typed string | null. Note that the + * msgbuf JSON reader is more lenient and accepts any subset of properties, using the + * field default for a missing one. *
  • A message that inherits from another message extends the interface of its * generalization.
  • *
  • An abstract message in a hierarchy with an abstract root is serialized polymorphically as * [typeId, {...}]. For such message, an additional union type - * Any<Name> of type-tagged tuples of all known concrete specializations is + * Any<Name>Json of type-tagged tuples of all known concrete specializations is * generated and used for fields referencing the abstract message.
  • *
  • An enum becomes a union of string literal types with the protocol names of its constants.
  • - *
  • Nested definitions are placed in a namespace named after the outer message.
  • + *
  • Nested definitions are placed in a namespace named after the outer message and keep their + * names, e.g. GroupJson.Info.
  • *
  • Types from other .proto files are imported with import type.
  • *
*/ @@ -64,6 +72,16 @@ public class TypeScriptGenerator extends AbstractTypeScriptGenerator { */ public static final String POLYMORPHIC_PREFIX = "Any"; + /** + * Suffix of the names of top-level types. + * + *

+ * The generated types describe the JSON format only. The suffix keeps the plain names free for + * types that represent the data itself. + *

+ */ + public static final String JSON_SUFFIX = "Json"; + private static final Pattern IDENTIFIER = Pattern.compile("[A-Za-z_$][A-Za-z0-9_$]*"); private final File _file; @@ -195,7 +213,7 @@ private void separate() { */ private void resolveReferences() { for (Definition def : _proto.getDefinitions()) { - _topLevelNames.add(def.getName()); + _topLevelNames.add(jsonTypeName(def)); if (hasPolymorphicType(def)) { _topLevelNames.add(polymorphicName(def)); } @@ -261,9 +279,9 @@ private void generateEnum(EnumDef def) { docComment(doc(def.getComment(), def)); List constants = def.getConstants(); if (constants.isEmpty()) { - line("export type " + def.getName() + " = never;"); + line("export type " + jsonTypeName(def) + " = never;"); } else { - line("export type " + def.getName() + " ="); + line("export type " + jsonTypeName(def) + " ="); for (int n = 0, cnt = constants.size(); n < cnt; n++) { Constant constant = constants.get(n); indentedDocComment(doc(constant.getComment(), def)); @@ -289,9 +307,9 @@ private void generateMessage(MessageDef def) { String extendsClause = extendedDef == null ? "" : " extends " + ref(extendedDef, def); List fields = jsonFields(def); if (fields.isEmpty()) { - line("export interface " + def.getName() + extendsClause + " {}"); + line("export interface " + jsonTypeName(def) + extendsClause + " {}"); } else { - line("export interface " + def.getName() + extendsClause + " {"); + line("export interface " + jsonTypeName(def) + extendsClause + " {"); boolean first = true; for (Field field : fields) { if (first) { @@ -300,20 +318,20 @@ private void generateMessage(MessageDef def) { nl(); } docComment(fieldComment(field, def)); - line(propertyName(field) + "?: " + typeExpr(field, def) + ";"); + line(propertyName(field) + (Util.isNullable(field) ? "?: " : ": ") + propertyType(field, def) + ";"); } line("}"); } if (hasPolymorphicType(def)) { separate(); - docComment("Polymorphic JSON representation of a {@link " + def.getName() + "}: a tuple of the type ID and the properties of a concrete type."); + docComment("Polymorphic JSON representation of a {@link " + jsonTypeName(def) + "}: a tuple of the type ID and the properties of a concrete type."); line("export type " + polymorphicName(def) + " = " + polymorphicType(def) + ";"); } if (!def.getDefinitions().isEmpty()) { separate(); - line("export namespace " + def.getName() + " {"); + line("export namespace " + jsonTypeName(def) + " {"); _separate = false; for (Definition inner : def.getDefinitions()) { generateDefinition(inner); @@ -496,7 +514,19 @@ private static MessageDef root(MessageDef def) { } private static String polymorphicName(Definition def) { - return POLYMORPHIC_PREFIX + def.getName(); + return POLYMORPHIC_PREFIX + jsonTypeName(def); + } + + /** + * The name of the TypeScript type describing the JSON format of the given definition. + * + *

+ * Top-level types get the {@link #JSON_SUFFIX}. Nested types keep their name, since they are + * qualified with the namespace of their (suffixed) top-level type. + *

+ */ + private static String jsonTypeName(Definition def) { + return def.getOuter() == null ? def.getName() + JSON_SUFFIX : def.getName(); } private String polymorphicType(MessageDef def) { @@ -511,6 +541,23 @@ private String polymorphicType(MessageDef def) { return alternatives.isEmpty() ? "never" : String.join(" | ", alternatives); } + /** + * The type of the property for the given field, including null if the Java + * writer emits a null value for it. + */ + private String propertyType(Field field, MessageDef context) { + String type = typeExpr(field, context); + if (!field.isRepeated() && !Util.isNullable(field) && isBytes(field.getType())) { + // Written with JsonUtil.writeBinaryOptional(), the default value is null. + return type + " | null"; + } + return type; + } + + private static boolean isBytes(Type type) { + return type instanceof PrimitiveType && ((PrimitiveType) type).getKind() == PrimitiveType.Kind.BYTES; + } + private String typeExpr(Field field, MessageDef context) { String elementType = typeExpr(field.getType(), context); if (field.isRepeated()) { @@ -621,7 +668,7 @@ private static boolean isShadowed(String topLevelName, Definition context) { } for (MessageDef scope = context.getOuter(); scope != null; scope = scope.getOuter()) { for (Definition inner : scope.getDefinitions()) { - if (inner.getName().equals(topLevelName)) { + if (jsonTypeName(inner).equals(topLevelName)) { return true; } if (hasPolymorphicType(inner) && polymorphicName(inner).equals(topLevelName)) { @@ -669,7 +716,7 @@ private static DefinitionFile fileOf(Definition def) { private static List path(Definition def) { List result = new ArrayList<>(); for (Definition current = def; current != null; current = current.getOuter()) { - result.add(0, current.getName()); + result.add(0, jsonTypeName(current)); } return result; } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/custom/explicit-types.ts b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/custom/explicit-types.ts index 05e842a2..c925b030 100644 --- a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/custom/explicit-types.ts +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/custom/explicit-types.ts @@ -2,19 +2,19 @@ // // Type definitions for the msgbuf JSON format of the protocol (types only, no runtime code). -import type { DisplayMode, Leaf } from '../test/ts/common/common'; +import type { DisplayModeJson, LeafJson } from '../test/ts/common/common'; /** * A message placed in an explicitly configured module. */ -export interface Explicit { +export interface ExplicitJson { /** * Mode. */ - mode?: DisplayMode; + mode: DisplayModeJson; /** * Leaves. */ - leaves?: Leaf[]; + leaves: LeafJson[]; } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/common/common.ts b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/common/common.ts index 2181ceae..b6b3f720 100644 --- a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/common/common.ts +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/common/common.ts @@ -11,7 +11,7 @@ /** * Display modes of a button. */ -export type DisplayMode = +export type DisplayModeJson = /** * Only the icon is shown. */ @@ -28,16 +28,16 @@ export type DisplayMode = /** * A point in the plane. */ -export interface Point { +export interface PointJson { /** * The X coordinate. */ - x?: number; + x: number; /** * The Y coordinate. */ - y?: number; + y: number; } /** @@ -45,34 +45,34 @@ export interface Point { * * Abstract type, the properties are only present in the JSON of its concrete specializations. */ -export interface Node { +export interface NodeJson { /** * The node ID. */ - id?: string; + id: string; } /** - * Polymorphic JSON representation of a {@link Node}: a tuple of the type ID and the properties of a concrete type. + * Polymorphic JSON representation of a {@link NodeJson}: a tuple of the type ID and the properties of a concrete type. */ -export type AnyNode = ['Leaf', Leaf] | ['Inner', Inner]; +export type AnyNodeJson = ['Leaf', LeafJson] | ['Inner', InnerJson]; /** * A leaf node. */ -export interface Leaf extends Node { +export interface LeafJson extends NodeJson { /** * The value. */ - value?: number; + value: number; } /** * An inner node. */ -export interface Inner extends Node { +export interface InnerJson extends NodeJson { /** * The children, written as type-tagged tuples. */ - children?: AnyNode[]; + children: AnyNodeJson[]; } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/shapes/shapes.ts b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/shapes/shapes.ts index f1206087..7c98da66 100644 --- a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/shapes/shapes.ts +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/shapes/shapes.ts @@ -5,81 +5,81 @@ /** * Shapes and button states for testing the TypeScript generator. * - *

See {@link ButtonState}, {@link Group.shapes the shapes of a group} and `nothing`.

+ *

See {@link ButtonStateJson}, {@link GroupJson.shapes the shapes of a group} and `nothing`.

* * @packageDocumentation */ -import type { Point as common_Point, DisplayMode, AnyNode } from '../common/common'; +import type { PointJson as common_PointJson, DisplayModeJson, AnyNodeJson } from '../common/common'; /** * A local point clashing with the imported one. */ -export interface Point { +export interface PointJson { /** * A coordinate pair. */ - value?: common_Point; + value?: common_PointJson; } /** * A label. */ -export interface Label { - text?: string; +export interface LabelJson { + text: string; } /** * State of a button. * - *

Refers to {@link Label}.

+ *

Refers to {@link LabelJson}.

*/ -export interface ButtonState { +export interface ButtonStateJson { /** * The label. */ - label?: string; + label: string; /** - * Whether the button is disabled, see {@link ButtonState.label} and {@link ButtonState.label the label}. + * Whether the button is disabled, see {@link ButtonStateJson.label} and {@link ButtonStateJson.label the label}. * * Code: `if (x) { y(); }`, literal: a; + labels: Record; /** * Ratings by number. */ - ratings?: Array<{ key: number; value: string }>; + ratings: Array<{ key: number; value: string }>; /** * A polymorphic reference to another file. */ - root?: AnyNode; + root?: AnyNodeJson; /** - * Local points, see {@link Point.value} and {@link common_Point.x}, inherited {@link Shape.origin}. + * Local points, see {@link PointJson.value} and {@link common_PointJson.x}, inherited {@link ShapeJson.origin}. */ - points?: Point[]; + points: PointJson[]; } /** * Concrete base class: JSON has no type information. */ -export interface Base { - name?: string; +export interface BaseJson { + name: string; } /** * Specialization of a concrete base. */ -export interface Derived extends Base { - extra?: number; +export interface DerivedJson extends BaseJson { + extra: number; } /** @@ -136,77 +141,77 @@ export interface Derived extends Base { * * Abstract type, the properties are only present in the JSON of its concrete specializations. */ -export interface Shape { +export interface ShapeJson { /** * The origin. */ - origin?: common_Point; + origin?: common_PointJson; } /** - * Polymorphic JSON representation of a {@link Shape}: a tuple of the type ID and the properties of a concrete type. + * Polymorphic JSON representation of a {@link ShapeJson}: a tuple of the type ID and the properties of a concrete type. */ -export type AnyShape = ['Rectangle', Rectangle] | ['Group', Group] | ['circle', Circle]; +export type AnyShapeJson = ['Rectangle', RectangleJson] | ['Group', GroupJson] | ['circle', CircleJson]; /** * Abstract intermediate class. * * Abstract type, the properties are only present in the JSON of its concrete specializations. */ -export interface Rounded extends Shape {} +export interface RoundedJson extends ShapeJson {} /** - * Polymorphic JSON representation of a {@link Rounded}: a tuple of the type ID and the properties of a concrete type. + * Polymorphic JSON representation of a {@link RoundedJson}: a tuple of the type ID and the properties of a concrete type. */ -export type AnyRounded = ['circle', Circle]; +export type AnyRoundedJson = ['circle', CircleJson]; /** * A circle. */ -export interface Circle extends Rounded { +export interface CircleJson extends RoundedJson { /** * The radius. */ - r?: number; + r: number; } /** * A rectangle. */ -export interface Rectangle extends Shape { - width?: number; +export interface RectangleJson extends ShapeJson { + width: number; - height?: number; + height: number; } /** * A group of shapes. */ -export interface Group extends Shape { +export interface GroupJson extends ShapeJson { /** * Contents written polymorphically. */ - shapes?: AnyShape[]; + shapes: AnyShapeJson[]; /** * Monomorphic reference to a concrete type in a hierarchy. */ - main?: Circle; + main?: CircleJson; /** * Reference to an abstract intermediate type. */ - rounded?: AnyRounded; + rounded?: AnyRoundedJson; - info?: Group.Info; + info?: GroupJson.Info; } -export namespace Group { +export namespace GroupJson { /** * A label local to groups. */ export interface Label { - kind?: Group.Label.Kind; + kind: GroupJson.Label.Kind; } export namespace Label { @@ -219,24 +224,29 @@ export namespace Group { } /** - * Nested message referencing the shadowed top-level type {@link __Label} and {@link Group.Label}. + * Nested message whose name clashes with the TypeScript name of the top-level {@link __LabelJson}. + */ + export interface LabelJson {} + + /** + * Nested message referencing the shadowed top-level type {@link __LabelJson} and {@link GroupJson.Label}. */ export interface Info { /** * The top-level label. */ - global?: __Label; + global?: __LabelJson; /** * The nested label. */ - local?: Group.Label; + local?: GroupJson.Label; } } /** * An empty enum. */ -export type Nothing = never; +export type NothingJson = never; -type __Label = Label; +type __LabelJson = LabelJson; diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/shapes/shapes.proto b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/shapes/shapes.proto index 448fe0ba..ba96ef20 100644 --- a/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/shapes/shapes.proto +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/shapes/shapes.proto @@ -71,6 +71,10 @@ message ButtonState { @Nullable Label caption; + /** Optional string, omitted when not set. */ + @Nullable + string hint; + /** Tags. */ repeated string tags; @@ -143,6 +147,10 @@ message Group extends Shape { Kind kind; } + /** Nested message whose name clashes with the TypeScript name of the top-level {@link test.ts.shapes.Label}. */ + message LabelJson { + } + /** Nested message referencing the shadowed top-level type {@link test.ts.shapes.Label} and {@link Label}. */ message Info { /** The top-level label. */ From a333f90d82a8b7b4b1d843cdd21b315136a8e403 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 15:15:35 +0200 Subject: [PATCH 188/207] Correct the polymorphic JSON format and grammar location in CLAUDE.md. Polymorphic values are written as a two-element array [typeId, {fields}], and only in hierarchies with an abstract root; a concrete root carries no type information. The grammar lives next to the generated parser in src/main/java, and the regenerated parser sources are checked in. Co-Authored-By: Claude Opus 5.5 (1M context) --- CLAUDE.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index f5276c1b..6b2ade22 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -53,7 +53,7 @@ Key source locations: - Generator entry point: `de.haumacher.msgbuf.generator.Generator` - Code generators: `de.haumacher.msgbuf.generator.MessageGenerator`, `EnumGenerator` - Other targets: Dart (`generator.dart.DartLibGenerator`, `option DartLib`), TypeScript types (`generator.ts.TypeScriptGenerator`, `-ts ` / Maven `typeScriptOutputDirectory` / `option TypeScript`; golden-file test `TestTypeScriptGenerator`, update expected files with `-Dmsgbuf.ts.update=true`) -- JavaCC grammar: `de.haumacher.msgbuf.generator/src/main/javacc/protobuf.jj` +- JavaCC grammar: `de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/parser/protobuf.jj` (next to the generated parser sources) - AST proto definition: `de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto` ## Runtime API Architecture @@ -85,7 +85,7 @@ Extensions beyond standard protobuf: - **Self-bootstrapping**: Changes to `generator/ast/proto.proto` require regenerating the AST Java classes with an existing generator, then rebuilding. Maven reactor handles this automatically. - **NoInterfaces mode**: When set, generates single classes instead of interface + impl. Changes package structure (no `impl` subpackage). Many conditionals in `MessageGenerator` depend on this flag. -- **Polymorphic JSON**: Abstract types serialize as `[type, ...fields]` arrays. Concrete types in hierarchies use same format. Monomorphic references use `writeContent()` without type info. +- **Polymorphic JSON**: In a hierarchy with an abstract root, a value is written as a two-element array `[typeId, {fields}]` (the root's final `writeTo()`). A field declared with a concrete type of such a hierarchy uses `writeContent()` and writes the plain object without type info. A hierarchy with a concrete root carries no type info at all. - **Field IDs**: Auto-synthesis starts at 1, skips manually assigned IDs, is inheritance-aware (child fields can't clash with parent IDs). Field ID 0 is reserved. - **Tests use JUnit 3 style** (`extends TestCase`) despite JUnit 4 dependency. Tests exercise generated code, not the generator itself directly. - **GWT constraint**: No Java I/O classes in `msgbuf-api`. No Java 8+ features in generated code. @@ -105,5 +105,5 @@ Maven plugin integration tests: `msgbuf-generator-maven-plugin/src/it/` - Java 11+ required (`maven.compiler.source/target = 11`) - Generated code must be GWT-compatible (no `java.io` usage in `msgbuf-api`) -- Generator uses JavaCC — regenerate parser after grammar changes to `protobuf.jj` +- Generator uses JavaCC — the `javacc-maven-plugin` regenerates the parser into `src/main/java` during the build after grammar changes to `protobuf.jj`; the generated parser sources are checked in and must be committed with the grammar change - Different licenses: API is Apache-2.0, Generator is GPL-3.0-or-later (generated code is not GPL-encumbered) From b3d631d28e38378613f7ab5f422bc0847a3e4e76 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 15:15:35 +0200 Subject: [PATCH 189/207] Add the msgbuf-workflow skill for Claude Code sessions. Adapted from the VAlbum2 working method: issue intake, reproducing with a .proto first, agent briefs, probe reviews across inheritance, nesting, cross-file extension and the option matrix, and a verification gate that treats the checked-in generated test sources and the TypeScript outputs as golden files. Records the wire-format doctrines and the traps found while building the TypeScript target. Co-Authored-By: Claude Opus 5.5 (1M context) --- .claude/skills/msgbuf-workflow/SKILL.md | 248 ++++++++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 .claude/skills/msgbuf-workflow/SKILL.md diff --git a/.claude/skills/msgbuf-workflow/SKILL.md b/.claude/skills/msgbuf-workflow/SKILL.md new file mode 100644 index 00000000..fbe92bfd --- /dev/null +++ b/.claude/skills/msgbuf-workflow/SKILL.md @@ -0,0 +1,248 @@ +--- +name: msgbuf-workflow +description: The working method for developing msgbuf — issue intake and triage, reproducing with a .proto first, sub-agent briefs, adversarial probe reviews composing generator features, the verification gate (Maven build, regenerated test sources as golden files, TypeScript golden files and tsc), branch/PR/commit discipline, and the wire-format and generated-code doctrines. Load at the start of any session doing feature or bug work on this repository. +--- + +# The msgbuf working method + +This skill is the meta-knowledge of how a session on this repository should run. It complements, +never duplicates, `CLAUDE.md` (build facts, architecture, gotchas) and `README.md` (the public +documentation of the `.proto` syntax, options and targets). Read both first. The GitHub issue +tracker at `msgbuf/msgbuf` **is** the work queue; `CHANGELOG.md` is the record of what shipped. + +## 1. The operating loop + +Work is a pipeline, not a pile: + +1. **Intake**: user reports (chat or GitHub issues) and the open issues at `msgbuf/msgbuf` + (`gh issue list -R msgbuf/msgbuf`). Bugs outrank queued features; a generator crash or + uncompilable generated code outranks everything. Triage every new issue with a diagnosis + comment *before* fixing. Labels are the GitHub defaults (`bug`, `enhancement`, `documentation`, …). +2. **Reproduce before dispatching.** Almost every report reduces to a `.proto` file. Write it, + run the built generator on it in a scratch directory, and compile or run the output: + + ```bash + J=$(ls $PWD/de.haumacher.msgbuf.generator/target/msgbuf-generator-*-full.jar) + java -jar $J -out /out /repro.proto # add -ts for the TypeScript target + ``` + + Know whether the problem is in the parser, the resolution/specialization stage, ID synthesis or + one code generator (§ "Generator Pipeline" in CLAUDE.md), and whether it is a real bug, an + already-fixed one, or your own probe error before an agent burns tokens. If the main tree is + agent-owned, reproduce in a git worktree (`git worktree add --detach /repro main`), + never in the live tree. +3. **Dispatch** one sub-agent per coherent package (§2), or do it yourself when the package is + small. msgbuf has one toolchain and one reactor, so parallel work needs separate worktrees (§3). +4. **Review with a novel probe** (§4). Non-negotiable. +5. **Gate** (§5), **commit and open or update the PR** (§6), close the issue with the fixing + commit or PR plus a summary comment naming the regression test. +6. **Before finishing: `gh issue list -R msgbuf/msgbuf`.** Anything you find and defer becomes an + issue (like #16–#21, found while building the TypeScript target), so a crashed session loses + nothing. + +Track packages with TaskCreate/TaskUpdate; keep statuses honest (in_progress on dispatch, +completed only after the commit is pushed). + +## 2. Agent briefs — what makes them work + +Use Opus for generator and runtime packages; Sonnet only for mechanical chores (regenerating, +README tables). Run in background; you'll be notified. A good brief contains, in order: + +- **Grounding**: "Read CLAUDE.md and README.md. Study ." Name the module + (`de.haumacher.msgbuf` runtime, `de.haumacher.msgbuf.generator`, the Maven plugin) and whether + `ast/proto.proto` or `parser/protobuf.jj` is in scope — both have regeneration consequences (§5). +- **The task as design intent**, with the load-bearing decisions already made: what the wire + format carries, what the generated API looks like, which options (`NoInterfaces`, `NoJson`, + `SharedGraph`, …) the change must respect, what the generator rejects with an error instead of + emitting broken code. Quote the user's own words where they designed the feature. +- **User fixtures embedded verbatim**: the `.proto` from the report, the JSON the user expects, the + compiler error they got. They become the regression test. +- **Explicit acceptance tests**: which test package under `src/test/java/test/` gets the new + `.proto` and the JUnit 3 test (`extends TestCase`, see CLAUDE.md); JSON/binary/XML round-trips + (write → read → equal) for every format the options leave enabled; exact expected JSON strings + where the format is the point. +- **The build discipline block** (the point is not wasting runs, not avoiding them): + - The edit loop runs the **owning module's targeted test**: + `mvn -q -pl de.haumacher.msgbuf.generator -am test -Dtest=TestHierarchy -Dsurefire.failIfNoSpecifiedTests=false`. + `-am` is needed unless the current `msgbuf-api` SNAPSHOT is installed in `~/.m2`. + - A generator change is not tested until the checked-in test sources are regenerated (§5) — + they are compiled from the repository, not generated by the build. + - The full `mvn clean install` runs at the end, before the report. A run whose inputs did not + change is not repeated "to be sure". Batch independent lookups in one call. +- **The standing rules block**: ALL existing tests green; never hand-edit generated code + (regenerate it: test sources, the AST classes from `proto.proto`, the JavaCC parser); + generated code and `msgbuf-api` stay GWT-compatible (no `java.io` Reader/Writer, Java language + level of the root pom); do NOT commit; **nothing half-done — cut whole items only and report + every cut**; a new generator error message names the file, the definition and the fix. +- **Ask for a report**: mechanism chosen and why, alternatives rejected, cuts, which checked-in + generated files changed and why, test count before/after. A vague report predicts a vague delivery. + +**Reworks go back to the same agent** via SendMessage with the failing probe and the demand: +*fix it generally, not to the probe*. If several rework rounds fail, question the architecture, +not the tests. + +**Stalled agents**: if a background agent's transcript goes quiet, check for a running `mvn` or +`java` process first (a long build is not a stall), then nudge-resume via SendMessage ("Resume +exactly where you left off: "). If it stays frozen, take the remainder over; +its uncommitted work is usually further along than its last message suggests (`git status`, run +its tests before redoing anything). + +**Crash recovery**: the crashed session's transcript is +`~/.claude/projects/-home-haui-devel-msgbuf/.jsonl`, sub-agent transcripts are in +`/subagents/`. Pull the last `Agent` tool_use out of the session transcript (that is the +brief, verbatim), check the tree (`git status`, `mvn -q compile`), and re-dispatch with a resume +preamble stating what exists and what compiles. Check `gh issue list` — reports filed during the +crash are untriaged. + +## 3. Concurrency — the rules + +- **Never let two agents edit the same file.** When parallelizing, write an explicit FILE BOUNDARY + paragraph into *both* briefs ("do not touch X, Y, Z; if you must, STOP and report"). +- **Shared hot spots have one owner per round**: `MessageGenerator.java` (most features touch it), + `ast/proto.proto` (regenerates the AST every generator class uses), `parser/protobuf.jj` + (regenerates the parser), and the checked-in test sources (a regeneration rewrites many files). +- **Concurrent Maven runs in one tree collide** on `target/` and on the `~/.m2` install of the + same SNAPSHOT. A second agent gets its own worktree (`git worktree add -b + /wt-x main`, run from this repo) and uses `mvn verify`, never `install`, so it cannot + overwrite the artifacts the main tree builds against. +- A commit made while an agent has uncommitted work in the tree must be **selective** + (`git add `). +- **A merge is not gated by the commits it merges.** Run the full gate (§5) on the merged tree — + generated code and generator changes are exactly where merges break. + +## 4. The probe review (the quality mechanism) + +After a delivery reports done and before committing: **write a `.proto` the agent never saw**, +composing the new feature with existing ones: inheritance three levels deep with an abstract +intermediate, nested messages and enums, cross-file `import` and `extends`, `@Nullable`, +`repeated` and `map` of the new construct, reserved-word names in backticks, and the option +matrix (`NoInterfaces`, `NoJson`/`NoBinary`/`NoXml`, `NoReflection`, `NoListener`, `NoVisitor`, +`SharedGraph`, `OpenWorld`). Generate, compile, round-trip. Good probes ask "is the mechanism +general?" not "does the happy path work?". Keep passing probes as permanent test packages. + +**Expect your own probes to be wrong first.** The traps seen so far: + +- **The generator derives its output root from the `package` declaration** when `-out` is missing: + the test protos live in `test//` but declare `package test..data;`, so running the jar on + them without `-out` writes a stray `src/test/test/` tree. Always pass `-out`. +- **A run with `-Dmsgbuf.ts.update=true` is not a test run** — it rewrites the TypeScript golden + files and then passes by construction. Rerun without the flag, and review the golden diff. +- **`mvn -pl de.haumacher.msgbuf.generator` alone fails to resolve `msgbuf-api:…-SNAPSHOT`** unless it + is installed — use `-am`, and then `-Dsurefire.failIfNoSpecifiedTests=false` with `-Dtest=…`. +- **Stale jar**: `target/msgbuf-generator-*-full.jar` is whatever the last `install`/`package` built, + possibly on another branch. Rebuild before probing a change. +- **A green unit build does not cover the plugin integration test**: `-Prun-its` runs it, and + `simple-it` is the archetype template calling a non-existent `touch` goal (#18) — it fails on + `main` too. Report it as known, don't chase it. +- **CLAUDE.md is not always right about the wire format**: polymorphic values are written as + `[typeId, {fields}]` (a two-element array whose second element is the object), and only when the + hierarchy root is abstract; references to a concrete type use `writeContent()` without a tag. + Check `MessageGenerator` (`writeTo`, `isMonomorphicReferenceToTypeInPolymorphicHierarchy`) + before asserting a format. +- **`gh pr view ` / `gh pr edit ` fail** with a GraphQL "Projects (classic) is being + deprecated" error. Use `gh pr view --json …` for reading and `gh api -X PATCH + repos/msgbuf/msgbuf/pulls/ -F body=@file` for editing. +- **`gh pr checkout` names the local branch differently** from the PR head, so a plain `git push` + is refused. Push with `git push origin HEAD:`. +- **A push can be rejected with a transient 403** ("Permission to msgbuf/msgbuf.git denied"). Report + it; on the user's request, retry once before suspecting credentials. +- **The Bash tool resets its working directory between calls.** Use absolute paths; never + `git add -A` after a relative `cd`. + +When a probe legitimately fails: send it back (§2). Small, deeper defects found on the way get +fixed with a regression test; unrelated ones become issues. Two classics to stay paranoid about: +generated code that does not compile for some option combination, and a silent change of the wire +format (§7). + +## 5. The verification gate (before every commit) + +```bash +mvn clean install # api → generator → plugin, all unit tests + +# If generator output changed: regenerate every checked-in test source and review the diff. +J=$(ls $PWD/de.haumacher.msgbuf.generator/target/msgbuf-generator-*-full.jar) # absolute, before the cd +cd de.haumacher.msgbuf.generator +for p in $(find src/test/java -name '*.proto'); do java -jar $J -out src/test/java $p; done +git status --short # every changed file must be explained by the change +cd .. && mvn clean install # the regenerated sources compile and pass +``` + +- **The checked-in generated test sources are golden files.** On `main`, regenerating them yields + zero diff. The loop prints `ERROR: Map types not supported in XML: …` (five times) and a + `Duplicate index '1' for 'RUNNING' and 'STARTED'` notice for the existing test protos — expected, + not a failure. After a generator change, the diff of `src/test/java/test/**` *is* the review of the + generated code: an unexplained change is a regression. +- **AST change** (`ast/proto.proto`): regenerate the AST classes with the previous generator + (`java -jar $J -out src/main/java src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto`), + then rebuild. The build does not do this for you (#23; CLAUDE.md still claims otherwise). +- **Grammar change** (`parser/protobuf.jj`, next to the parser sources): the JavaCC plugin + regenerates the parser into `src/main/java` during the build; the regenerated parser files are + checked in and ride the same commit. +- **TypeScript target**: `TestTypeScriptGenerator` compares against + `src/test/resources/ts/expected`; update with `-Dmsgbuf.ts.update=true`, then review the diff and + rerun without the flag. Type-check the golden files plus a usage file with `@ts-expect-error` + negative cases in the scratchpad: + `npx -y -p typescript tsc --strict --noEmit --isolatedModules --verbatimModuleSyntax --moduleResolution bundler --module esnext --target es2020 `. +- **Maven plugin changes**: also run `mvn install -Prun-its -pl msgbuf-generator-maven-plugin` + (known failure #18 until fixed). +- The Eclipse plugin (`de.haumacher.msgbuf.eclipse`, `de.haumacher.msgbuf.feature`) is not in + the reactor; changes there need a separate Eclipse/PDE build and are rare. + +All green or no commit. Never trust a green result from a tree with uncommitted foreign edits; +check `git status` first. When reporting, give the numbers (tests per module) and say what was +*not* run — the user asks. + +## 6. Branches, commits, PRs, releases + +- **Issue work goes through a branch and a PR** (`feature/issue--`, `fix/issue--` + in `msgbuf/msgbuf`, as for #12–#14), `Closes #` in the PR body. Small doc and chore fixes + may go straight to `main` when the user says so. External contributions arrive as PRs from forks. +- **House style**: an imperative one-line title stating the change, then a paragraph of the why + (never a bullet changelog), ending with the Co-Authored-By line from the harness rules. + Regenerated files ride the same commit as the change that produced them. +- **`CHANGELOG.md`**: every user-visible change gets an entry under the next version (the current + SNAPSHOT), in the existing sections (New Features, Bug Fixes). README documents every new + syntax element, option and generator switch. +- **PR descriptions** stay true to the branch: when a follow-up commit changes behavior, update the + description in the same step (§4 for the `gh` workaround). +- **The agents don't commit; you do**, after review. Pushing and force-pushing a shared branch are + the user's call; a history rewrite of a PR branch others may have checked out needs explicit consent. +- **Releases are the user's**: `mvn release:clean release:prepare` / `release:perform` + (HOWTO-RELEASE.md) publish to Maven Central. Never run them, never edit the version numbers the + release plugin manages. + +## 7. Wire-format and generated-code doctrines (enforce in every brief and review) + +- **The wire formats are a contract with deployed peers.** JSON, binary and XML written by one + msgbuf version are read by another (TopLogic servers and clients, Dart and TypeScript consumers). + A change in what a generated writer emits is a breaking change: it needs an explicit decision, + a README and CHANGELOG note, and readers that still accept the old form. Readers stay lenient + (missing properties take defaults). +- **All targets describe one format.** The Java writer is the reference; the Dart and TypeScript + targets must describe exactly what it writes (property names = `*__PROP` constants, enum + protocol names, nullable fields omitted, polymorphic tuples). Verify against the Java generator, + not against the docs. +- **Generated code must compile for every option combination** and stay GWT-compatible: no + `java.io` Reader/Writer in `msgbuf-api` or generated code, no features beyond the language level + of the root pom, no dependencies beyond `msgbuf-api`. +- **The generator rejects, it doesn't emit garbage.** Invalid input gets an error naming the + file and definition (see #16, #21 for the failure mode to avoid: a crash or uncompilable output). +- **Names are honest.** Generated and internal names say what a thing is (the TypeScript types are + `…Json` because they describe the JSON format, not the data). The user will notice a name that + claims more than it delivers. +- **Licenses**: `msgbuf-api` is Apache-2.0, the generator GPL-3.0-or-later, generated code is + unencumbered. Generated code may only depend on `msgbuf-api`; don't copy generator code into + templates of generated code. +- **Everything generic**: a fix shaped like the bug report is not done. It must hold for nested, + inherited, cross-file and option-varied variants of the reported case (the probe of §4). + +## 8. Working with this user + +The user is the author of msgbuf, an expert in Java, code generation and software architecture, +and a main downstream consumer (TopLogic). They review sharply and ask for evidence: "did you run +the tests???" is answered with the command, the counts per module, and what was not run — never +with an unqualified "yes". Their design remarks are usually complete (e.g. naming the generated +TypeScript types after what they are); restate the design crisply, adopt it, and credit it in the +commit message. Answer questions with the mechanism first, then the recommendation. When they +overrule a suggestion ("keep one PR"), follow it without relitigating. From a0fafc9a8ad79fcf25f75dc03b12eba822d6ba0b Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 15:27:11 +0200 Subject: [PATCH 190/207] Deploy releases to Maven Central from a GitHub workflow on tag push. Releasing required a local `release:perform` with the Central Portal token and the GPG key on the maintainer's machine. `release:prepare` already pushes the `msgbuf-api-` tag, so a workflow triggered by that tag now does the perform half. It checks the tag against the project version, builds and signs the tagged sources and deploys them through the central-publishing-maven-plugin. The credentials come from repository secrets. A manual run builds and signs without deploying, to check the secrets before the first release. maven-gpg-plugin 1.5 could not sign non-interactively, so it is upgraded to 3.2.7, which reads MAVEN_GPG_PASSPHRASE and still falls back to the gpg-agent for local releases. Co-Authored-By: Claude Opus 5.5 --- .claude/skills/msgbuf-workflow/SKILL.md | 7 ++- .github/workflows/release.yml | 80 +++++++++++++++++++++++++ HOWTO-RELEASE.md | 38 ++++++++++-- pom.xml | 8 ++- 4 files changed, 121 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.claude/skills/msgbuf-workflow/SKILL.md b/.claude/skills/msgbuf-workflow/SKILL.md index fbe92bfd..a55cdb48 100644 --- a/.claude/skills/msgbuf-workflow/SKILL.md +++ b/.claude/skills/msgbuf-workflow/SKILL.md @@ -208,9 +208,10 @@ check `git status` first. When reporting, give the numbers (tests per module) an description in the same step (§4 for the `gh` workaround). - **The agents don't commit; you do**, after review. Pushing and force-pushing a shared branch are the user's call; a history rewrite of a PR branch others may have checked out needs explicit consent. -- **Releases are the user's**: `mvn release:clean release:prepare` / `release:perform` - (HOWTO-RELEASE.md) publish to Maven Central. Never run them, never edit the version numbers the - release plugin manages. +- **Releases are the user's**: `mvn release:clean release:prepare` pushes a `msgbuf-api-` + tag, and the tag push runs `.github/workflows/release.yml`, which deploys to Maven Central + (HOWTO-RELEASE.md). Never run `release:*`, never push a `msgbuf-api-*` tag, never edit the + version numbers the release plugin manages. ## 7. Wire-format and generated-code doctrines (enforce in every brief and review) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..c05e4383 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,80 @@ +# Deploys a release to Maven Central when a release tag is pushed. +# +# The tag is created by `mvn release:clean release:prepare` (tag format msgbuf-api-, +# see tagNameFormat of the maven-release-plugin in pom.xml), which also pushes it. This workflow +# then builds the tagged sources, signs the artifacts and publishes them through the Central +# Portal (central-publishing-maven-plugin) - the part `mvn release:perform` did before. +# +# Required repository secrets: +# CENTRAL_USERNAME - user name of a Central Portal user token (https://central.sonatype.com/account) +# CENTRAL_PASSWORD - password of that user token +# GPG_PRIVATE_KEY - ASCII-armored secret signing key (gpg --armor --export-secret-keys ) +# GPG_PASSPHRASE - passphrase of that key +# +# A manual run (workflow_dispatch) builds and signs the current branch without deploying, +# to check the build and the signing secrets before cutting a release. + +name: Release to Maven Central + +on: + push: + tags: + - 'msgbuf-api-*' + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: release-${{ github.ref }} + cancel-in-progress: false + +jobs: + release: + runs-on: ubuntu-latest + timeout-minutes: 60 + steps: + - name: Check out + uses: actions/checkout@v5 + + - name: Set up JDK, Maven settings and signing key + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: '21' + cache: maven + server-id: central + server-username: CENTRAL_USERNAME + server-password: CENTRAL_PASSWORD + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + + - name: Check that the tag matches the project version + if: github.event_name == 'push' + run: | + version=$(mvn -B -q -N help:evaluate -Dexpression=project.version -DforceStdout) + tag="${GITHUB_REF_NAME}" + echo "Tag: ${tag}, project version: ${version}" + if [ "${tag}" != "msgbuf-api-${version}" ]; then + echo "::error::Tag ${tag} does not match project version ${version} (expected msgbuf-api-${version})." + exit 1 + fi + case "${version}" in + *-SNAPSHOT) + echo "::error::Refusing to release snapshot version ${version}." + exit 1 + ;; + esac + + - name: Build and sign (dry run) + if: github.event_name != 'push' + run: mvn -B -Possrh clean verify + env: + MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + + - name: Deploy to Maven Central + if: github.event_name == 'push' + run: mvn -B -Possrh clean deploy + env: + CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }} + CENTRAL_PASSWORD: ${{ secrets.CENTRAL_PASSWORD }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} diff --git a/HOWTO-RELEASE.md b/HOWTO-RELEASE.md index 060c13d9..f804cc66 100644 --- a/HOWTO-RELEASE.md +++ b/HOWTO-RELEASE.md @@ -6,18 +6,44 @@ mvn release:clean release:prepare ``` +This sets the release version, commits, creates the tag `msgbuf-api-`, sets the next +snapshot version, commits again and pushes both commits and the tag. + ## Release to Maven Central -``` -mvn release:perform -``` +Pushing the tag starts the GitHub workflow `.github/workflows/release.yml` ("Release to Maven +Central"). It checks that the tag matches the project version, builds the tagged sources, signs the +artifacts and publishes them through the Central Portal. It waits until the deployment is +published. Follow it in the repository's Actions tab. + +Do **not** run `mvn release:perform` in addition: the version would be deployed twice, and the +second deployment is rejected by Maven Central. +The workflow needs these repository secrets (Settings → Secrets and variables → Actions): + +| Secret | Content | +|--------------------|-------------------------------------------------------------------------| +| `CENTRAL_USERNAME` | User name of a Central Portal user token (central.sonatype.com → Account → Generate User Token) | +| `CENTRAL_PASSWORD` | Password of that user token | +| `GPG_PRIVATE_KEY` | ASCII-armored signing key: `gpg --armor --export-secret-keys ` | +| `GPG_PASSPHRASE` | Passphrase of that key | + +To check the build and the signing secrets without releasing, run the workflow manually (Actions → +Release to Maven Central → Run workflow): it builds and signs the selected branch but does not +deploy. + +A failed deployment can be repeated by re-running the workflow for the tag, as long as nothing was +published yet. ## Signing -Artifacts are GPG signed only in the `ossrh` profile. `release:perform` activates it automatically (see -`releaseProfiles` of the `maven-release-plugin`), so a regular `mvn install` does not require a GPG key. -For a manual deployment to Maven Central, activate the profile explicitly: +Artifacts are GPG signed only in the `ossrh` profile. The release workflow and `release:perform` +activate it, so a regular `mvn install` does not require a GPG key. The key passphrase is read from +the environment variable `MAVEN_GPG_PASSPHRASE` if set, otherwise the gpg-agent is asked. + +For a manual deployment to Maven Central (e.g. if GitHub Actions is unavailable), check out the +tag and activate the profile explicitly. This needs the `central` server credentials in +`~/.m2/settings.xml`: ``` mvn deploy -Possrh diff --git a/pom.xml b/pom.xml index 385d0512..39d659b6 100644 --- a/pom.xml +++ b/pom.xml @@ -140,8 +140,10 @@ ossrh @@ -151,7 +153,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.5 + 3.2.7 sign-artifacts From 301729826216186fc0e4c8342b6e39ebf805a10a Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 15:32:49 +0200 Subject: [PATCH 191/207] Resolve the defining file of nested definitions to fix polymorphic hierarchies nested in messages. Only top-level definitions have their file set, and `getFile() == null` marks a definition as nested for name qualification. The specialization and OpenWorld logic used `getFile()` to mean "the file this definition is declared in". So an abstract message nested in another message crashed the generator with a NullPointerException (#16), and the "same file" filter for local subtypes worked for nested definitions only by accident. `Util.definingFile()` walks up to the top-level definition and is now used at every such site; it replaces a private copy in the TypeScript generator. Probes found two more defects on the same path. JSON and XML readers of a top-level root referenced nested subtypes by their simple names, which did not compile. An extension file whose only extension of an OpenWorld root is nested did not get the implied NoBinary. Closes #16 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 7 + .../generator/AbstractMessageGenerator.java | 4 +- .../msgbuf/generator/CodeConvention.java | 4 +- .../haumacher/msgbuf/generator/Generator.java | 27 +- .../msgbuf/generator/MessageGenerator.java | 6 +- .../msgbuf/generator/common/Util.java | 19 + .../generator/plugins/XmlStreamingPlugin.java | 4 +- .../generator/ts/TypeScriptGenerator.java | 21 +- .../src/test/java/test/nested/TestNested.java | 303 +++ .../test/java/test/nested/TestNestedDoc.java | 116 ++ .../test/java/test/nested/data/Animal.java | 92 + .../test/java/test/nested/data/Holder.java | 127 ++ .../test/java/test/nested/data/Level1.java | 471 +++++ .../src/test/java/test/nested/data/Outer.java | 357 ++++ .../test/java/test/nested/data/Triangle.java | 71 + .../src/test/java/test/nested/data/Zoo.java | 254 +++ .../test/nested/data/impl/Animal_Impl.java | 253 +++ .../test/nested/data/impl/Holder_Impl.java | 538 ++++++ .../test/nested/data/impl/Level1_Impl.java | 1682 +++++++++++++++++ .../test/nested/data/impl/Outer_Impl.java | 1301 +++++++++++++ .../test/nested/data/impl/Triangle_Impl.java | 246 +++ .../java/test/nested/data/impl/Zoo_Impl.java | 974 ++++++++++ .../src/test/java/test/nested/doc/Doc.java | 522 +++++ .../src/test/java/test/nested/doc/Figure.java | 64 + .../src/test/java/test/nested/doc/doc.proto | 32 + .../java/test/nested/doc/impl/Doc_Impl.java | 1640 ++++++++++++++++ .../test/nested/doc/impl/Figure_Impl.java | 217 +++ .../src/test/java/test/nested/note/Note.java | 144 ++ .../java/test/nested/note/impl/Note_Impl.java | 638 +++++++ .../src/test/java/test/nested/note/note.proto | 13 + .../test/java/test/nested/owbase/Events.java | 182 ++ .../test/nested/owbase/impl/Events_Impl.java | 658 +++++++ .../test/java/test/nested/owbase/owbase.proto | 19 + .../java/test/nested/owcount/CountEvent.java | 52 + .../test/nested/owcount/OwcountTypes.java | 19 + .../nested/owcount/impl/CountEvent_Impl.java | 181 ++ .../java/test/nested/owcount/owcount.proto | 8 + .../java/test/nested/owext/OwextTypes.java | 19 + .../test/java/test/nested/owext/Patches.java | 89 + .../test/nested/owext/impl/Patches_Impl.java | 306 +++ .../test/java/test/nested/owext/owext.proto | 17 + .../src/test/java/test/nested/shapes.proto | 100 + .../de.haumacher.msgbuf.data.TypeRegistration | 2 + 43 files changed, 11768 insertions(+), 31 deletions(-) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNested.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNestedDoc.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Animal.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Holder.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Level1.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Outer.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Triangle.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Zoo.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Animal_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Holder_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Level1_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Outer_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Triangle_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Zoo_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/Doc.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/Figure.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/doc.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/impl/Doc_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/impl/Figure_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/note/Note.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/note/impl/Note_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/note/note.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/Events.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/impl/Events_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/owbase.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/CountEvent.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/OwcountTypes.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/impl/CountEvent_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/owcount.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/OwextTypes.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/Patches.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/impl/Patches_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/owext.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/shapes.proto diff --git a/CHANGELOG.md b/CHANGELOG.md index 236509e0..0bc58689 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,13 @@ - **File documentation comment**: A doc comment before the `syntax` or `package` declaration is kept as the documentation of the `.proto` file (`DefinitionFile.comment`) and emitted as TSDoc `@packageDocumentation` of the TypeScript module. +### Bug Fixes +- **Nested polymorphic hierarchies** (#16): An abstract message nested in another message no longer crashes the + generator with a `NullPointerException`. Nested sub-messages of a top-level abstract message are referenced by + their qualified names in the generated JSON and XML readers (previously uncompilable). For `option OpenWorld`, the + "same file" test for local subtypes and the implied `NoBinary` of extension files now also hold for nested + definitions. + ## 1.2.1 ### Bug Fixes diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/AbstractMessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/AbstractMessageGenerator.java index 2436e5ba..c9cd9723 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/AbstractMessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/AbstractMessageGenerator.java @@ -71,7 +71,7 @@ protected String qImplName(MessageDef def) { protected static List concreteSpecializations(MessageDef def) { ArrayList result = new ArrayList<>(); - addConcreteSpecializations(result, def, def.getFile()); + addConcreteSpecializations(result, def, Util.definingFile(def)); return result; } @@ -95,7 +95,7 @@ protected static List localSpecializations(MessageDef def, Definitio return def.getSpecializations(); } return def.getSpecializations().stream() - .filter(s -> s.getFile() == originFile) + .filter(s -> Util.definingFile(s) == originFile) .collect(Collectors.toList()); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java index 588fd329..46c6abe4 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java @@ -279,7 +279,9 @@ public static String jsonTypeConstant(MessageDef def) { } public static String jsonTypeConstantRef(MessageDef def) { - return typeName(def) + "." + jsonTypeConstant(def); + // A nested specialization is not in scope by its simple name in the code of its generalization. + String typeRef = def.getFile() == null ? qTypeName(def) : typeName(def); + return typeRef + "." + jsonTypeConstant(def); } public static String mkBinaryTypeConstant(MessageDef def) { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java index bac207a2..194879f4 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java @@ -312,17 +312,29 @@ private void propagateOpenWorldOptions(DefinitionFile file) { // Already an OpenWorld file, options already set return; } - for (Definition def : file.getDefinitions()) { + if (extendsOpenWorldFromOtherFile(file, file.getDefinitions())) { + // Extension file inherits NoBinary from OpenWorld base + file.getOptions().put("NoBinary", Flag.create().setValue(true)); + } + } + + private static boolean extendsOpenWorldFromOtherFile(DefinitionFile file, List definitions) { + for (Definition def : definitions) { if (def instanceof MessageDef) { MessageDef msg = (MessageDef) def; MessageDef extended = msg.getExtendedDef(); - if (extended != null && extended.getFile() != file && Util.getFlag(extended.getFile(), "OpenWorld")) { - // Extension file inherits NoBinary from OpenWorld base - file.getOptions().put("NoBinary", Flag.create().setValue(true)); - return; + if (extended != null) { + DefinitionFile extendedFile = Util.definingFile(extended); + if (extendedFile != file && Util.getFlag(extendedFile, "OpenWorld")) { + return true; + } + } + if (extendsOpenWorldFromOtherFile(file, msg.getDefinitions())) { + return true; } } } + return false; } private void resolveImports(DefinitionFile file, File sourceFile) throws IOException, ParseException { @@ -491,8 +503,9 @@ private List findCrossFileExtensions(DefinitionFile file) { private void collectCrossFileExtensions(MessageDef def, DefinitionFile file, List result) { MessageDef extended = def.getExtendedDef(); - if (extended != null && extended.getFile() != file) { - if (Util.getFlag(extended.getFile(), "OpenWorld")) { + DefinitionFile extendedFile = extended == null ? null : Util.definingFile(extended); + if (extendedFile != null && extendedFile != file) { + if (Util.getFlag(extendedFile, "OpenWorld")) { if (!def.isAbstract()) { result.add(def); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index d3d7abd4..853c60f6 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -17,6 +17,7 @@ import de.haumacher.msgbuf.binary.DataType; import de.haumacher.msgbuf.generator.ast.CustomType; import de.haumacher.msgbuf.generator.ast.Definition; +import de.haumacher.msgbuf.generator.ast.DefinitionFile; import de.haumacher.msgbuf.generator.ast.EnumDef; import de.haumacher.msgbuf.generator.ast.Field; import de.haumacher.msgbuf.generator.ast.MapType; @@ -2345,11 +2346,12 @@ private String getOpenWorldRoot() { private boolean isCrossFileExtension() { MessageDef gen = getAbstractGeneralization(); if (gen == null) return false; - return gen.getFile() != _def.getFile() && Util.getFlag(gen.getFile(), "OpenWorld"); + DefinitionFile genFile = Util.definingFile(gen); + return genFile != Util.definingFile(_def) && Util.getFlag(genFile, "OpenWorld"); } private List localSpecializations(MessageDef def) { - return localSpecializations(def, _def.getFile()); + return localSpecializations(def, Util.definingFile(_def)); } } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/Util.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/Util.java index f2ace617..2f0da893 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/Util.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/Util.java @@ -11,6 +11,7 @@ import de.haumacher.msgbuf.generator.CodeConvention; import de.haumacher.msgbuf.generator.ast.CustomType; import de.haumacher.msgbuf.generator.ast.Definition; +import de.haumacher.msgbuf.generator.ast.DefinitionFile; import de.haumacher.msgbuf.generator.ast.EnumDef; import de.haumacher.msgbuf.generator.ast.Field; import de.haumacher.msgbuf.generator.ast.Flag; @@ -45,6 +46,24 @@ public static String stringContent(String stringLiteral) { return stringLiteral.substring(1, stringLiteral.length() - 1).replaceAll("\\\\(.)", "$1"); } + /** + * The file the given definition is declared in. + * + *

+ * Only top-level definitions have a direct reference to their file ({@link Definition#getFile()} + * is null for nested definitions, which marks them as nested for name + * qualification). For a nested definition, the file of its top-level outer definition is + * returned. + *

+ */ + public static DefinitionFile definingFile(Definition def) { + Definition current = def; + while (current.getOuter() != null) { + current = current.getOuter(); + } + return current.getFile(); + } + public static String toString(Definition def) { MessageDef outer = def.getOuter(); if (outer == null) { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java index 29ab65c0..bac45eef 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java @@ -442,7 +442,9 @@ private void readPrimitiveXmlElement(Field field) { } String xmlTypeNameRef(MessageDef def) { - return implName(def) + "." + xmlTypeNameConstant(def); + // A nested specialization is not in scope by its simple name in the code of its generalization. + String implRef = def.getFile() == null ? qImplName(def) : implName(def); + return implRef + "." + xmlTypeNameConstant(def); } }; } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java index 16bca762..83b71d09 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java @@ -534,7 +534,7 @@ private String polymorphicType(MessageDef def) { for (MessageDef specialization : Util.concreteTransitiveSpecializations(def)) { alternatives.add("[" + stringLiteral(MsgBufJsonProtocol.typeId(specialization)) + ", " + ref(specialization, def) + "]"); } - if (Util.getFlag(fileOf(root(def)), "OpenWorld")) { + if (Util.getFlag(Util.definingFile(root(def)), "OpenWorld")) { // Extension types from other modules. alternatives.add("[string, " + ref(def, def) + "]"); } @@ -633,13 +633,13 @@ private static String primitiveType(PrimitiveType.Kind kind) { */ private String ref(Definition target, Definition context) { List path = path(target); - return ref(fileOf(target), path, context); + return ref(Util.definingFile(target), path, context); } private String polymorphicRef(MessageDef target, Definition context) { List path = path(target); path.set(path.size() - 1, polymorphicName(target)); - return ref(fileOf(target), path, context); + return ref(Util.definingFile(target), path, context); } private String ref(DefinitionFile file, List path, Definition context) { @@ -698,21 +698,6 @@ private String importBinding(DefinitionFile file, String name) { return binding; } - /** - * The file containing the given definition. - * - *

- * Only top-level definitions have a direct reference to their file. - *

- */ - private static DefinitionFile fileOf(Definition def) { - Definition current = def; - while (current.getOuter() != null) { - current = current.getOuter(); - } - return current.getFile(); - } - private static List path(Definition def) { List result = new ArrayList<>(); for (Definition current = def; current != null; current = current.getOuter()) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNested.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNested.java new file mode 100644 index 00000000..a9752731 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNested.java @@ -0,0 +1,303 @@ +/* + * Copyright (c) 2026 Bernhard Haumacher et al. All Rights Reserved. + */ +package test.nested; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import de.haumacher.msgbuf.binary.OctetDataReader; +import de.haumacher.msgbuf.binary.OctetDataWriter; +import de.haumacher.msgbuf.io.StringR; +import de.haumacher.msgbuf.json.JsonReader; +import de.haumacher.msgbuf.xml.XmlSerializable; +import junit.framework.TestCase; +import test.nested.data.Animal; +import test.nested.data.Holder; +import test.nested.data.Level1; +import test.nested.data.Level1.Level2; +import test.nested.data.Outer; +import test.nested.data.Triangle; +import test.nested.data.Zoo; +import test.nested.owbase.Events; +import test.nested.owcount.CountEvent; +import test.nested.owext.Patches; + +/** + * Test case for polymorphic hierarchies whose abstract root (or parts of it) are nested messages (issue #16). + */ +@SuppressWarnings("javadoc") +public class TestNested extends TestCase { + + /** The shape of the issue report: an abstract root nested in a message. */ + public void testNestedAbstractRootJson() throws IOException { + Outer.Shape circle = Outer.Circle.create().setRadius(5).setName("c"); + assertEquals("[\"Circle\",{\"name\":\"c\",\"radius\":5}]", circle.toString()); + + Outer.Shape copy = Outer.Shape.readShape(json(circle.toString())); + assertTrue(copy instanceof Outer.Circle); + assertEquals(5, ((Outer.Circle) copy).getRadius()); + assertEquals("c", copy.getName()); + } + + public void testTopLevelExtendingNestedJson() throws IOException { + Outer.Shape triangle = Triangle.create().setBase(3).setHeight(4).setName("t"); + assertEquals("[\"Triangle\",{\"name\":\"t\",\"base\":3,\"height\":4}]", triangle.toString()); + assertTrue(Outer.Shape.readShape(json(triangle.toString())) instanceof Triangle); + } + + public void testFieldsInNestedSibling() throws IOException, XMLStreamException { + Outer.Drawing drawing = Outer.Drawing.create() + .setMain(Outer.Square.create().setSide(2).setName("main")) + .addShape(Outer.Circle.create().setRadius(1)) + .addShape(Triangle.create().setBase(7)) + .addShape(Outer.Square.create().setSide(9)); + assertEquals( + "{\"main\":[\"Square\",{\"name\":\"main\",\"side\":2}],\"shapes\":[" + + "[\"Circle\",{\"name\":\"\",\"radius\":1}]," + + "[\"Triangle\",{\"name\":\"\",\"base\":7,\"height\":0}]," + + "[\"Square\",{\"name\":\"\",\"side\":9}]]}", + drawing.toString()); + + String expected = drawing.toString(); + assertEquals(expected, Outer.Drawing.readDrawing(json(expected)).toString()); + assertEquals(expected, Outer.Drawing.readDrawing(binaryReader(binary(drawing))).toString()); + assertEquals(expected, Outer.Drawing.readDrawing(xmlReader(xml(drawing))).toString()); + + Outer.Drawing copy = Outer.Drawing.readDrawing(json(expected)); + assertTrue(copy.getMain() instanceof Outer.Square); + assertTrue(copy.getShapes().get(0) instanceof Outer.Circle); + assertTrue(copy.getShapes().get(1) instanceof Triangle); + assertTrue(copy.getShapes().get(2) instanceof Outer.Square); + } + + public void testFieldInOuter() throws IOException, XMLStreamException { + Outer outer = Outer.create().setShape(Outer.Circle.create().setRadius(42).setName("x")); + String expected = outer.toString(); + assertEquals("{\"shape\":[\"Circle\",{\"name\":\"x\",\"radius\":42}]}", expected); + assertEquals(expected, Outer.readOuter(json(expected)).toString()); + assertEquals(expected, Outer.readOuter(binaryReader(binary(outer))).toString()); + assertEquals(expected, Outer.readOuter(xmlReader(xml(outer))).toString()); + } + + /** Root abstract, abstract intermediate, concrete leaves; nested two levels deep. */ + public void testDeeplyNestedWithAbstractIntermediate() throws IOException, XMLStreamException { + Level1 value = Level1.create() + .setNode(Level2.Root.create().setTitle("r") + .addChildren(Level2.Leaf.create().setValue(1)) + .addChildren(Level2.Branch.create().setExpanded(true) + .addChildren(Level2.Leaf.create().setValue(2).setLabel("deep")))) + .addNodes(Level2.Leaf.create().setValue(3)) + .addNodes(Level2.Branch.create()); + + String expected = value.toString(); + assertEquals( + "{\"node\":[\"Root\",{\"label\":\"\",\"children\":[" + + "[\"Leaf\",{\"label\":\"\",\"value\":1}]," + + "[\"Branch\",{\"label\":\"\",\"children\":[[\"Leaf\",{\"label\":\"deep\",\"value\":2}]],\"expanded\":true}]" + + "],\"title\":\"r\"}],\"nodes\":[" + + "[\"Leaf\",{\"label\":\"\",\"value\":3}]," + + "[\"Branch\",{\"label\":\"\",\"children\":[],\"expanded\":false}]]}", + expected); + assertEquals(expected, Level1.readLevel1(json(expected)).toString()); + assertEquals(expected, Level1.readLevel1(binaryReader(binary(value))).toString()); + assertEquals(expected, Level1.readLevel1(xmlReader(xml(value))).toString()); + + // Reading through the abstract intermediate. + Level2.Composite composite = Level2.Composite.readComposite(json(value.getNode().toString())); + assertTrue(composite instanceof Level2.Root); + assertEquals(2, composite.getChildren().size()); + } + + /** Nested sub-messages extending a top-level abstract root. */ + public void testNestedExtendingTopLevel() throws IOException, XMLStreamException { + Zoo zoo = Zoo.create() + .addAnimal(Zoo.Cat.create().setIndoor(true).setName("tom")) + .addAnimal(Zoo.Parrot.create().addWord("hello").setWingspan(0.5).setName("polly")); + + String expected = zoo.toString(); + assertEquals( + "{\"animals\":[[\"Cat\",{\"name\":\"tom\",\"indoor\":true}]," + + "[\"Parrot\",{\"name\":\"polly\",\"wingspan\":0.5,\"words\":[\"hello\"]}]]}", + expected); + assertEquals(expected, Zoo.readZoo(json(expected)).toString()); + assertEquals(expected, Zoo.readZoo(binaryReader(binary(zoo))).toString()); + assertEquals(expected, Zoo.readZoo(xmlReader(xml(zoo))).toString()); + + Animal parrot = Animal.readAnimal(json(zoo.getAnimals().get(1).toString())); + assertTrue(parrot instanceof Zoo.Parrot); + assertTrue(Zoo.Bird.readBird(json(parrot.toString())) instanceof Zoo.Parrot); + } + + /** A top-level message with fields of nested and top-level abstract types. */ + public void testTopLevelHolder() throws IOException, XMLStreamException { + Holder holder = Holder.create() + .setShape(Triangle.create().setHeight(1)) + .addShapes(Outer.Circle.create().setRadius(2)) + .addShapes(Outer.Square.create().setSide(3)) + .setNode(Level2.Leaf.create().setValue(4)) + .addAnimal(Zoo.Cat.create()); + + String expected = holder.toString(); + assertEquals(expected, Holder.readHolder(json(expected)).toString()); + assertEquals(expected, Holder.readHolder(binaryReader(binary(holder))).toString()); + assertEquals(expected, Holder.readHolder(xmlReader(xml(holder))).toString()); + + Holder copy = Holder.readHolder(binaryReader(binary(holder))); + assertTrue(copy.getShape() instanceof Triangle); + assertTrue(copy.getShapes().get(0) instanceof Outer.Circle); + assertTrue(copy.getShapes().get(1) instanceof Outer.Square); + assertTrue(copy.getNode() instanceof Level2.Leaf); + assertTrue(copy.getAnimals().get(0) instanceof Zoo.Cat); + } + + public void testVisitor() { + Outer.Shape.Visitor shapes = new Outer.Shape.Visitor<>() { + @Override + public String visit(Outer.Circle self, Void arg) { + return "circle"; + } + + @Override + public String visit(Outer.Square self, Void arg) { + return "square"; + } + + @Override + public String visit(Triangle self, Void arg) { + return "triangle"; + } + }; + assertEquals("circle", Outer.Circle.create().visit(shapes, null)); + assertEquals("square", Outer.Square.create().visit(shapes, null)); + assertEquals("triangle", Triangle.create().visit(shapes, null)); + + Level2.Node.Visitor nodes = new Level2.Node.Visitor<>() { + @Override + public String visit(Level2.Leaf self, Void arg) { + return "leaf"; + } + + @Override + public String visit(Level2.Branch self, Void arg) { + return "branch"; + } + + @Override + public String visit(Level2.Root self, Void arg) { + return "root"; + } + }; + assertEquals("leaf", Level2.Leaf.create().visit(nodes, null)); + assertEquals("branch", Level2.Branch.create().visit(nodes, null)); + assertEquals("root", Level2.Root.create().visit(nodes, null)); + // Dispatch through the abstract intermediate's visitor. + Level2.Node root = Level2.Root.create(); + assertEquals("root", ((Level2.Composite) root).visit((Level2.Composite.Visitor) nodes, null)); + + Animal.Visitor animals = new Animal.Visitor<>() { + @Override + public String visit(Zoo.Cat self, Void arg) { + return "cat"; + } + + @Override + public String visit(Zoo.Parrot self, Void arg) { + return "parrot"; + } + }; + assertEquals("cat", Zoo.Cat.create().visit(animals, null)); + assertEquals("parrot", Zoo.Parrot.create().visit(animals, null)); + } + + /** + * A nested OpenWorld root extended by nested and top-level messages of other files. + * + *

+ * OpenWorld implies NoBinary, so only JSON and XML apply. The extension types are discovered + * through the generated service descriptor in src/test/resources/META-INF/services. + * XML is checked for the local type only: the generated XML reader of an OpenWorld root does not + * consult the registry of extension types (for top-level roots neither). + *

+ */ + public void testOpenWorldCrossFile() throws IOException, XMLStreamException { + Events events = Events.create() + .addEvent(Events.TextEvent.create().setText("hi").setTimestamp(1)) + .addEvent(Patches.PatchEvent.create().setPatch("p").setTimestamp(2)) + .addEvent(CountEvent.create().setCount(3).setTimestamp(3)); + + String expected = events.toString(); + assertEquals( + "{\"events\":[[\"TextEvent\",{\"timestamp\":1,\"text\":\"hi\"}]," + + "[\"PatchEvent\",{\"timestamp\":2,\"patch\":\"p\"}]," + + "[\"CountEvent\",{\"timestamp\":3,\"count\":3}]]}", + expected); + + // OpenWorld implies NoBinary, also for a file whose only extension is nested. + assertFalse(Patches.PatchEvent.create() instanceof de.haumacher.msgbuf.binary.BinaryDataObject); + assertFalse(CountEvent.create() instanceof de.haumacher.msgbuf.binary.BinaryDataObject); + + Events copy = Events.readEvents(json(expected)); + assertEquals(expected, copy.toString()); + assertTrue(copy.getEvents().get(0) instanceof Events.TextEvent); + assertTrue(copy.getEvents().get(1) instanceof Patches.PatchEvent); + assertTrue(copy.getEvents().get(2) instanceof CountEvent); + + // XML: the local type of the base file is read back. + Events local = Events.create().addEvent(Events.TextEvent.create().setText("hi").setTimestamp(1)); + assertEquals(local.toString(), Events.readEvents(xmlReader(xml(local))).toString()); + + Events.Event.Visitor visitor = new Patches.PatchEvent.Visitor<>() { + @Override + public String visit(Events.TextEvent self, Void arg) { + return "text"; + } + + @Override + public String visit(Patches.PatchEvent self, Void arg) { + return "patch"; + } + + @Override + public String visitDefault(Events.Event self, Void arg) { + return "default"; + } + }; + assertEquals("text", copy.getEvents().get(0).visit(visitor, null)); + assertEquals("patch", copy.getEvents().get(1).visit(visitor, null)); + assertEquals("default", copy.getEvents().get(2).visit(visitor, null)); + } + + private static JsonReader json(String data) { + return new JsonReader(new StringR(data)); + } + + private static byte[] binary(de.haumacher.msgbuf.binary.BinaryDataObject value) throws IOException { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + value.writeTo(new OctetDataWriter(buffer)); + return buffer.toByteArray(); + } + + private static OctetDataReader binaryReader(byte[] data) { + return new OctetDataReader(new ByteArrayInputStream(data)); + } + + private static String xml(XmlSerializable value) throws XMLStreamException { + StringWriter buffer = new StringWriter(); + value.writeTo(XMLOutputFactory.newDefaultFactory().createXMLStreamWriter(buffer)); + return buffer.toString(); + } + + private static XMLStreamReader xmlReader(String xml) throws XMLStreamException { + return XMLInputFactory.newFactory().createXMLStreamReader(new StringReader(xml)); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNestedDoc.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNestedDoc.java new file mode 100644 index 00000000..d1e1bdbc --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNestedDoc.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2026 Bernhard Haumacher et al. All Rights Reserved. + */ +package test.nested; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; + +import de.haumacher.msgbuf.binary.OctetDataReader; +import de.haumacher.msgbuf.binary.OctetDataWriter; +import de.haumacher.msgbuf.io.StringR; +import de.haumacher.msgbuf.json.JsonReader; +import junit.framework.TestCase; +import test.nested.doc.Doc; +import test.nested.doc.Figure; +import test.nested.note.Note; + +/** + * Test case for a nested polymorphic hierarchy used in repeated, map and nullable fields, and + * referenced from another file (issue #16). + */ +@SuppressWarnings("javadoc") +public class TestNestedDoc extends TestCase { + + public void testJson() throws IOException { + Doc doc = createDoc(); + String json = doc.toString(); + assertEquals("{\"items\":[" + + "[\"Case\",{\"kind\":\"RICH\",\"package\":\"pkg\",\"weight\":3,\"children\":[" + + "[\"Para\",{\"kind\":\"PLAIN\",\"package\":\"\",\"weight\":1,\"text\":\"hello\"}]," + + "[\"Figure\",{\"kind\":\"PLAIN\",\"package\":\"\",\"weight\":0,\"src\":\"x.png\"}]," + + "[\"Case\",{\"kind\":\"PLAIN\",\"package\":\"\",\"weight\":0,\"children\":[]}]]}]," + + "[\"Figure\",{\"kind\":\"PLAIN\",\"package\":\"\",\"weight\":0,\"src\":\"y\"}]]," + + "\"byName\":{\"p\":[\"Para\",{\"kind\":\"PLAIN\",\"package\":\"\",\"weight\":0,\"text\":\"m\"}]}," + + "\"maybe\":[\"Figure\",{\"kind\":\"PLAIN\",\"package\":\"\",\"weight\":0,\"src\":\"\"}]}", json); + assertEquals(json, Doc.readDoc(new JsonReader(new StringR(json))).toString()); + } + + public void testJsonNullable() throws IOException { + String json = Doc.create().toString(); + assertEquals("{\"items\":[],\"byName\":{}}", json); + assertNull(Doc.readDoc(new JsonReader(new StringR(json))).getMaybe()); + } + + public void testBinary() throws IOException { + Doc doc = createDoc(); + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + doc.writeTo(new OctetDataWriter(buffer)); + Doc copy = Doc.readDoc(new OctetDataReader(new ByteArrayInputStream(buffer.toByteArray()))); + assertEquals(doc.toString(), copy.toString()); + } + + public void testXml() throws XMLStreamException { + // Doc itself has a map field, which is not supported in XML. + Doc.Sec.Case value = createCase(); + StringWriter buffer = new StringWriter(); + value.writeTo(XMLOutputFactory.newDefaultFactory().createXMLStreamWriter(buffer)); + Doc.Sec.Item copy = Doc.Sec.Item.readItem( + XMLInputFactory.newFactory().createXMLStreamReader(new StringReader(buffer.toString()))); + assertEquals(value.toString(), copy.toString()); + } + + public void testCrossFileReference() throws IOException { + Note note = Note.create() + .setTarget(createCase()) + .setInner(Note.Inner.create().addRef(Figure.create()).addRef(Doc.Sec.Para.create())); + String json = note.toString(); + assertEquals(json, Note.readNote(new JsonReader(new StringR(json))).toString()); + } + + public void testVisitor() { + Doc.Sec.Item.Visitor visitor = + new Doc.Sec.Item.Visitor() { + @Override + public String visit(Doc.Sec.Para self, Void arg) { + return "para"; + } + + @Override + public String visit(Doc.Sec.Case self, Void arg) { + return "case"; + } + + @Override + public String visit(Figure self, Void arg) { + return "figure"; + } + }; + assertEquals("case", createCase().visit(visitor, null)); + assertEquals("figure", Figure.create().visit(visitor, null)); + } + + private static Doc createDoc() { + return Doc.create() + .addItem(createCase()) + .addItem(Figure.create().setSrc("y")) + .putByName("p", Doc.Sec.Para.create().setText("m")) + .setMaybe(Figure.create()); + } + + private static Doc.Sec.Case createCase() { + Doc.Sec.Case result = Doc.Sec.Case.create().setWeight(3).setPackage("pkg").setKind(Doc.Sec.Item.Kind.RICH); + result.addChildren(Doc.Sec.Para.create().setText("hello").setWeight(1)); + result.addChildren(Figure.create().setSrc("x.png")); + result.addChildren(Doc.Sec.Case.create()); + return result; + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Animal.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Animal.java new file mode 100644 index 00000000..319ca69d --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Animal.java @@ -0,0 +1,92 @@ +package test.nested.data; + +/** + * A top-level abstract root. + */ +public interface Animal extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** Type codes for the {@link test.nested.data.Animal} hierarchy. */ + public enum TypeKind { + + /** Type literal for {@link test.nested.data.Zoo.Cat}. */ + CAT, + + /** Type literal for {@link test.nested.data.Zoo.Parrot}. */ + PARROT, + ; + + } + + /** Visitor interface for the {@link test.nested.data.Animal} hierarchy.*/ + public interface Visitor extends test.nested.data.Zoo.Bird.Visitor { + + /** Visit case for {@link test.nested.data.Zoo.Cat}.*/ + R visit(test.nested.data.Zoo.Cat self, A arg) throws E; + + } + + /** @see #getName() */ + String NAME__PROP = "name"; + + /** Identifier for the property {@link #getName()} in binary format. */ + static final int NAME__ID = 1; + + /** The type code of this instance. */ + TypeKind kind(); + + String getName(); + + /** + * @see #getName() + */ + test.nested.data.Animal setName(String value); + + @Override + public test.nested.data.Animal registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.data.Animal unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Animal readAnimal(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.Animal result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case test.nested.data.Zoo.Cat.CAT__TYPE: result = test.nested.data.Zoo.Cat.readCat(in); break; + case test.nested.data.Zoo.Parrot.PARROT__TYPE: result = test.nested.data.Zoo.Parrot.readParrot(in); break; + default: in.skipValue(); result = null; break; + } + in.endArray(); + return result; + } + + /** The binary identifier for this concrete type in the polymorphic {@link test.nested.data.Animal} hierarchy. */ + abstract int typeId(); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Animal readAnimal(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + int typeField = in.nextName(); + assert typeField == 0; + int type = in.nextInt(); + test.nested.data.Animal result; + switch (type) { + case test.nested.data.Zoo.Cat.CAT__TYPE_ID: result = test.nested.data.impl.Zoo_Impl.Cat_Impl.readCat_Content(in); break; + case test.nested.data.Zoo.Parrot.PARROT__TYPE_ID: result = test.nested.data.impl.Zoo_Impl.Parrot_Impl.readParrot_Content(in); break; + default: result = null; while (in.hasNext()) {in.skipValue(); } + } + in.endObject(); + return result; + } + + /** Creates a new {@link Animal} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Animal readAnimal(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Animal_Impl.readAnimal_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Holder.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Holder.java new file mode 100644 index 00000000..8deba0ef --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Holder.java @@ -0,0 +1,127 @@ +package test.nested.data; + +/** + * A top-level holder of values of nested abstract types. + */ +public interface Holder extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.nested.data.Holder} instance. + */ + static test.nested.data.Holder create() { + return new test.nested.data.impl.Holder_Impl(); + } + + /** Identifier for the {@link test.nested.data.Holder} type in JSON format. */ + String HOLDER__TYPE = "Holder"; + + /** @see #getShape() */ + String SHAPE__PROP = "shape"; + + /** @see #getShapes() */ + String SHAPES__PROP = "shapes"; + + /** @see #getNode() */ + String NODE__PROP = "node"; + + /** @see #getAnimals() */ + String ANIMALS__PROP = "animals"; + + /** Identifier for the property {@link #getShape()} in binary format. */ + static final int SHAPE__ID = 1; + + /** Identifier for the property {@link #getShapes()} in binary format. */ + static final int SHAPES__ID = 2; + + /** Identifier for the property {@link #getNode()} in binary format. */ + static final int NODE__ID = 3; + + /** Identifier for the property {@link #getAnimals()} in binary format. */ + static final int ANIMALS__ID = 4; + + test.nested.data.Outer.Shape getShape(); + + /** + * @see #getShape() + */ + test.nested.data.Holder setShape(test.nested.data.Outer.Shape value); + + /** + * Checks, whether {@link #getShape()} has a value. + */ + boolean hasShape(); + + java.util.List getShapes(); + + /** + * @see #getShapes() + */ + test.nested.data.Holder setShapes(java.util.List value); + + /** + * Adds a value to the {@link #getShapes()} list. + */ + test.nested.data.Holder addShapes(test.nested.data.Outer.Shape value); + + /** + * Removes a value from the {@link #getShapes()} list. + */ + void removeShapes(test.nested.data.Outer.Shape value); + + test.nested.data.Level1.Level2.Node getNode(); + + /** + * @see #getNode() + */ + test.nested.data.Holder setNode(test.nested.data.Level1.Level2.Node value); + + /** + * Checks, whether {@link #getNode()} has a value. + */ + boolean hasNode(); + + java.util.List getAnimals(); + + /** + * @see #getAnimals() + */ + test.nested.data.Holder setAnimals(java.util.List value); + + /** + * Adds a value to the {@link #getAnimals()} list. + */ + test.nested.data.Holder addAnimal(test.nested.data.Animal value); + + /** + * Removes a value from the {@link #getAnimals()} list. + */ + void removeAnimal(test.nested.data.Animal value); + + @Override + public test.nested.data.Holder registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.data.Holder unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Holder readHolder(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.Holder_Impl result = new test.nested.data.impl.Holder_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Holder readHolder(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.data.Holder result = test.nested.data.impl.Holder_Impl.readHolder_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Holder} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Holder readHolder(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Holder_Impl.readHolder_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Level1.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Level1.java new file mode 100644 index 00000000..044936cf --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Level1.java @@ -0,0 +1,471 @@ +package test.nested.data; + +/** + * A hierarchy nested two levels deep. + */ +public interface Level1 extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + public interface Level2 extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + public interface Node extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** Type codes for the {@link test.nested.data.Level1.Level2.Node} hierarchy. */ + public enum TypeKind { + + /** Type literal for {@link test.nested.data.Level1.Level2.Branch}. */ + BRANCH, + + /** Type literal for {@link test.nested.data.Level1.Level2.Root}. */ + ROOT, + + /** Type literal for {@link test.nested.data.Level1.Level2.Leaf}. */ + LEAF, + ; + + } + + /** Visitor interface for the {@link test.nested.data.Level1.Level2.Node} hierarchy.*/ + public interface Visitor extends test.nested.data.Level1.Level2.Composite.Visitor { + + /** Visit case for {@link test.nested.data.Level1.Level2.Leaf}.*/ + R visit(test.nested.data.Level1.Level2.Leaf self, A arg) throws E; + + } + + /** @see #getLabel() */ + String LABEL__PROP = "label"; + + /** Identifier for the property {@link #getLabel()} in binary format. */ + static final int LABEL__ID = 1; + + /** The type code of this instance. */ + TypeKind kind(); + + String getLabel(); + + /** + * @see #getLabel() + */ + test.nested.data.Level1.Level2.Node setLabel(String value); + + @Override + public test.nested.data.Level1.Level2.Node registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.data.Level1.Level2.Node unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Level1.Level2.Node readNode(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.Level1.Level2.Node result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case test.nested.data.Level1.Level2.Branch.BRANCH__TYPE: result = test.nested.data.Level1.Level2.Branch.readBranch(in); break; + case test.nested.data.Level1.Level2.Root.ROOT__TYPE: result = test.nested.data.Level1.Level2.Root.readRoot(in); break; + case test.nested.data.Level1.Level2.Leaf.LEAF__TYPE: result = test.nested.data.Level1.Level2.Leaf.readLeaf(in); break; + default: in.skipValue(); result = null; break; + } + in.endArray(); + return result; + } + + /** The binary identifier for this concrete type in the polymorphic {@link test.nested.data.Level1.Level2.Node} hierarchy. */ + abstract int typeId(); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Level1.Level2.Node readNode(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + int typeField = in.nextName(); + assert typeField == 0; + int type = in.nextInt(); + test.nested.data.Level1.Level2.Node result; + switch (type) { + case test.nested.data.Level1.Level2.Branch.BRANCH__TYPE_ID: result = test.nested.data.impl.Level1_Impl.Level2_Impl.Branch_Impl.readBranch_Content(in); break; + case test.nested.data.Level1.Level2.Root.ROOT__TYPE_ID: result = test.nested.data.impl.Level1_Impl.Level2_Impl.Root_Impl.readRoot_Content(in); break; + case test.nested.data.Level1.Level2.Leaf.LEAF__TYPE_ID: result = test.nested.data.impl.Level1_Impl.Level2_Impl.Leaf_Impl.readLeaf_Content(in); break; + default: result = null; while (in.hasNext()) {in.skipValue(); } + } + in.endObject(); + return result; + } + + /** Creates a new {@link Node} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Node readNode(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Level1_Impl.Level2_Impl.Node_Impl.readNode_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + + } + /** + * Abstract intermediate. + */ + public interface Composite extends test.nested.data.Level1.Level2.Node { + + /** Visitor interface for the {@link test.nested.data.Level1.Level2.Composite} hierarchy.*/ + public interface Visitor { + + /** Visit case for {@link test.nested.data.Level1.Level2.Branch}.*/ + R visit(test.nested.data.Level1.Level2.Branch self, A arg) throws E; + + /** Visit case for {@link test.nested.data.Level1.Level2.Root}.*/ + R visit(test.nested.data.Level1.Level2.Root self, A arg) throws E; + + } + + /** @see #getChildren() */ + String CHILDREN__PROP = "children"; + + /** Identifier for the property {@link #getChildren()} in binary format. */ + static final int CHILDREN__ID = 2; + + java.util.List getChildren(); + + /** + * @see #getChildren() + */ + test.nested.data.Level1.Level2.Composite setChildren(java.util.List value); + + /** + * Adds a value to the {@link #getChildren()} list. + */ + test.nested.data.Level1.Level2.Composite addChildren(test.nested.data.Level1.Level2.Node value); + + /** + * Removes a value from the {@link #getChildren()} list. + */ + void removeChildren(test.nested.data.Level1.Level2.Node value); + + @Override + test.nested.data.Level1.Level2.Composite setLabel(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Level1.Level2.Composite readComposite(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.Level1.Level2.Composite result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case test.nested.data.Level1.Level2.Branch.BRANCH__TYPE: result = test.nested.data.Level1.Level2.Branch.readBranch(in); break; + case test.nested.data.Level1.Level2.Root.ROOT__TYPE: result = test.nested.data.Level1.Level2.Root.readRoot(in); break; + default: in.skipValue(); result = null; break; + } + in.endArray(); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Level1.Level2.Composite readComposite(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + int typeField = in.nextName(); + assert typeField == 0; + int type = in.nextInt(); + test.nested.data.Level1.Level2.Composite result; + switch (type) { + case test.nested.data.Level1.Level2.Branch.BRANCH__TYPE_ID: result = test.nested.data.impl.Level1_Impl.Level2_Impl.Branch_Impl.readBranch_Content(in); break; + case test.nested.data.Level1.Level2.Root.ROOT__TYPE_ID: result = test.nested.data.impl.Level1_Impl.Level2_Impl.Root_Impl.readRoot_Content(in); break; + default: result = null; while (in.hasNext()) {in.skipValue(); } + } + in.endObject(); + return result; + } + + /** Creates a new {@link Composite} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Composite readComposite(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Level1_Impl.Level2_Impl.Composite_Impl.readComposite_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + + } + public interface Leaf extends test.nested.data.Level1.Level2.Node { + + /** + * Creates a {@link test.nested.data.Level1.Level2.Leaf} instance. + */ + static test.nested.data.Level1.Level2.Leaf create() { + return new test.nested.data.impl.Level1_Impl.Level2_Impl.Leaf_Impl(); + } + + /** Identifier for the {@link test.nested.data.Level1.Level2.Leaf} type in JSON format. */ + String LEAF__TYPE = "Leaf"; + + /** @see #getValue() */ + String VALUE__PROP = "value"; + + /** Identifier for the {@link test.nested.data.Level1.Level2.Leaf} type in binary format. */ + static final int LEAF__TYPE_ID = 3; + + /** Identifier for the property {@link #getValue()} in binary format. */ + static final int VALUE__ID = 2; + + int getValue(); + + /** + * @see #getValue() + */ + test.nested.data.Level1.Level2.Leaf setValue(int value); + + @Override + test.nested.data.Level1.Level2.Leaf setLabel(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Level1.Level2.Leaf readLeaf(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.Level1_Impl.Level2_Impl.Leaf_Impl result = new test.nested.data.impl.Level1_Impl.Level2_Impl.Leaf_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Level1.Level2.Leaf readLeaf(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.data.Level1.Level2.Leaf result = test.nested.data.impl.Level1_Impl.Level2_Impl.Leaf_Impl.readLeaf_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Leaf} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Leaf readLeaf(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Level1_Impl.Level2_Impl.Leaf_Impl.readLeaf_XmlContent(in); + } + + } + public interface Branch extends test.nested.data.Level1.Level2.Composite { + + /** + * Creates a {@link test.nested.data.Level1.Level2.Branch} instance. + */ + static test.nested.data.Level1.Level2.Branch create() { + return new test.nested.data.impl.Level1_Impl.Level2_Impl.Branch_Impl(); + } + + /** Identifier for the {@link test.nested.data.Level1.Level2.Branch} type in JSON format. */ + String BRANCH__TYPE = "Branch"; + + /** @see #isExpanded() */ + String EXPANDED__PROP = "expanded"; + + /** Identifier for the {@link test.nested.data.Level1.Level2.Branch} type in binary format. */ + static final int BRANCH__TYPE_ID = 1; + + /** Identifier for the property {@link #isExpanded()} in binary format. */ + static final int EXPANDED__ID = 3; + + boolean isExpanded(); + + /** + * @see #isExpanded() + */ + test.nested.data.Level1.Level2.Branch setExpanded(boolean value); + + @Override + test.nested.data.Level1.Level2.Branch setChildren(java.util.List value); + + @Override + test.nested.data.Level1.Level2.Branch addChildren(test.nested.data.Level1.Level2.Node value); + + @Override + test.nested.data.Level1.Level2.Branch setLabel(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Level1.Level2.Branch readBranch(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.Level1_Impl.Level2_Impl.Branch_Impl result = new test.nested.data.impl.Level1_Impl.Level2_Impl.Branch_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Level1.Level2.Branch readBranch(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.data.Level1.Level2.Branch result = test.nested.data.impl.Level1_Impl.Level2_Impl.Branch_Impl.readBranch_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Branch} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Branch readBranch(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Level1_Impl.Level2_Impl.Branch_Impl.readBranch_XmlContent(in); + } + + } + public interface Root extends test.nested.data.Level1.Level2.Composite { + + /** + * Creates a {@link test.nested.data.Level1.Level2.Root} instance. + */ + static test.nested.data.Level1.Level2.Root create() { + return new test.nested.data.impl.Level1_Impl.Level2_Impl.Root_Impl(); + } + + /** Identifier for the {@link test.nested.data.Level1.Level2.Root} type in JSON format. */ + String ROOT__TYPE = "Root"; + + /** @see #getTitle() */ + String TITLE__PROP = "title"; + + /** Identifier for the {@link test.nested.data.Level1.Level2.Root} type in binary format. */ + static final int ROOT__TYPE_ID = 2; + + /** Identifier for the property {@link #getTitle()} in binary format. */ + static final int TITLE__ID = 3; + + String getTitle(); + + /** + * @see #getTitle() + */ + test.nested.data.Level1.Level2.Root setTitle(String value); + + @Override + test.nested.data.Level1.Level2.Root setChildren(java.util.List value); + + @Override + test.nested.data.Level1.Level2.Root addChildren(test.nested.data.Level1.Level2.Node value); + + @Override + test.nested.data.Level1.Level2.Root setLabel(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Level1.Level2.Root readRoot(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.Level1_Impl.Level2_Impl.Root_Impl result = new test.nested.data.impl.Level1_Impl.Level2_Impl.Root_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Level1.Level2.Root readRoot(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.data.Level1.Level2.Root result = test.nested.data.impl.Level1_Impl.Level2_Impl.Root_Impl.readRoot_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Root} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Root readRoot(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Level1_Impl.Level2_Impl.Root_Impl.readRoot_XmlContent(in); + } + + } + + /** + * Creates a {@link test.nested.data.Level1.Level2} instance. + */ + static test.nested.data.Level1.Level2 create() { + return new test.nested.data.impl.Level1_Impl.Level2_Impl(); + } + + /** Identifier for the {@link test.nested.data.Level1.Level2} type in JSON format. */ + String LEVEL_2__TYPE = "Level2"; + + @Override + public test.nested.data.Level1.Level2 registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.data.Level1.Level2 unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Level1.Level2 readLevel2(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.Level1_Impl.Level2_Impl result = new test.nested.data.impl.Level1_Impl.Level2_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Level1.Level2 readLevel2(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.data.Level1.Level2 result = test.nested.data.impl.Level1_Impl.Level2_Impl.readLevel2_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Level2} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Level2 readLevel2(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Level1_Impl.Level2_Impl.readLevel2_XmlContent(in); + } + + } + + /** + * Creates a {@link test.nested.data.Level1} instance. + */ + static test.nested.data.Level1 create() { + return new test.nested.data.impl.Level1_Impl(); + } + + /** Identifier for the {@link test.nested.data.Level1} type in JSON format. */ + String LEVEL_1__TYPE = "Level1"; + + /** @see #getNode() */ + String NODE__PROP = "node"; + + /** @see #getNodes() */ + String NODES__PROP = "nodes"; + + /** Identifier for the property {@link #getNode()} in binary format. */ + static final int NODE__ID = 1; + + /** Identifier for the property {@link #getNodes()} in binary format. */ + static final int NODES__ID = 2; + + test.nested.data.Level1.Level2.Node getNode(); + + /** + * @see #getNode() + */ + test.nested.data.Level1 setNode(test.nested.data.Level1.Level2.Node value); + + /** + * Checks, whether {@link #getNode()} has a value. + */ + boolean hasNode(); + + java.util.List getNodes(); + + /** + * @see #getNodes() + */ + test.nested.data.Level1 setNodes(java.util.List value); + + /** + * Adds a value to the {@link #getNodes()} list. + */ + test.nested.data.Level1 addNodes(test.nested.data.Level1.Level2.Node value); + + /** + * Removes a value from the {@link #getNodes()} list. + */ + void removeNodes(test.nested.data.Level1.Level2.Node value); + + @Override + public test.nested.data.Level1 registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.data.Level1 unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Level1 readLevel1(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.Level1_Impl result = new test.nested.data.impl.Level1_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Level1 readLevel1(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.data.Level1 result = test.nested.data.impl.Level1_Impl.readLevel1_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Level1} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Level1 readLevel1(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Level1_Impl.readLevel1_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Outer.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Outer.java new file mode 100644 index 00000000..488bc922 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Outer.java @@ -0,0 +1,357 @@ +package test.nested.data; + +/** + * Hierarchies with an abstract root declared inside other messages (issue #16). + */ +public interface Outer extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + /** + * Abstract root of a hierarchy nested in a top-level message. + */ + public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** Type codes for the {@link test.nested.data.Outer.Shape} hierarchy. */ + public enum TypeKind { + + /** Type literal for {@link test.nested.data.Outer.Circle}. */ + CIRCLE, + + /** Type literal for {@link test.nested.data.Outer.Square}. */ + SQUARE, + + /** Type literal for {@link test.nested.data.Triangle}. */ + TRIANGLE, + ; + + } + + /** Visitor interface for the {@link test.nested.data.Outer.Shape} hierarchy.*/ + public interface Visitor { + + /** Visit case for {@link test.nested.data.Outer.Circle}.*/ + R visit(test.nested.data.Outer.Circle self, A arg) throws E; + + /** Visit case for {@link test.nested.data.Outer.Square}.*/ + R visit(test.nested.data.Outer.Square self, A arg) throws E; + + /** Visit case for {@link test.nested.data.Triangle}.*/ + R visit(test.nested.data.Triangle self, A arg) throws E; + + } + + /** @see #getName() */ + String NAME__PROP = "name"; + + /** Identifier for the property {@link #getName()} in binary format. */ + static final int NAME__ID = 1; + + /** The type code of this instance. */ + TypeKind kind(); + + String getName(); + + /** + * @see #getName() + */ + test.nested.data.Outer.Shape setName(String value); + + @Override + public test.nested.data.Outer.Shape registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.data.Outer.Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Outer.Shape readShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.Outer.Shape result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case test.nested.data.Outer.Circle.CIRCLE__TYPE: result = test.nested.data.Outer.Circle.readCircle(in); break; + case test.nested.data.Outer.Square.SQUARE__TYPE: result = test.nested.data.Outer.Square.readSquare(in); break; + case Triangle.TRIANGLE__TYPE: result = test.nested.data.Triangle.readTriangle(in); break; + default: in.skipValue(); result = null; break; + } + in.endArray(); + return result; + } + + /** The binary identifier for this concrete type in the polymorphic {@link test.nested.data.Outer.Shape} hierarchy. */ + abstract int typeId(); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Outer.Shape readShape(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + int typeField = in.nextName(); + assert typeField == 0; + int type = in.nextInt(); + test.nested.data.Outer.Shape result; + switch (type) { + case test.nested.data.Outer.Circle.CIRCLE__TYPE_ID: result = test.nested.data.impl.Outer_Impl.Circle_Impl.readCircle_Content(in); break; + case test.nested.data.Outer.Square.SQUARE__TYPE_ID: result = test.nested.data.impl.Outer_Impl.Square_Impl.readSquare_Content(in); break; + case test.nested.data.Triangle.TRIANGLE__TYPE_ID: result = test.nested.data.impl.Triangle_Impl.readTriangle_Content(in); break; + default: result = null; while (in.hasNext()) {in.skipValue(); } + } + in.endObject(); + return result; + } + + /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Shape readShape(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Outer_Impl.Shape_Impl.readShape_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + + } + public interface Circle extends test.nested.data.Outer.Shape { + + /** + * Creates a {@link test.nested.data.Outer.Circle} instance. + */ + static test.nested.data.Outer.Circle create() { + return new test.nested.data.impl.Outer_Impl.Circle_Impl(); + } + + /** Identifier for the {@link test.nested.data.Outer.Circle} type in JSON format. */ + String CIRCLE__TYPE = "Circle"; + + /** @see #getRadius() */ + String RADIUS__PROP = "radius"; + + /** Identifier for the {@link test.nested.data.Outer.Circle} type in binary format. */ + static final int CIRCLE__TYPE_ID = 1; + + /** Identifier for the property {@link #getRadius()} in binary format. */ + static final int RADIUS__ID = 2; + + int getRadius(); + + /** + * @see #getRadius() + */ + test.nested.data.Outer.Circle setRadius(int value); + + @Override + test.nested.data.Outer.Circle setName(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Outer.Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.Outer_Impl.Circle_Impl result = new test.nested.data.impl.Outer_Impl.Circle_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Outer.Circle readCircle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.data.Outer.Circle result = test.nested.data.impl.Outer_Impl.Circle_Impl.readCircle_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Circle readCircle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Outer_Impl.Circle_Impl.readCircle_XmlContent(in); + } + + } + public interface Square extends test.nested.data.Outer.Shape { + + /** + * Creates a {@link test.nested.data.Outer.Square} instance. + */ + static test.nested.data.Outer.Square create() { + return new test.nested.data.impl.Outer_Impl.Square_Impl(); + } + + /** Identifier for the {@link test.nested.data.Outer.Square} type in JSON format. */ + String SQUARE__TYPE = "Square"; + + /** @see #getSide() */ + String SIDE__PROP = "side"; + + /** Identifier for the {@link test.nested.data.Outer.Square} type in binary format. */ + static final int SQUARE__TYPE_ID = 2; + + /** Identifier for the property {@link #getSide()} in binary format. */ + static final int SIDE__ID = 2; + + int getSide(); + + /** + * @see #getSide() + */ + test.nested.data.Outer.Square setSide(int value); + + @Override + test.nested.data.Outer.Square setName(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Outer.Square readSquare(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.Outer_Impl.Square_Impl result = new test.nested.data.impl.Outer_Impl.Square_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Outer.Square readSquare(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.data.Outer.Square result = test.nested.data.impl.Outer_Impl.Square_Impl.readSquare_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Square} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Square readSquare(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Outer_Impl.Square_Impl.readSquare_XmlContent(in); + } + + } + /** + * A sibling message holding values of the nested abstract type. + */ + public interface Drawing extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.nested.data.Outer.Drawing} instance. + */ + static test.nested.data.Outer.Drawing create() { + return new test.nested.data.impl.Outer_Impl.Drawing_Impl(); + } + + /** Identifier for the {@link test.nested.data.Outer.Drawing} type in JSON format. */ + String DRAWING__TYPE = "Drawing"; + + /** @see #getMain() */ + String MAIN__PROP = "main"; + + /** @see #getShapes() */ + String SHAPES__PROP = "shapes"; + + /** Identifier for the property {@link #getMain()} in binary format. */ + static final int MAIN__ID = 1; + + /** Identifier for the property {@link #getShapes()} in binary format. */ + static final int SHAPES__ID = 2; + + test.nested.data.Outer.Shape getMain(); + + /** + * @see #getMain() + */ + test.nested.data.Outer.Drawing setMain(test.nested.data.Outer.Shape value); + + /** + * Checks, whether {@link #getMain()} has a value. + */ + boolean hasMain(); + + java.util.List getShapes(); + + /** + * @see #getShapes() + */ + test.nested.data.Outer.Drawing setShapes(java.util.List value); + + /** + * Adds a value to the {@link #getShapes()} list. + */ + test.nested.data.Outer.Drawing addShape(test.nested.data.Outer.Shape value); + + /** + * Removes a value from the {@link #getShapes()} list. + */ + void removeShape(test.nested.data.Outer.Shape value); + + @Override + public test.nested.data.Outer.Drawing registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.data.Outer.Drawing unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Outer.Drawing readDrawing(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.Outer_Impl.Drawing_Impl result = new test.nested.data.impl.Outer_Impl.Drawing_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Outer.Drawing readDrawing(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.data.Outer.Drawing result = test.nested.data.impl.Outer_Impl.Drawing_Impl.readDrawing_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Drawing} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Drawing readDrawing(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Outer_Impl.Drawing_Impl.readDrawing_XmlContent(in); + } + + } + + /** + * Creates a {@link test.nested.data.Outer} instance. + */ + static test.nested.data.Outer create() { + return new test.nested.data.impl.Outer_Impl(); + } + + /** Identifier for the {@link test.nested.data.Outer} type in JSON format. */ + String OUTER__TYPE = "Outer"; + + /** @see #getShape() */ + String SHAPE__PROP = "shape"; + + /** Identifier for the property {@link #getShape()} in binary format. */ + static final int SHAPE__ID = 1; + + /** + * A field of the nested abstract type in the outer message itself. + */ + test.nested.data.Outer.Shape getShape(); + + /** + * @see #getShape() + */ + test.nested.data.Outer setShape(test.nested.data.Outer.Shape value); + + /** + * Checks, whether {@link #getShape()} has a value. + */ + boolean hasShape(); + + @Override + public test.nested.data.Outer registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.data.Outer unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Outer readOuter(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.Outer_Impl result = new test.nested.data.impl.Outer_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Outer readOuter(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.data.Outer result = test.nested.data.impl.Outer_Impl.readOuter_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Outer} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Outer readOuter(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Outer_Impl.readOuter_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Triangle.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Triangle.java new file mode 100644 index 00000000..31b6e109 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Triangle.java @@ -0,0 +1,71 @@ +package test.nested.data; + +/** + * A top-level message extending a nested abstract message. + */ +public interface Triangle extends test.nested.data.Outer.Shape { + + /** + * Creates a {@link test.nested.data.Triangle} instance. + */ + static test.nested.data.Triangle create() { + return new test.nested.data.impl.Triangle_Impl(); + } + + /** Identifier for the {@link test.nested.data.Triangle} type in JSON format. */ + String TRIANGLE__TYPE = "Triangle"; + + /** @see #getBase() */ + String BASE__PROP = "base"; + + /** @see #getHeight() */ + String HEIGHT__PROP = "height"; + + /** Identifier for the {@link test.nested.data.Triangle} type in binary format. */ + static final int TRIANGLE__TYPE_ID = 3; + + /** Identifier for the property {@link #getBase()} in binary format. */ + static final int BASE__ID = 2; + + /** Identifier for the property {@link #getHeight()} in binary format. */ + static final int HEIGHT__ID = 3; + + int getBase(); + + /** + * @see #getBase() + */ + test.nested.data.Triangle setBase(int value); + + int getHeight(); + + /** + * @see #getHeight() + */ + test.nested.data.Triangle setHeight(int value); + + @Override + test.nested.data.Triangle setName(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Triangle readTriangle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.Triangle_Impl result = new test.nested.data.impl.Triangle_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Triangle readTriangle(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.data.Triangle result = test.nested.data.impl.Triangle_Impl.readTriangle_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Triangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Triangle readTriangle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Triangle_Impl.readTriangle_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Zoo.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Zoo.java new file mode 100644 index 00000000..14e5f003 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/Zoo.java @@ -0,0 +1,254 @@ +package test.nested.data; + +/** + * A container for sub-messages extending a top-level abstract message. + */ +public interface Zoo extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + public interface Cat extends test.nested.data.Animal { + + /** + * Creates a {@link test.nested.data.Zoo.Cat} instance. + */ + static test.nested.data.Zoo.Cat create() { + return new test.nested.data.impl.Zoo_Impl.Cat_Impl(); + } + + /** Identifier for the {@link test.nested.data.Zoo.Cat} type in JSON format. */ + String CAT__TYPE = "Cat"; + + /** @see #isIndoor() */ + String INDOOR__PROP = "indoor"; + + /** Identifier for the {@link test.nested.data.Zoo.Cat} type in binary format. */ + static final int CAT__TYPE_ID = 1; + + /** Identifier for the property {@link #isIndoor()} in binary format. */ + static final int INDOOR__ID = 2; + + boolean isIndoor(); + + /** + * @see #isIndoor() + */ + test.nested.data.Zoo.Cat setIndoor(boolean value); + + @Override + test.nested.data.Zoo.Cat setName(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Zoo.Cat readCat(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.Zoo_Impl.Cat_Impl result = new test.nested.data.impl.Zoo_Impl.Cat_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Zoo.Cat readCat(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.data.Zoo.Cat result = test.nested.data.impl.Zoo_Impl.Cat_Impl.readCat_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Cat} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Cat readCat(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Zoo_Impl.Cat_Impl.readCat_XmlContent(in); + } + + } + /** + * A nested abstract intermediate below a top-level root. + */ + public interface Bird extends test.nested.data.Animal { + + /** Visitor interface for the {@link test.nested.data.Zoo.Bird} hierarchy.*/ + public interface Visitor { + + /** Visit case for {@link test.nested.data.Zoo.Parrot}.*/ + R visit(test.nested.data.Zoo.Parrot self, A arg) throws E; + + } + + /** @see #getWingspan() */ + String WINGSPAN__PROP = "wingspan"; + + /** Identifier for the property {@link #getWingspan()} in binary format. */ + static final int WINGSPAN__ID = 2; + + double getWingspan(); + + /** + * @see #getWingspan() + */ + test.nested.data.Zoo.Bird setWingspan(double value); + + @Override + test.nested.data.Zoo.Bird setName(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Zoo.Bird readBird(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.Zoo.Bird result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case test.nested.data.Zoo.Parrot.PARROT__TYPE: result = test.nested.data.Zoo.Parrot.readParrot(in); break; + default: in.skipValue(); result = null; break; + } + in.endArray(); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Zoo.Bird readBird(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + int typeField = in.nextName(); + assert typeField == 0; + int type = in.nextInt(); + test.nested.data.Zoo.Bird result; + switch (type) { + case test.nested.data.Zoo.Parrot.PARROT__TYPE_ID: result = test.nested.data.impl.Zoo_Impl.Parrot_Impl.readParrot_Content(in); break; + default: result = null; while (in.hasNext()) {in.skipValue(); } + } + in.endObject(); + return result; + } + + /** Creates a new {@link Bird} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Bird readBird(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Zoo_Impl.Bird_Impl.readBird_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + + } + public interface Parrot extends test.nested.data.Zoo.Bird { + + /** + * Creates a {@link test.nested.data.Zoo.Parrot} instance. + */ + static test.nested.data.Zoo.Parrot create() { + return new test.nested.data.impl.Zoo_Impl.Parrot_Impl(); + } + + /** Identifier for the {@link test.nested.data.Zoo.Parrot} type in JSON format. */ + String PARROT__TYPE = "Parrot"; + + /** @see #getWords() */ + String WORDS__PROP = "words"; + + /** Identifier for the {@link test.nested.data.Zoo.Parrot} type in binary format. */ + static final int PARROT__TYPE_ID = 2; + + /** Identifier for the property {@link #getWords()} in binary format. */ + static final int WORDS__ID = 3; + + java.util.List getWords(); + + /** + * @see #getWords() + */ + test.nested.data.Zoo.Parrot setWords(java.util.List value); + + /** + * Adds a value to the {@link #getWords()} list. + */ + test.nested.data.Zoo.Parrot addWord(String value); + + /** + * Removes a value from the {@link #getWords()} list. + */ + void removeWord(String value); + + @Override + test.nested.data.Zoo.Parrot setWingspan(double value); + + @Override + test.nested.data.Zoo.Parrot setName(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Zoo.Parrot readParrot(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.Zoo_Impl.Parrot_Impl result = new test.nested.data.impl.Zoo_Impl.Parrot_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Zoo.Parrot readParrot(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.data.Zoo.Parrot result = test.nested.data.impl.Zoo_Impl.Parrot_Impl.readParrot_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Parrot} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Parrot readParrot(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Zoo_Impl.Parrot_Impl.readParrot_XmlContent(in); + } + + } + + /** + * Creates a {@link test.nested.data.Zoo} instance. + */ + static test.nested.data.Zoo create() { + return new test.nested.data.impl.Zoo_Impl(); + } + + /** Identifier for the {@link test.nested.data.Zoo} type in JSON format. */ + String ZOO__TYPE = "Zoo"; + + /** @see #getAnimals() */ + String ANIMALS__PROP = "animals"; + + /** Identifier for the property {@link #getAnimals()} in binary format. */ + static final int ANIMALS__ID = 1; + + java.util.List getAnimals(); + + /** + * @see #getAnimals() + */ + test.nested.data.Zoo setAnimals(java.util.List value); + + /** + * Adds a value to the {@link #getAnimals()} list. + */ + test.nested.data.Zoo addAnimal(test.nested.data.Animal value); + + /** + * Removes a value from the {@link #getAnimals()} list. + */ + void removeAnimal(test.nested.data.Animal value); + + @Override + public test.nested.data.Zoo registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.data.Zoo unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.data.Zoo readZoo(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.data.impl.Zoo_Impl result = new test.nested.data.impl.Zoo_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.data.Zoo readZoo(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.data.Zoo result = test.nested.data.impl.Zoo_Impl.readZoo_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Zoo} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Zoo readZoo(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.data.impl.Zoo_Impl.readZoo_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Animal_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Animal_Impl.java new file mode 100644 index 00000000..a3b6ecbd --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Animal_Impl.java @@ -0,0 +1,253 @@ +package test.nested.data.impl; + +/** + * Implementation of {@link test.nested.data.Animal}. + */ +public abstract class Animal_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.data.Animal { + + private String _name = ""; + + /** + * Creates a {@link Animal_Impl} instance. + */ + public Animal_Impl() { + super(); + } + + @Override + public final String getName() { + return _name; + } + + @Override + public test.nested.data.Animal setName(String value) { + internalSetName(value); + return this; + } + + /** Internal setter for {@link #getName()} without chain call utility. */ + protected final void internalSetName(String value) { + _listener.beforeSet(this, NAME__PROP, value); + _name = value; + _listener.afterChanged(this, NAME__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.data.Animal registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.data.Animal unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + NAME__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NAME__PROP: return getName(); + default: return test.nested.data.Animal.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NAME__PROP: internalSetName((String) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.beginArray(); + out.value(jsonType()); + writeContent(out); + out.endArray(); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NAME__PROP); + out.value(getName()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + out.name(0); + out.value(typeId()); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(NAME__ID); + out.value(getName()); + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case NAME__ID: setName(in.nextString()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.data.Animal} type. */ + public static final String ANIMAL__XML_ELEMENT = "animal"; + + /** XML attribute or element name of a {@link #getName} property. */ + private static final String NAME__XML_ATTR = "name"; + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.nested.data.Animal} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Animal_Impl readAnimal_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case test.nested.data.impl.Zoo_Impl.Cat_Impl.CAT__XML_ELEMENT: { + return test.nested.data.impl.Zoo_Impl.Cat_Impl.readCat_XmlContent(in); + } + + case test.nested.data.impl.Zoo_Impl.Parrot_Impl.PARROT__XML_ELEMENT: { + return test.nested.data.impl.Zoo_Impl.Parrot_Impl.readParrot_XmlContent(in); + } + + default: { + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NAME__XML_ATTR: { + setName(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NAME__XML_ATTR: { + setName(in.getElementText()); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Holder_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Holder_Impl.java new file mode 100644 index 00000000..c179c4a4 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Holder_Impl.java @@ -0,0 +1,538 @@ +package test.nested.data.impl; + +/** + * Implementation of {@link test.nested.data.Holder}. + */ +public class Holder_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.data.Holder { + + private test.nested.data.Outer.Shape _shape = null; + + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.nested.data.Outer.Shape element) { + _listener.beforeAdd(Holder_Impl.this, SHAPES__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.nested.data.Outer.Shape element) { + _listener.afterRemove(Holder_Impl.this, SHAPES__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Holder_Impl.this, SHAPES__PROP); + } + }; + + private test.nested.data.Level1.Level2.Node _node = null; + + private final java.util.List _animals = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.nested.data.Animal element) { + _listener.beforeAdd(Holder_Impl.this, ANIMALS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.nested.data.Animal element) { + _listener.afterRemove(Holder_Impl.this, ANIMALS__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Holder_Impl.this, ANIMALS__PROP); + } + }; + + /** + * Creates a {@link Holder_Impl} instance. + * + * @see test.nested.data.Holder#create() + */ + public Holder_Impl() { + super(); + } + + @Override + public final test.nested.data.Outer.Shape getShape() { + return _shape; + } + + @Override + public test.nested.data.Holder setShape(test.nested.data.Outer.Shape value) { + internalSetShape(value); + return this; + } + + /** Internal setter for {@link #getShape()} without chain call utility. */ + protected final void internalSetShape(test.nested.data.Outer.Shape value) { + _listener.beforeSet(this, SHAPE__PROP, value); + _shape = value; + _listener.afterChanged(this, SHAPE__PROP); + } + + @Override + public final boolean hasShape() { + return _shape != null; + } + + @Override + public final java.util.List getShapes() { + return _shapes; + } + + @Override + public test.nested.data.Holder setShapes(java.util.List value) { + internalSetShapes(value); + return this; + } + + /** Internal setter for {@link #getShapes()} without chain call utility. */ + protected final void internalSetShapes(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); + _shapes.clear(); + _shapes.addAll(value); + } + + @Override + public test.nested.data.Holder addShapes(test.nested.data.Outer.Shape value) { + internalAddShapes(value); + return this; + } + + /** Implementation of {@link #addShapes(test.nested.data.Outer.Shape)} without chain call utility. */ + protected final void internalAddShapes(test.nested.data.Outer.Shape value) { + _shapes.add(value); + } + + @Override + public final void removeShapes(test.nested.data.Outer.Shape value) { + _shapes.remove(value); + } + + @Override + public final test.nested.data.Level1.Level2.Node getNode() { + return _node; + } + + @Override + public test.nested.data.Holder setNode(test.nested.data.Level1.Level2.Node value) { + internalSetNode(value); + return this; + } + + /** Internal setter for {@link #getNode()} without chain call utility. */ + protected final void internalSetNode(test.nested.data.Level1.Level2.Node value) { + _listener.beforeSet(this, NODE__PROP, value); + _node = value; + _listener.afterChanged(this, NODE__PROP); + } + + @Override + public final boolean hasNode() { + return _node != null; + } + + @Override + public final java.util.List getAnimals() { + return _animals; + } + + @Override + public test.nested.data.Holder setAnimals(java.util.List value) { + internalSetAnimals(value); + return this; + } + + /** Internal setter for {@link #getAnimals()} without chain call utility. */ + protected final void internalSetAnimals(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'animals' cannot be null."); + _animals.clear(); + _animals.addAll(value); + } + + @Override + public test.nested.data.Holder addAnimal(test.nested.data.Animal value) { + internalAddAnimal(value); + return this; + } + + /** Implementation of {@link #addAnimal(test.nested.data.Animal)} without chain call utility. */ + protected final void internalAddAnimal(test.nested.data.Animal value) { + _animals.add(value); + } + + @Override + public final void removeAnimal(test.nested.data.Animal value) { + _animals.remove(value); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.data.Holder registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.data.Holder unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return HOLDER__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + SHAPE__PROP, + SHAPES__PROP, + NODE__PROP, + ANIMALS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case SHAPE__PROP: return getShape(); + case SHAPES__PROP: return getShapes(); + case NODE__PROP: return getNode(); + case ANIMALS__PROP: return getAnimals(); + default: return test.nested.data.Holder.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case SHAPE__PROP: internalSetShape((test.nested.data.Outer.Shape) value); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(test.nested.data.Outer.Shape.class, value)); break; + case NODE__PROP: internalSetNode((test.nested.data.Level1.Level2.Node) value); break; + case ANIMALS__PROP: internalSetAnimals(de.haumacher.msgbuf.util.Conversions.asList(test.nested.data.Animal.class, value)); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + if (hasShape()) { + out.name(SHAPE__PROP); + getShape().writeTo(out); + } + out.name(SHAPES__PROP); + out.beginArray(); + for (test.nested.data.Outer.Shape x : getShapes()) { + x.writeTo(out); + } + out.endArray(); + if (hasNode()) { + out.name(NODE__PROP); + getNode().writeTo(out); + } + out.name(ANIMALS__PROP); + out.beginArray(); + for (test.nested.data.Animal x : getAnimals()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case SHAPE__PROP: setShape(test.nested.data.Outer.Shape.readShape(in)); break; + case SHAPES__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.nested.data.Outer.Shape.readShape(in)); + } + in.endArray(); + setShapes(newValue); + } + break; + case NODE__PROP: setNode(test.nested.data.Level1.Level2.Node.readNode(in)); break; + case ANIMALS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.nested.data.Animal.readAnimal(in)); + } + in.endArray(); + setAnimals(newValue); + } + break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + if (hasShape()) { + out.name(SHAPE__ID); + getShape().writeTo(out); + } + out.name(SHAPES__ID); + { + java.util.List values = getShapes(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.nested.data.Outer.Shape x : values) { + x.writeTo(out); + } + out.endArray(); + } + if (hasNode()) { + out.name(NODE__ID); + getNode().writeTo(out); + } + out.name(ANIMALS__ID); + { + java.util.List values = getAnimals(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.nested.data.Animal x : values) { + x.writeTo(out); + } + out.endArray(); + } + } + + /** Helper for creating an object of type {@link test.nested.data.Holder} from a polymorphic composition. */ + public static test.nested.data.Holder readHolder_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.Holder_Impl result = new Holder_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case SHAPE__ID: setShape(test.nested.data.Outer.Shape.readShape(in)); break; + case SHAPES__ID: { + in.beginArray(); + while (in.hasNext()) { + addShapes(test.nested.data.Outer.Shape.readShape(in)); + } + in.endArray(); + } + break; + case NODE__ID: setNode(test.nested.data.Level1.Level2.Node.readNode(in)); break; + case ANIMALS__ID: { + in.beginArray(); + while (in.hasNext()) { + addAnimal(test.nested.data.Animal.readAnimal(in)); + } + in.endArray(); + } + break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.data.Holder} type. */ + public static final String HOLDER__XML_ELEMENT = "holder"; + + /** XML attribute or element name of a {@link #getShape} property. */ + private static final String SHAPE__XML_ATTR = "shape"; + + /** XML attribute or element name of a {@link #getShapes} property. */ + private static final String SHAPES__XML_ATTR = "shapes"; + + /** XML attribute or element name of a {@link #getNode} property. */ + private static final String NODE__XML_ATTR = "node"; + + /** XML attribute or element name of a {@link #getAnimals} property. */ + private static final String ANIMALS__XML_ATTR = "animals"; + + @Override + public String getXmlTagName() { + return HOLDER__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasShape()) { + out.writeStartElement(SHAPE__XML_ATTR); + getShape().writeTo(out); + out.writeEndElement(); + } + out.writeStartElement(SHAPES__XML_ATTR); + for (test.nested.data.Outer.Shape element : getShapes()) { + element.writeTo(out); + } + out.writeEndElement(); + if (hasNode()) { + out.writeStartElement(NODE__XML_ATTR); + getNode().writeTo(out); + out.writeEndElement(); + } + out.writeStartElement(ANIMALS__XML_ATTR); + for (test.nested.data.Animal element : getAnimals()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.nested.data.Holder} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Holder_Impl readHolder_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Holder_Impl result = new Holder_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case SHAPE__XML_ATTR: { + in.nextTag(); + setShape(test.nested.data.impl.Outer_Impl.Shape_Impl.readShape_XmlContent(in)); + internalSkipUntilMatchingEndElement(in); + break; + } + case SHAPES__XML_ATTR: { + internalReadShapesListXml(in); + break; + } + case NODE__XML_ATTR: { + in.nextTag(); + setNode(test.nested.data.impl.Level1_Impl.Level2_Impl.Node_Impl.readNode_XmlContent(in)); + internalSkipUntilMatchingEndElement(in); + break; + } + case ANIMALS__XML_ATTR: { + internalReadAnimalsListXml(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadShapesListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addShapes(test.nested.data.impl.Outer_Impl.Shape_Impl.readShape_XmlContent(in)); + } + } + + private void internalReadAnimalsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addAnimal(test.nested.data.impl.Animal_Impl.readAnimal_XmlContent(in)); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Level1_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Level1_Impl.java new file mode 100644 index 00000000..3601cdd2 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Level1_Impl.java @@ -0,0 +1,1682 @@ +package test.nested.data.impl; + +/** + * Implementation of {@link test.nested.data.Level1}. + */ +public class Level1_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.data.Level1 { + /** + * Implementation of {@link test.nested.data.Level1.Level2}. + */ + public static class Level2_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.data.Level1.Level2 { + /** + * Implementation of {@link test.nested.data.Level1.Level2.Node}. + */ + public static abstract class Node_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.data.Level1.Level2.Node { + + private String _label = ""; + + /** + * Creates a {@link Node_Impl} instance. + */ + public Node_Impl() { + super(); + } + + @Override + public final String getLabel() { + return _label; + } + + @Override + public test.nested.data.Level1.Level2.Node setLabel(String value) { + internalSetLabel(value); + return this; + } + + /** Internal setter for {@link #getLabel()} without chain call utility. */ + protected final void internalSetLabel(String value) { + _listener.beforeSet(this, LABEL__PROP, value); + _label = value; + _listener.afterChanged(this, LABEL__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.data.Level1.Level2.Node registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.data.Level1.Level2.Node unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + LABEL__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case LABEL__PROP: return getLabel(); + default: return test.nested.data.Level1.Level2.Node.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case LABEL__PROP: internalSetLabel((String) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.beginArray(); + out.value(jsonType()); + writeContent(out); + out.endArray(); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(LABEL__PROP); + out.value(getLabel()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case LABEL__PROP: setLabel(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + out.name(0); + out.value(typeId()); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(LABEL__ID); + out.value(getLabel()); + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case LABEL__ID: setLabel(in.nextString()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.data.Level1.Level2.Node} type. */ + public static final String NODE__XML_ELEMENT = "node"; + + /** XML attribute or element name of a {@link #getLabel} property. */ + private static final String LABEL__XML_ATTR = "label"; + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(LABEL__XML_ATTR, getLabel()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.nested.data.Level1.Level2.Node} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Node_Impl readNode_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case test.nested.data.impl.Level1_Impl.Level2_Impl.Branch_Impl.BRANCH__XML_ELEMENT: { + return test.nested.data.impl.Level1_Impl.Level2_Impl.Branch_Impl.readBranch_XmlContent(in); + } + + case test.nested.data.impl.Level1_Impl.Level2_Impl.Root_Impl.ROOT__XML_ELEMENT: { + return test.nested.data.impl.Level1_Impl.Level2_Impl.Root_Impl.readRoot_XmlContent(in); + } + + case test.nested.data.impl.Level1_Impl.Level2_Impl.Leaf_Impl.LEAF__XML_ELEMENT: { + return test.nested.data.impl.Level1_Impl.Level2_Impl.Leaf_Impl.readLeaf_XmlContent(in); + } + + default: { + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case LABEL__XML_ATTR: { + setLabel(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case LABEL__XML_ATTR: { + setLabel(in.getElementText()); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + } + /** + * Implementation of {@link test.nested.data.Level1.Level2.Composite}. + */ + public static abstract class Composite_Impl extends test.nested.data.impl.Level1_Impl.Level2_Impl.Node_Impl implements test.nested.data.Level1.Level2.Composite { + + private final java.util.List _children = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.nested.data.Level1.Level2.Node element) { + _listener.beforeAdd(Composite_Impl.this, CHILDREN__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.nested.data.Level1.Level2.Node element) { + _listener.afterRemove(Composite_Impl.this, CHILDREN__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Composite_Impl.this, CHILDREN__PROP); + } + }; + + /** + * Creates a {@link Composite_Impl} instance. + */ + public Composite_Impl() { + super(); + } + + @Override + public final java.util.List getChildren() { + return _children; + } + + @Override + public test.nested.data.Level1.Level2.Composite setChildren(java.util.List value) { + internalSetChildren(value); + return this; + } + + /** Internal setter for {@link #getChildren()} without chain call utility. */ + protected final void internalSetChildren(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'children' cannot be null."); + _children.clear(); + _children.addAll(value); + } + + @Override + public test.nested.data.Level1.Level2.Composite addChildren(test.nested.data.Level1.Level2.Node value) { + internalAddChildren(value); + return this; + } + + /** Implementation of {@link #addChildren(test.nested.data.Level1.Level2.Node)} without chain call utility. */ + protected final void internalAddChildren(test.nested.data.Level1.Level2.Node value) { + _children.add(value); + } + + @Override + public final void removeChildren(test.nested.data.Level1.Level2.Node value) { + _children.remove(value); + } + + @Override + public test.nested.data.Level1.Level2.Composite setLabel(String value) { + internalSetLabel(value); + return this; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + CHILDREN__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.data.impl.Level1_Impl.Level2_Impl.Node_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.data.impl.Level1_Impl.Level2_Impl.Node_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case CHILDREN__PROP: return getChildren(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case CHILDREN__PROP: internalSetChildren(de.haumacher.msgbuf.util.Conversions.asList(test.nested.data.Level1.Level2.Node.class, value)); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(CHILDREN__PROP); + out.beginArray(); + for (test.nested.data.Level1.Level2.Node x : getChildren()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case CHILDREN__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.nested.data.Level1.Level2.Node.readNode(in)); + } + in.endArray(); + setChildren(newValue); + } + break; + default: super.readField(in, field); + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(CHILDREN__ID); + { + java.util.List values = getChildren(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.nested.data.Level1.Level2.Node x : values) { + x.writeTo(out); + } + out.endArray(); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case CHILDREN__ID: { + in.beginArray(); + while (in.hasNext()) { + addChildren(test.nested.data.Level1.Level2.Node.readNode(in)); + } + in.endArray(); + } + break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.data.Level1.Level2.Composite} type. */ + public static final String COMPOSITE__XML_ELEMENT = "composite"; + + /** XML attribute or element name of a {@link #getChildren} property. */ + private static final String CHILDREN__XML_ATTR = "children"; + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + out.writeStartElement(CHILDREN__XML_ATTR); + for (test.nested.data.Level1.Level2.Node element : getChildren()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.nested.data.Level1.Level2.Composite} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Composite_Impl readComposite_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case test.nested.data.impl.Level1_Impl.Level2_Impl.Branch_Impl.BRANCH__XML_ELEMENT: { + return test.nested.data.impl.Level1_Impl.Level2_Impl.Branch_Impl.readBranch_XmlContent(in); + } + + case test.nested.data.impl.Level1_Impl.Level2_Impl.Root_Impl.ROOT__XML_ELEMENT: { + return test.nested.data.impl.Level1_Impl.Level2_Impl.Root_Impl.readRoot_XmlContent(in); + } + + default: { + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case CHILDREN__XML_ATTR: { + internalReadChildrenListXml(in); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + private void internalReadChildrenListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addChildren(test.nested.data.impl.Level1_Impl.Level2_Impl.Node_Impl.readNode_XmlContent(in)); + } + } + + @Override + public final R visit(test.nested.data.Level1.Level2.Node.Visitor v, A arg) throws E { + return visit((test.nested.data.Level1.Level2.Composite.Visitor) v, arg); + } + + } + /** + * Implementation of {@link test.nested.data.Level1.Level2.Leaf}. + */ + public static class Leaf_Impl extends test.nested.data.impl.Level1_Impl.Level2_Impl.Node_Impl implements test.nested.data.Level1.Level2.Leaf { + + private int _value = 0; + + /** + * Creates a {@link Leaf_Impl} instance. + * + * @see test.nested.data.Level1.Level2.Leaf#create() + */ + public Leaf_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.LEAF; + } + + @Override + public final int getValue() { + return _value; + } + + @Override + public test.nested.data.Level1.Level2.Leaf setValue(int value) { + internalSetValue(value); + return this; + } + + /** Internal setter for {@link #getValue()} without chain call utility. */ + protected final void internalSetValue(int value) { + _listener.beforeSet(this, VALUE__PROP, value); + _value = value; + _listener.afterChanged(this, VALUE__PROP); + } + + @Override + public test.nested.data.Level1.Level2.Leaf setLabel(String value) { + internalSetLabel(value); + return this; + } + + @Override + public String jsonType() { + return LEAF__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + VALUE__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.data.impl.Level1_Impl.Level2_Impl.Node_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.data.impl.Level1_Impl.Level2_Impl.Node_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case VALUE__PROP: return getValue(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case VALUE__PROP: internalSetValue((int) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(VALUE__PROP); + out.value(getValue()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case VALUE__PROP: setValue(in.nextInt()); break; + default: super.readField(in, field); + } + } + + @Override + public int typeId() { + return LEAF__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(VALUE__ID); + out.value(getValue()); + } + + /** Helper for creating an object of type {@link test.nested.data.Level1.Level2.Leaf} from a polymorphic composition. */ + public static test.nested.data.Level1.Level2.Leaf readLeaf_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.Level1_Impl.Level2_Impl.Leaf_Impl result = new Leaf_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case VALUE__ID: setValue(in.nextInt()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.data.Level1.Level2.Leaf} type. */ + public static final String LEAF__XML_ELEMENT = "leaf"; + + /** XML attribute or element name of a {@link #getValue} property. */ + private static final String VALUE__XML_ATTR = "value"; + + @Override + public String getXmlTagName() { + return LEAF__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(VALUE__XML_ATTR, Integer.toString(getValue())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.data.Level1.Level2.Leaf} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Leaf_Impl readLeaf_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Leaf_Impl result = new Leaf_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case VALUE__XML_ATTR: { + setValue(Integer.parseInt(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case VALUE__XML_ATTR: { + setValue(Integer.parseInt(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.nested.data.Level1.Level2.Node.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + + } + /** + * Implementation of {@link test.nested.data.Level1.Level2.Branch}. + */ + public static class Branch_Impl extends test.nested.data.impl.Level1_Impl.Level2_Impl.Composite_Impl implements test.nested.data.Level1.Level2.Branch { + + private boolean _expanded = false; + + /** + * Creates a {@link Branch_Impl} instance. + * + * @see test.nested.data.Level1.Level2.Branch#create() + */ + public Branch_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.BRANCH; + } + + @Override + public final boolean isExpanded() { + return _expanded; + } + + @Override + public test.nested.data.Level1.Level2.Branch setExpanded(boolean value) { + internalSetExpanded(value); + return this; + } + + /** Internal setter for {@link #isExpanded()} without chain call utility. */ + protected final void internalSetExpanded(boolean value) { + _listener.beforeSet(this, EXPANDED__PROP, value); + _expanded = value; + _listener.afterChanged(this, EXPANDED__PROP); + } + + @Override + public test.nested.data.Level1.Level2.Branch setChildren(java.util.List value) { + internalSetChildren(value); + return this; + } + + @Override + public test.nested.data.Level1.Level2.Branch addChildren(test.nested.data.Level1.Level2.Node value) { + internalAddChildren(value); + return this; + } + + @Override + public test.nested.data.Level1.Level2.Branch setLabel(String value) { + internalSetLabel(value); + return this; + } + + @Override + public String jsonType() { + return BRANCH__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + EXPANDED__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.data.impl.Level1_Impl.Level2_Impl.Composite_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.data.impl.Level1_Impl.Level2_Impl.Composite_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case EXPANDED__PROP: return isExpanded(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case EXPANDED__PROP: internalSetExpanded((boolean) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(EXPANDED__PROP); + out.value(isExpanded()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case EXPANDED__PROP: setExpanded(in.nextBoolean()); break; + default: super.readField(in, field); + } + } + + @Override + public int typeId() { + return BRANCH__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(EXPANDED__ID); + out.value(isExpanded()); + } + + /** Helper for creating an object of type {@link test.nested.data.Level1.Level2.Branch} from a polymorphic composition. */ + public static test.nested.data.Level1.Level2.Branch readBranch_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.Level1_Impl.Level2_Impl.Branch_Impl result = new Branch_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case EXPANDED__ID: setExpanded(in.nextBoolean()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.data.Level1.Level2.Branch} type. */ + public static final String BRANCH__XML_ELEMENT = "branch"; + + /** XML attribute or element name of a {@link #isExpanded} property. */ + private static final String EXPANDED__XML_ATTR = "expanded"; + + @Override + public String getXmlTagName() { + return BRANCH__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(EXPANDED__XML_ATTR, Boolean.toString(isExpanded())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.data.Level1.Level2.Branch} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Branch_Impl readBranch_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Branch_Impl result = new Branch_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case EXPANDED__XML_ATTR: { + setExpanded(Boolean.parseBoolean(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case EXPANDED__XML_ATTR: { + setExpanded(Boolean.parseBoolean(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.nested.data.Level1.Level2.Composite.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + + } + /** + * Implementation of {@link test.nested.data.Level1.Level2.Root}. + */ + public static class Root_Impl extends test.nested.data.impl.Level1_Impl.Level2_Impl.Composite_Impl implements test.nested.data.Level1.Level2.Root { + + private String _title = ""; + + /** + * Creates a {@link Root_Impl} instance. + * + * @see test.nested.data.Level1.Level2.Root#create() + */ + public Root_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.ROOT; + } + + @Override + public final String getTitle() { + return _title; + } + + @Override + public test.nested.data.Level1.Level2.Root setTitle(String value) { + internalSetTitle(value); + return this; + } + + /** Internal setter for {@link #getTitle()} without chain call utility. */ + protected final void internalSetTitle(String value) { + _listener.beforeSet(this, TITLE__PROP, value); + _title = value; + _listener.afterChanged(this, TITLE__PROP); + } + + @Override + public test.nested.data.Level1.Level2.Root setChildren(java.util.List value) { + internalSetChildren(value); + return this; + } + + @Override + public test.nested.data.Level1.Level2.Root addChildren(test.nested.data.Level1.Level2.Node value) { + internalAddChildren(value); + return this; + } + + @Override + public test.nested.data.Level1.Level2.Root setLabel(String value) { + internalSetLabel(value); + return this; + } + + @Override + public String jsonType() { + return ROOT__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + TITLE__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.data.impl.Level1_Impl.Level2_Impl.Composite_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.data.impl.Level1_Impl.Level2_Impl.Composite_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case TITLE__PROP: return getTitle(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case TITLE__PROP: internalSetTitle((String) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(TITLE__PROP); + out.value(getTitle()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case TITLE__PROP: setTitle(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + @Override + public int typeId() { + return ROOT__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(TITLE__ID); + out.value(getTitle()); + } + + /** Helper for creating an object of type {@link test.nested.data.Level1.Level2.Root} from a polymorphic composition. */ + public static test.nested.data.Level1.Level2.Root readRoot_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.Level1_Impl.Level2_Impl.Root_Impl result = new Root_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case TITLE__ID: setTitle(in.nextString()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.data.Level1.Level2.Root} type. */ + public static final String ROOT__XML_ELEMENT = "root"; + + /** XML attribute or element name of a {@link #getTitle} property. */ + private static final String TITLE__XML_ATTR = "title"; + + @Override + public String getXmlTagName() { + return ROOT__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(TITLE__XML_ATTR, getTitle()); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.data.Level1.Level2.Root} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Root_Impl readRoot_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Root_Impl result = new Root_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case TITLE__XML_ATTR: { + setTitle(value); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case TITLE__XML_ATTR: { + setTitle(in.getElementText()); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.nested.data.Level1.Level2.Composite.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + + } + + /** + * Creates a {@link Level2_Impl} instance. + * + * @see test.nested.data.Level1.Level2#create() + */ + public Level2_Impl() { + super(); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.data.Level1.Level2 registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.data.Level1.Level2 unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return LEVEL_2__TYPE; + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + // No fields to write, hook for subclasses. + } + + /** Helper for creating an object of type {@link test.nested.data.Level1.Level2} from a polymorphic composition. */ + public static test.nested.data.Level1.Level2 readLevel2_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.Level1_Impl.Level2_Impl result = new Level2_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.data.Level1.Level2} type. */ + public static final String LEVEL_2__XML_ELEMENT = "level-2"; + + @Override + public String getXmlTagName() { + return LEVEL_2__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.nested.data.Level1.Level2} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Level2_Impl readLevel2_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Level2_Impl result = new Level2_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + } + + private test.nested.data.Level1.Level2.Node _node = null; + + private final java.util.List _nodes = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.nested.data.Level1.Level2.Node element) { + _listener.beforeAdd(Level1_Impl.this, NODES__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.nested.data.Level1.Level2.Node element) { + _listener.afterRemove(Level1_Impl.this, NODES__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Level1_Impl.this, NODES__PROP); + } + }; + + /** + * Creates a {@link Level1_Impl} instance. + * + * @see test.nested.data.Level1#create() + */ + public Level1_Impl() { + super(); + } + + @Override + public final test.nested.data.Level1.Level2.Node getNode() { + return _node; + } + + @Override + public test.nested.data.Level1 setNode(test.nested.data.Level1.Level2.Node value) { + internalSetNode(value); + return this; + } + + /** Internal setter for {@link #getNode()} without chain call utility. */ + protected final void internalSetNode(test.nested.data.Level1.Level2.Node value) { + _listener.beforeSet(this, NODE__PROP, value); + _node = value; + _listener.afterChanged(this, NODE__PROP); + } + + @Override + public final boolean hasNode() { + return _node != null; + } + + @Override + public final java.util.List getNodes() { + return _nodes; + } + + @Override + public test.nested.data.Level1 setNodes(java.util.List value) { + internalSetNodes(value); + return this; + } + + /** Internal setter for {@link #getNodes()} without chain call utility. */ + protected final void internalSetNodes(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'nodes' cannot be null."); + _nodes.clear(); + _nodes.addAll(value); + } + + @Override + public test.nested.data.Level1 addNodes(test.nested.data.Level1.Level2.Node value) { + internalAddNodes(value); + return this; + } + + /** Implementation of {@link #addNodes(test.nested.data.Level1.Level2.Node)} without chain call utility. */ + protected final void internalAddNodes(test.nested.data.Level1.Level2.Node value) { + _nodes.add(value); + } + + @Override + public final void removeNodes(test.nested.data.Level1.Level2.Node value) { + _nodes.remove(value); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.data.Level1 registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.data.Level1 unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return LEVEL_1__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + NODE__PROP, + NODES__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NODE__PROP: return getNode(); + case NODES__PROP: return getNodes(); + default: return test.nested.data.Level1.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NODE__PROP: internalSetNode((test.nested.data.Level1.Level2.Node) value); break; + case NODES__PROP: internalSetNodes(de.haumacher.msgbuf.util.Conversions.asList(test.nested.data.Level1.Level2.Node.class, value)); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + if (hasNode()) { + out.name(NODE__PROP); + getNode().writeTo(out); + } + out.name(NODES__PROP); + out.beginArray(); + for (test.nested.data.Level1.Level2.Node x : getNodes()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NODE__PROP: setNode(test.nested.data.Level1.Level2.Node.readNode(in)); break; + case NODES__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.nested.data.Level1.Level2.Node.readNode(in)); + } + in.endArray(); + setNodes(newValue); + } + break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + if (hasNode()) { + out.name(NODE__ID); + getNode().writeTo(out); + } + out.name(NODES__ID); + { + java.util.List values = getNodes(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.nested.data.Level1.Level2.Node x : values) { + x.writeTo(out); + } + out.endArray(); + } + } + + /** Helper for creating an object of type {@link test.nested.data.Level1} from a polymorphic composition. */ + public static test.nested.data.Level1 readLevel1_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.Level1_Impl result = new Level1_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case NODE__ID: setNode(test.nested.data.Level1.Level2.Node.readNode(in)); break; + case NODES__ID: { + in.beginArray(); + while (in.hasNext()) { + addNodes(test.nested.data.Level1.Level2.Node.readNode(in)); + } + in.endArray(); + } + break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.data.Level1} type. */ + public static final String LEVEL_1__XML_ELEMENT = "level-1"; + + /** XML attribute or element name of a {@link #getNode} property. */ + private static final String NODE__XML_ATTR = "node"; + + /** XML attribute or element name of a {@link #getNodes} property. */ + private static final String NODES__XML_ATTR = "nodes"; + + @Override + public String getXmlTagName() { + return LEVEL_1__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasNode()) { + out.writeStartElement(NODE__XML_ATTR); + getNode().writeTo(out); + out.writeEndElement(); + } + out.writeStartElement(NODES__XML_ATTR); + for (test.nested.data.Level1.Level2.Node element : getNodes()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.nested.data.Level1} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Level1_Impl readLevel1_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Level1_Impl result = new Level1_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NODE__XML_ATTR: { + in.nextTag(); + setNode(test.nested.data.impl.Level1_Impl.Level2_Impl.Node_Impl.readNode_XmlContent(in)); + internalSkipUntilMatchingEndElement(in); + break; + } + case NODES__XML_ATTR: { + internalReadNodesListXml(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadNodesListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addNodes(test.nested.data.impl.Level1_Impl.Level2_Impl.Node_Impl.readNode_XmlContent(in)); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Outer_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Outer_Impl.java new file mode 100644 index 00000000..1eccdcb5 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Outer_Impl.java @@ -0,0 +1,1301 @@ +package test.nested.data.impl; + +/** + * Implementation of {@link test.nested.data.Outer}. + */ +public class Outer_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.data.Outer { + /** + * Implementation of {@link test.nested.data.Outer.Shape}. + */ + public static abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.data.Outer.Shape { + + private String _name = ""; + + /** + * Creates a {@link Shape_Impl} instance. + */ + public Shape_Impl() { + super(); + } + + @Override + public final String getName() { + return _name; + } + + @Override + public test.nested.data.Outer.Shape setName(String value) { + internalSetName(value); + return this; + } + + /** Internal setter for {@link #getName()} without chain call utility. */ + protected final void internalSetName(String value) { + _listener.beforeSet(this, NAME__PROP, value); + _name = value; + _listener.afterChanged(this, NAME__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.data.Outer.Shape registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.data.Outer.Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + NAME__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NAME__PROP: return getName(); + default: return test.nested.data.Outer.Shape.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NAME__PROP: internalSetName((String) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.beginArray(); + out.value(jsonType()); + writeContent(out); + out.endArray(); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NAME__PROP); + out.value(getName()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + out.name(0); + out.value(typeId()); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(NAME__ID); + out.value(getName()); + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case NAME__ID: setName(in.nextString()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.data.Outer.Shape} type. */ + public static final String SHAPE__XML_ELEMENT = "shape"; + + /** XML attribute or element name of a {@link #getName} property. */ + private static final String NAME__XML_ATTR = "name"; + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.nested.data.Outer.Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case test.nested.data.impl.Outer_Impl.Circle_Impl.CIRCLE__XML_ELEMENT: { + return test.nested.data.impl.Outer_Impl.Circle_Impl.readCircle_XmlContent(in); + } + + case test.nested.data.impl.Outer_Impl.Square_Impl.SQUARE__XML_ELEMENT: { + return test.nested.data.impl.Outer_Impl.Square_Impl.readSquare_XmlContent(in); + } + + case Triangle_Impl.TRIANGLE__XML_ELEMENT: { + return test.nested.data.impl.Triangle_Impl.readTriangle_XmlContent(in); + } + + default: { + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NAME__XML_ATTR: { + setName(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NAME__XML_ATTR: { + setName(in.getElementText()); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + } + /** + * Implementation of {@link test.nested.data.Outer.Circle}. + */ + public static class Circle_Impl extends test.nested.data.impl.Outer_Impl.Shape_Impl implements test.nested.data.Outer.Circle { + + private int _radius = 0; + + /** + * Creates a {@link Circle_Impl} instance. + * + * @see test.nested.data.Outer.Circle#create() + */ + public Circle_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.CIRCLE; + } + + @Override + public final int getRadius() { + return _radius; + } + + @Override + public test.nested.data.Outer.Circle setRadius(int value) { + internalSetRadius(value); + return this; + } + + /** Internal setter for {@link #getRadius()} without chain call utility. */ + protected final void internalSetRadius(int value) { + _listener.beforeSet(this, RADIUS__PROP, value); + _radius = value; + _listener.afterChanged(this, RADIUS__PROP); + } + + @Override + public test.nested.data.Outer.Circle setName(String value) { + internalSetName(value); + return this; + } + + @Override + public String jsonType() { + return CIRCLE__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + RADIUS__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.data.impl.Outer_Impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.data.impl.Outer_Impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case RADIUS__PROP: return getRadius(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case RADIUS__PROP: internalSetRadius((int) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(RADIUS__PROP); + out.value(getRadius()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case RADIUS__PROP: setRadius(in.nextInt()); break; + default: super.readField(in, field); + } + } + + @Override + public int typeId() { + return CIRCLE__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(RADIUS__ID); + out.value(getRadius()); + } + + /** Helper for creating an object of type {@link test.nested.data.Outer.Circle} from a polymorphic composition. */ + public static test.nested.data.Outer.Circle readCircle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.Outer_Impl.Circle_Impl result = new Circle_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case RADIUS__ID: setRadius(in.nextInt()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.data.Outer.Circle} type. */ + public static final String CIRCLE__XML_ELEMENT = "circle"; + + /** XML attribute or element name of a {@link #getRadius} property. */ + private static final String RADIUS__XML_ATTR = "radius"; + + @Override + public String getXmlTagName() { + return CIRCLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(RADIUS__XML_ATTR, Integer.toString(getRadius())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.data.Outer.Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Circle_Impl result = new Circle_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case RADIUS__XML_ATTR: { + setRadius(Integer.parseInt(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case RADIUS__XML_ATTR: { + setRadius(Integer.parseInt(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.nested.data.Outer.Shape.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + + } + /** + * Implementation of {@link test.nested.data.Outer.Square}. + */ + public static class Square_Impl extends test.nested.data.impl.Outer_Impl.Shape_Impl implements test.nested.data.Outer.Square { + + private int _side = 0; + + /** + * Creates a {@link Square_Impl} instance. + * + * @see test.nested.data.Outer.Square#create() + */ + public Square_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.SQUARE; + } + + @Override + public final int getSide() { + return _side; + } + + @Override + public test.nested.data.Outer.Square setSide(int value) { + internalSetSide(value); + return this; + } + + /** Internal setter for {@link #getSide()} without chain call utility. */ + protected final void internalSetSide(int value) { + _listener.beforeSet(this, SIDE__PROP, value); + _side = value; + _listener.afterChanged(this, SIDE__PROP); + } + + @Override + public test.nested.data.Outer.Square setName(String value) { + internalSetName(value); + return this; + } + + @Override + public String jsonType() { + return SQUARE__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + SIDE__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.data.impl.Outer_Impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.data.impl.Outer_Impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case SIDE__PROP: return getSide(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case SIDE__PROP: internalSetSide((int) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(SIDE__PROP); + out.value(getSide()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case SIDE__PROP: setSide(in.nextInt()); break; + default: super.readField(in, field); + } + } + + @Override + public int typeId() { + return SQUARE__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(SIDE__ID); + out.value(getSide()); + } + + /** Helper for creating an object of type {@link test.nested.data.Outer.Square} from a polymorphic composition. */ + public static test.nested.data.Outer.Square readSquare_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.Outer_Impl.Square_Impl result = new Square_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case SIDE__ID: setSide(in.nextInt()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.data.Outer.Square} type. */ + public static final String SQUARE__XML_ELEMENT = "square"; + + /** XML attribute or element name of a {@link #getSide} property. */ + private static final String SIDE__XML_ATTR = "side"; + + @Override + public String getXmlTagName() { + return SQUARE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(SIDE__XML_ATTR, Integer.toString(getSide())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.data.Outer.Square} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Square_Impl readSquare_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Square_Impl result = new Square_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case SIDE__XML_ATTR: { + setSide(Integer.parseInt(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case SIDE__XML_ATTR: { + setSide(Integer.parseInt(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.nested.data.Outer.Shape.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + + } + /** + * Implementation of {@link test.nested.data.Outer.Drawing}. + */ + public static class Drawing_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.data.Outer.Drawing { + + private test.nested.data.Outer.Shape _main = null; + + private final java.util.List _shapes = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.nested.data.Outer.Shape element) { + _listener.beforeAdd(Drawing_Impl.this, SHAPES__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.nested.data.Outer.Shape element) { + _listener.afterRemove(Drawing_Impl.this, SHAPES__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Drawing_Impl.this, SHAPES__PROP); + } + }; + + /** + * Creates a {@link Drawing_Impl} instance. + * + * @see test.nested.data.Outer.Drawing#create() + */ + public Drawing_Impl() { + super(); + } + + @Override + public final test.nested.data.Outer.Shape getMain() { + return _main; + } + + @Override + public test.nested.data.Outer.Drawing setMain(test.nested.data.Outer.Shape value) { + internalSetMain(value); + return this; + } + + /** Internal setter for {@link #getMain()} without chain call utility. */ + protected final void internalSetMain(test.nested.data.Outer.Shape value) { + _listener.beforeSet(this, MAIN__PROP, value); + _main = value; + _listener.afterChanged(this, MAIN__PROP); + } + + @Override + public final boolean hasMain() { + return _main != null; + } + + @Override + public final java.util.List getShapes() { + return _shapes; + } + + @Override + public test.nested.data.Outer.Drawing setShapes(java.util.List value) { + internalSetShapes(value); + return this; + } + + /** Internal setter for {@link #getShapes()} without chain call utility. */ + protected final void internalSetShapes(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'shapes' cannot be null."); + _shapes.clear(); + _shapes.addAll(value); + } + + @Override + public test.nested.data.Outer.Drawing addShape(test.nested.data.Outer.Shape value) { + internalAddShape(value); + return this; + } + + /** Implementation of {@link #addShape(test.nested.data.Outer.Shape)} without chain call utility. */ + protected final void internalAddShape(test.nested.data.Outer.Shape value) { + _shapes.add(value); + } + + @Override + public final void removeShape(test.nested.data.Outer.Shape value) { + _shapes.remove(value); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.data.Outer.Drawing registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.data.Outer.Drawing unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return DRAWING__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + MAIN__PROP, + SHAPES__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case MAIN__PROP: return getMain(); + case SHAPES__PROP: return getShapes(); + default: return test.nested.data.Outer.Drawing.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case MAIN__PROP: internalSetMain((test.nested.data.Outer.Shape) value); break; + case SHAPES__PROP: internalSetShapes(de.haumacher.msgbuf.util.Conversions.asList(test.nested.data.Outer.Shape.class, value)); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + if (hasMain()) { + out.name(MAIN__PROP); + getMain().writeTo(out); + } + out.name(SHAPES__PROP); + out.beginArray(); + for (test.nested.data.Outer.Shape x : getShapes()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case MAIN__PROP: setMain(test.nested.data.Outer.Shape.readShape(in)); break; + case SHAPES__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.nested.data.Outer.Shape.readShape(in)); + } + in.endArray(); + setShapes(newValue); + } + break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + if (hasMain()) { + out.name(MAIN__ID); + getMain().writeTo(out); + } + out.name(SHAPES__ID); + { + java.util.List values = getShapes(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.nested.data.Outer.Shape x : values) { + x.writeTo(out); + } + out.endArray(); + } + } + + /** Helper for creating an object of type {@link test.nested.data.Outer.Drawing} from a polymorphic composition. */ + public static test.nested.data.Outer.Drawing readDrawing_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.Outer_Impl.Drawing_Impl result = new Drawing_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case MAIN__ID: setMain(test.nested.data.Outer.Shape.readShape(in)); break; + case SHAPES__ID: { + in.beginArray(); + while (in.hasNext()) { + addShape(test.nested.data.Outer.Shape.readShape(in)); + } + in.endArray(); + } + break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.data.Outer.Drawing} type. */ + public static final String DRAWING__XML_ELEMENT = "drawing"; + + /** XML attribute or element name of a {@link #getMain} property. */ + private static final String MAIN__XML_ATTR = "main"; + + /** XML attribute or element name of a {@link #getShapes} property. */ + private static final String SHAPES__XML_ATTR = "shapes"; + + @Override + public String getXmlTagName() { + return DRAWING__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasMain()) { + out.writeStartElement(MAIN__XML_ATTR); + getMain().writeTo(out); + out.writeEndElement(); + } + out.writeStartElement(SHAPES__XML_ATTR); + for (test.nested.data.Outer.Shape element : getShapes()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.nested.data.Outer.Drawing} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Drawing_Impl readDrawing_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Drawing_Impl result = new Drawing_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case MAIN__XML_ATTR: { + in.nextTag(); + setMain(test.nested.data.impl.Outer_Impl.Shape_Impl.readShape_XmlContent(in)); + internalSkipUntilMatchingEndElement(in); + break; + } + case SHAPES__XML_ATTR: { + internalReadShapesListXml(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadShapesListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addShape(test.nested.data.impl.Outer_Impl.Shape_Impl.readShape_XmlContent(in)); + } + } + + } + + private test.nested.data.Outer.Shape _shape = null; + + /** + * Creates a {@link Outer_Impl} instance. + * + * @see test.nested.data.Outer#create() + */ + public Outer_Impl() { + super(); + } + + @Override + public final test.nested.data.Outer.Shape getShape() { + return _shape; + } + + @Override + public test.nested.data.Outer setShape(test.nested.data.Outer.Shape value) { + internalSetShape(value); + return this; + } + + /** Internal setter for {@link #getShape()} without chain call utility. */ + protected final void internalSetShape(test.nested.data.Outer.Shape value) { + _listener.beforeSet(this, SHAPE__PROP, value); + _shape = value; + _listener.afterChanged(this, SHAPE__PROP); + } + + @Override + public final boolean hasShape() { + return _shape != null; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.data.Outer registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.data.Outer unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return OUTER__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + SHAPE__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case SHAPE__PROP: return getShape(); + default: return test.nested.data.Outer.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case SHAPE__PROP: internalSetShape((test.nested.data.Outer.Shape) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + if (hasShape()) { + out.name(SHAPE__PROP); + getShape().writeTo(out); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case SHAPE__PROP: setShape(test.nested.data.Outer.Shape.readShape(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + if (hasShape()) { + out.name(SHAPE__ID); + getShape().writeTo(out); + } + } + + /** Helper for creating an object of type {@link test.nested.data.Outer} from a polymorphic composition. */ + public static test.nested.data.Outer readOuter_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.Outer_Impl result = new Outer_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case SHAPE__ID: setShape(test.nested.data.Outer.Shape.readShape(in)); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.data.Outer} type. */ + public static final String OUTER__XML_ELEMENT = "outer"; + + /** XML attribute or element name of a {@link #getShape} property. */ + private static final String SHAPE__XML_ATTR = "shape"; + + @Override + public String getXmlTagName() { + return OUTER__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasShape()) { + out.writeStartElement(SHAPE__XML_ATTR); + getShape().writeTo(out); + out.writeEndElement(); + } + } + + /** Creates a new {@link test.nested.data.Outer} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Outer_Impl readOuter_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Outer_Impl result = new Outer_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case SHAPE__XML_ATTR: { + in.nextTag(); + setShape(test.nested.data.impl.Outer_Impl.Shape_Impl.readShape_XmlContent(in)); + internalSkipUntilMatchingEndElement(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Triangle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Triangle_Impl.java new file mode 100644 index 00000000..64a87441 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Triangle_Impl.java @@ -0,0 +1,246 @@ +package test.nested.data.impl; + +/** + * Implementation of {@link test.nested.data.Triangle}. + */ +public class Triangle_Impl extends test.nested.data.impl.Outer_Impl.Shape_Impl implements test.nested.data.Triangle { + + private int _base = 0; + + private int _height = 0; + + /** + * Creates a {@link Triangle_Impl} instance. + * + * @see test.nested.data.Triangle#create() + */ + public Triangle_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.TRIANGLE; + } + + @Override + public final int getBase() { + return _base; + } + + @Override + public test.nested.data.Triangle setBase(int value) { + internalSetBase(value); + return this; + } + + /** Internal setter for {@link #getBase()} without chain call utility. */ + protected final void internalSetBase(int value) { + _listener.beforeSet(this, BASE__PROP, value); + _base = value; + _listener.afterChanged(this, BASE__PROP); + } + + @Override + public final int getHeight() { + return _height; + } + + @Override + public test.nested.data.Triangle setHeight(int value) { + internalSetHeight(value); + return this; + } + + /** Internal setter for {@link #getHeight()} without chain call utility. */ + protected final void internalSetHeight(int value) { + _listener.beforeSet(this, HEIGHT__PROP, value); + _height = value; + _listener.afterChanged(this, HEIGHT__PROP); + } + + @Override + public test.nested.data.Triangle setName(String value) { + internalSetName(value); + return this; + } + + @Override + public String jsonType() { + return TRIANGLE__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + BASE__PROP, + HEIGHT__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.data.impl.Outer_Impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.data.impl.Outer_Impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case BASE__PROP: return getBase(); + case HEIGHT__PROP: return getHeight(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case BASE__PROP: internalSetBase((int) value); break; + case HEIGHT__PROP: internalSetHeight((int) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(BASE__PROP); + out.value(getBase()); + out.name(HEIGHT__PROP); + out.value(getHeight()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case BASE__PROP: setBase(in.nextInt()); break; + case HEIGHT__PROP: setHeight(in.nextInt()); break; + default: super.readField(in, field); + } + } + + @Override + public int typeId() { + return TRIANGLE__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(BASE__ID); + out.value(getBase()); + out.name(HEIGHT__ID); + out.value(getHeight()); + } + + /** Helper for creating an object of type {@link test.nested.data.Triangle} from a polymorphic composition. */ + public static test.nested.data.Triangle readTriangle_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.Triangle_Impl result = new Triangle_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case BASE__ID: setBase(in.nextInt()); break; + case HEIGHT__ID: setHeight(in.nextInt()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.data.Triangle} type. */ + public static final String TRIANGLE__XML_ELEMENT = "triangle"; + + /** XML attribute or element name of a {@link #getBase} property. */ + private static final String BASE__XML_ATTR = "base"; + + /** XML attribute or element name of a {@link #getHeight} property. */ + private static final String HEIGHT__XML_ATTR = "height"; + + @Override + public String getXmlTagName() { + return TRIANGLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(BASE__XML_ATTR, Integer.toString(getBase())); + out.writeAttribute(HEIGHT__XML_ATTR, Integer.toString(getHeight())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.data.Triangle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Triangle_Impl readTriangle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Triangle_Impl result = new Triangle_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case BASE__XML_ATTR: { + setBase(Integer.parseInt(value)); + break; + } + case HEIGHT__XML_ATTR: { + setHeight(Integer.parseInt(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case BASE__XML_ATTR: { + setBase(Integer.parseInt(in.getElementText())); + break; + } + case HEIGHT__XML_ATTR: { + setHeight(Integer.parseInt(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.nested.data.Outer.Shape.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Zoo_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Zoo_Impl.java new file mode 100644 index 00000000..83c78376 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/data/impl/Zoo_Impl.java @@ -0,0 +1,974 @@ +package test.nested.data.impl; + +/** + * Implementation of {@link test.nested.data.Zoo}. + */ +public class Zoo_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.data.Zoo { + /** + * Implementation of {@link test.nested.data.Zoo.Cat}. + */ + public static class Cat_Impl extends test.nested.data.impl.Animal_Impl implements test.nested.data.Zoo.Cat { + + private boolean _indoor = false; + + /** + * Creates a {@link Cat_Impl} instance. + * + * @see test.nested.data.Zoo.Cat#create() + */ + public Cat_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.CAT; + } + + @Override + public final boolean isIndoor() { + return _indoor; + } + + @Override + public test.nested.data.Zoo.Cat setIndoor(boolean value) { + internalSetIndoor(value); + return this; + } + + /** Internal setter for {@link #isIndoor()} without chain call utility. */ + protected final void internalSetIndoor(boolean value) { + _listener.beforeSet(this, INDOOR__PROP, value); + _indoor = value; + _listener.afterChanged(this, INDOOR__PROP); + } + + @Override + public test.nested.data.Zoo.Cat setName(String value) { + internalSetName(value); + return this; + } + + @Override + public String jsonType() { + return CAT__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + INDOOR__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.data.impl.Animal_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.data.impl.Animal_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case INDOOR__PROP: return isIndoor(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case INDOOR__PROP: internalSetIndoor((boolean) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(INDOOR__PROP); + out.value(isIndoor()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case INDOOR__PROP: setIndoor(in.nextBoolean()); break; + default: super.readField(in, field); + } + } + + @Override + public int typeId() { + return CAT__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(INDOOR__ID); + out.value(isIndoor()); + } + + /** Helper for creating an object of type {@link test.nested.data.Zoo.Cat} from a polymorphic composition. */ + public static test.nested.data.Zoo.Cat readCat_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.Zoo_Impl.Cat_Impl result = new Cat_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case INDOOR__ID: setIndoor(in.nextBoolean()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.data.Zoo.Cat} type. */ + public static final String CAT__XML_ELEMENT = "cat"; + + /** XML attribute or element name of a {@link #isIndoor} property. */ + private static final String INDOOR__XML_ATTR = "indoor"; + + @Override + public String getXmlTagName() { + return CAT__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(INDOOR__XML_ATTR, Boolean.toString(isIndoor())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.data.Zoo.Cat} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Cat_Impl readCat_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Cat_Impl result = new Cat_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case INDOOR__XML_ATTR: { + setIndoor(Boolean.parseBoolean(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case INDOOR__XML_ATTR: { + setIndoor(Boolean.parseBoolean(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.nested.data.Animal.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + + } + /** + * Implementation of {@link test.nested.data.Zoo.Bird}. + */ + public static abstract class Bird_Impl extends test.nested.data.impl.Animal_Impl implements test.nested.data.Zoo.Bird { + + private double _wingspan = 0.0d; + + /** + * Creates a {@link Bird_Impl} instance. + */ + public Bird_Impl() { + super(); + } + + @Override + public final double getWingspan() { + return _wingspan; + } + + @Override + public test.nested.data.Zoo.Bird setWingspan(double value) { + internalSetWingspan(value); + return this; + } + + /** Internal setter for {@link #getWingspan()} without chain call utility. */ + protected final void internalSetWingspan(double value) { + _listener.beforeSet(this, WINGSPAN__PROP, value); + _wingspan = value; + _listener.afterChanged(this, WINGSPAN__PROP); + } + + @Override + public test.nested.data.Zoo.Bird setName(String value) { + internalSetName(value); + return this; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + WINGSPAN__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.data.impl.Animal_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.data.impl.Animal_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case WINGSPAN__PROP: return getWingspan(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case WINGSPAN__PROP: internalSetWingspan((double) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(WINGSPAN__PROP); + out.value(getWingspan()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case WINGSPAN__PROP: setWingspan(in.nextDouble()); break; + default: super.readField(in, field); + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(WINGSPAN__ID); + out.value(getWingspan()); + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case WINGSPAN__ID: setWingspan(in.nextDouble()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.data.Zoo.Bird} type. */ + public static final String BIRD__XML_ELEMENT = "bird"; + + /** XML attribute or element name of a {@link #getWingspan} property. */ + private static final String WINGSPAN__XML_ATTR = "wingspan"; + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WINGSPAN__XML_ATTR, Double.toString(getWingspan())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.data.Zoo.Bird} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Bird_Impl readBird_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case test.nested.data.impl.Zoo_Impl.Parrot_Impl.PARROT__XML_ELEMENT: { + return test.nested.data.impl.Zoo_Impl.Parrot_Impl.readParrot_XmlContent(in); + } + + default: { + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case WINGSPAN__XML_ATTR: { + setWingspan(Double.parseDouble(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case WINGSPAN__XML_ATTR: { + setWingspan(Double.parseDouble(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public final R visit(test.nested.data.Animal.Visitor v, A arg) throws E { + return visit((test.nested.data.Zoo.Bird.Visitor) v, arg); + } + + } + /** + * Implementation of {@link test.nested.data.Zoo.Parrot}. + */ + public static class Parrot_Impl extends test.nested.data.impl.Zoo_Impl.Bird_Impl implements test.nested.data.Zoo.Parrot { + + private final java.util.List _words = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, String element) { + _listener.beforeAdd(Parrot_Impl.this, WORDS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, String element) { + _listener.afterRemove(Parrot_Impl.this, WORDS__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Parrot_Impl.this, WORDS__PROP); + } + }; + + /** + * Creates a {@link Parrot_Impl} instance. + * + * @see test.nested.data.Zoo.Parrot#create() + */ + public Parrot_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.PARROT; + } + + @Override + public final java.util.List getWords() { + return _words; + } + + @Override + public test.nested.data.Zoo.Parrot setWords(java.util.List value) { + internalSetWords(value); + return this; + } + + /** Internal setter for {@link #getWords()} without chain call utility. */ + protected final void internalSetWords(java.util.List value) { + _words.clear(); + _words.addAll(value); + } + + @Override + public test.nested.data.Zoo.Parrot addWord(String value) { + internalAddWord(value); + return this; + } + + /** Implementation of {@link #addWord(String)} without chain call utility. */ + protected final void internalAddWord(String value) { + _words.add(value); + } + + @Override + public final void removeWord(String value) { + _words.remove(value); + } + + @Override + public test.nested.data.Zoo.Parrot setWingspan(double value) { + internalSetWingspan(value); + return this; + } + + @Override + public test.nested.data.Zoo.Parrot setName(String value) { + internalSetName(value); + return this; + } + + @Override + public String jsonType() { + return PARROT__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + WORDS__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.data.impl.Zoo_Impl.Bird_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.data.impl.Zoo_Impl.Bird_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case WORDS__PROP: return getWords(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case WORDS__PROP: internalSetWords(de.haumacher.msgbuf.util.Conversions.asList(String.class, value)); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(WORDS__PROP); + out.beginArray(); + for (String x : getWords()) { + out.value(x); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case WORDS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); + } + in.endArray(); + setWords(newValue); + } + break; + default: super.readField(in, field); + } + } + + @Override + public int typeId() { + return PARROT__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(WORDS__ID); + { + java.util.List values = getWords(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.STRING, values.size()); + for (String x : values) { + out.value(x); + } + out.endArray(); + } + } + + /** Helper for creating an object of type {@link test.nested.data.Zoo.Parrot} from a polymorphic composition. */ + public static test.nested.data.Zoo.Parrot readParrot_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.Zoo_Impl.Parrot_Impl result = new Parrot_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case WORDS__ID: { + in.beginArray(); + while (in.hasNext()) { + addWord(in.nextString()); + } + in.endArray(); + } + break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.data.Zoo.Parrot} type. */ + public static final String PARROT__XML_ELEMENT = "parrot"; + + /** XML attribute or element name of a {@link #getWords} property. */ + private static final String WORDS__XML_ATTR = "words"; + + @Override + public String getXmlTagName() { + return PARROT__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WORDS__XML_ATTR, getWords().stream().map(x -> x).collect(java.util.stream.Collectors.joining(", "))); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.data.Zoo.Parrot} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Parrot_Impl readParrot_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Parrot_Impl result = new Parrot_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case WORDS__XML_ATTR: { + setWords(java.util.Arrays.stream(value.split("\\s*,\\s*")).map(x -> x).collect(java.util.stream.Collectors.toList())); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case WORDS__XML_ATTR: { + setWords(java.util.Arrays.stream(in.getElementText().split("\\s*,\\s*")).map(x -> x).collect(java.util.stream.Collectors.toList())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.nested.data.Zoo.Bird.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + + } + + private final java.util.List _animals = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.nested.data.Animal element) { + _listener.beforeAdd(Zoo_Impl.this, ANIMALS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.nested.data.Animal element) { + _listener.afterRemove(Zoo_Impl.this, ANIMALS__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Zoo_Impl.this, ANIMALS__PROP); + } + }; + + /** + * Creates a {@link Zoo_Impl} instance. + * + * @see test.nested.data.Zoo#create() + */ + public Zoo_Impl() { + super(); + } + + @Override + public final java.util.List getAnimals() { + return _animals; + } + + @Override + public test.nested.data.Zoo setAnimals(java.util.List value) { + internalSetAnimals(value); + return this; + } + + /** Internal setter for {@link #getAnimals()} without chain call utility. */ + protected final void internalSetAnimals(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'animals' cannot be null."); + _animals.clear(); + _animals.addAll(value); + } + + @Override + public test.nested.data.Zoo addAnimal(test.nested.data.Animal value) { + internalAddAnimal(value); + return this; + } + + /** Implementation of {@link #addAnimal(test.nested.data.Animal)} without chain call utility. */ + protected final void internalAddAnimal(test.nested.data.Animal value) { + _animals.add(value); + } + + @Override + public final void removeAnimal(test.nested.data.Animal value) { + _animals.remove(value); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.data.Zoo registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.data.Zoo unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return ZOO__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + ANIMALS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case ANIMALS__PROP: return getAnimals(); + default: return test.nested.data.Zoo.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case ANIMALS__PROP: internalSetAnimals(de.haumacher.msgbuf.util.Conversions.asList(test.nested.data.Animal.class, value)); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(ANIMALS__PROP); + out.beginArray(); + for (test.nested.data.Animal x : getAnimals()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case ANIMALS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.nested.data.Animal.readAnimal(in)); + } + in.endArray(); + setAnimals(newValue); + } + break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(ANIMALS__ID); + { + java.util.List values = getAnimals(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.nested.data.Animal x : values) { + x.writeTo(out); + } + out.endArray(); + } + } + + /** Helper for creating an object of type {@link test.nested.data.Zoo} from a polymorphic composition. */ + public static test.nested.data.Zoo readZoo_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.data.impl.Zoo_Impl result = new Zoo_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case ANIMALS__ID: { + in.beginArray(); + while (in.hasNext()) { + addAnimal(test.nested.data.Animal.readAnimal(in)); + } + in.endArray(); + } + break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.data.Zoo} type. */ + public static final String ZOO__XML_ELEMENT = "zoo"; + + /** XML attribute or element name of a {@link #getAnimals} property. */ + private static final String ANIMALS__XML_ATTR = "animals"; + + @Override + public String getXmlTagName() { + return ZOO__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeStartElement(ANIMALS__XML_ATTR); + for (test.nested.data.Animal element : getAnimals()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.nested.data.Zoo} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Zoo_Impl readZoo_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Zoo_Impl result = new Zoo_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case ANIMALS__XML_ATTR: { + internalReadAnimalsListXml(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadAnimalsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addAnimal(test.nested.data.impl.Animal_Impl.readAnimal_XmlContent(in)); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/Doc.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/Doc.java new file mode 100644 index 00000000..2b900744 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/Doc.java @@ -0,0 +1,522 @@ +package test.nested.doc; + +/** + * A hierarchy nested two levels deep with an abstract intermediate, a nested enum, a reserved-word + * property and message name, and fields holding it as repeated, map and nullable values (issue #16). + */ +public interface Doc extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + public interface Sec extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + public interface Item extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** Type codes for the {@link test.nested.doc.Doc.Sec.Item} hierarchy. */ + public enum TypeKind { + + /** Type literal for {@link test.nested.doc.Doc.Sec.Para}. */ + PARA, + + /** Type literal for {@link test.nested.doc.Doc.Sec.Case}. */ + CASE, + + /** Type literal for {@link test.nested.doc.Figure}. */ + FIGURE, + ; + + } + + /** Visitor interface for the {@link test.nested.doc.Doc.Sec.Item} hierarchy.*/ + public interface Visitor extends test.nested.doc.Doc.Sec.Block.Visitor { + + // Pure sum interface. + + } + + public enum Kind implements de.haumacher.msgbuf.data.ProtocolEnum { + + PLAIN("PLAIN"), + + RICH("RICH"), + + ; + + private final String _protocolName; + + private Kind(String protocolName) { + _protocolName = protocolName; + } + + /** + * The protocol name of a {@link Kind} constant. + * + * @see #valueOfProtocol(String) + */ + @Override + public String protocolName() { + return _protocolName; + } + + /** Looks up a {@link Kind} constant by it's protocol name. */ + public static Kind valueOfProtocol(String protocolName) { + if (protocolName == null) { return null; } + switch (protocolName) { + case "PLAIN": return PLAIN; + case "RICH": return RICH; + } + return PLAIN; + } + + /** Writes this instance to the given output. */ + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.value(protocolName()); + } + + /** Reads a new instance from the given reader. */ + public static Kind readKind(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + return valueOfProtocol(in.nextString()); + } + + /** Writes this instance to the given binary output. */ + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + switch (this) { + case PLAIN: out.value(1); break; + case RICH: out.value(2); break; + default: out.value(0); + } + } + + /** Reads a new instance from the given binary reader. */ + public static Kind readKind(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + switch (in.nextInt()) { + case 1: return PLAIN; + case 2: return RICH; + default: return PLAIN; + } + } + } + + /** @see #getKind() */ + String KIND__PROP = "kind"; + + /** @see #getPackage() */ + String PACKAGE__PROP = "package"; + + /** Identifier for the property {@link #getKind()} in binary format. */ + static final int KIND__ID = 1; + + /** Identifier for the property {@link #getPackage()} in binary format. */ + static final int PACKAGE__ID = 2; + + /** The type code of this instance. */ + TypeKind kind(); + + test.nested.doc.Doc.Sec.Item.Kind getKind(); + + /** + * @see #getKind() + */ + test.nested.doc.Doc.Sec.Item setKind(test.nested.doc.Doc.Sec.Item.Kind value); + + String getPackage(); + + /** + * @see #getPackage() + */ + test.nested.doc.Doc.Sec.Item setPackage(String value); + + @Override + public test.nested.doc.Doc.Sec.Item registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.doc.Doc.Sec.Item unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.doc.Doc.Sec.Item readItem(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.doc.Doc.Sec.Item result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case test.nested.doc.Doc.Sec.Para.PARA__TYPE: result = test.nested.doc.Doc.Sec.Para.readPara(in); break; + case test.nested.doc.Doc.Sec.Case.CASE__TYPE: result = test.nested.doc.Doc.Sec.Case.readCase(in); break; + case Figure.FIGURE__TYPE: result = test.nested.doc.Figure.readFigure(in); break; + default: in.skipValue(); result = null; break; + } + in.endArray(); + return result; + } + + /** The binary identifier for this concrete type in the polymorphic {@link test.nested.doc.Doc.Sec.Item} hierarchy. */ + abstract int typeId(); + + /** Reads a new instance from the given reader. */ + static test.nested.doc.Doc.Sec.Item readItem(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + int typeField = in.nextName(); + assert typeField == 0; + int type = in.nextInt(); + test.nested.doc.Doc.Sec.Item result; + switch (type) { + case test.nested.doc.Doc.Sec.Para.PARA__TYPE_ID: result = test.nested.doc.impl.Doc_Impl.Sec_Impl.Para_Impl.readPara_Content(in); break; + case test.nested.doc.Doc.Sec.Case.CASE__TYPE_ID: result = test.nested.doc.impl.Doc_Impl.Sec_Impl.Case_Impl.readCase_Content(in); break; + case test.nested.doc.Figure.FIGURE__TYPE_ID: result = test.nested.doc.impl.Figure_Impl.readFigure_Content(in); break; + default: result = null; while (in.hasNext()) {in.skipValue(); } + } + in.endObject(); + return result; + } + + /** Creates a new {@link Item} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Item readItem(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.doc.impl.Doc_Impl.Sec_Impl.Item_Impl.readItem_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + + } + public interface Block extends test.nested.doc.Doc.Sec.Item { + + /** Visitor interface for the {@link test.nested.doc.Doc.Sec.Block} hierarchy.*/ + public interface Visitor { + + /** Visit case for {@link test.nested.doc.Doc.Sec.Para}.*/ + R visit(test.nested.doc.Doc.Sec.Para self, A arg) throws E; + + /** Visit case for {@link test.nested.doc.Doc.Sec.Case}.*/ + R visit(test.nested.doc.Doc.Sec.Case self, A arg) throws E; + + /** Visit case for {@link test.nested.doc.Figure}.*/ + R visit(test.nested.doc.Figure self, A arg) throws E; + + } + + /** @see #getWeight() */ + String WEIGHT__PROP = "weight"; + + /** Identifier for the property {@link #getWeight()} in binary format. */ + static final int WEIGHT__ID = 3; + + int getWeight(); + + /** + * @see #getWeight() + */ + test.nested.doc.Doc.Sec.Block setWeight(int value); + + @Override + test.nested.doc.Doc.Sec.Block setKind(test.nested.doc.Doc.Sec.Item.Kind value); + + @Override + test.nested.doc.Doc.Sec.Block setPackage(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.doc.Doc.Sec.Block readBlock(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.doc.Doc.Sec.Block result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case test.nested.doc.Doc.Sec.Para.PARA__TYPE: result = test.nested.doc.Doc.Sec.Para.readPara(in); break; + case test.nested.doc.Doc.Sec.Case.CASE__TYPE: result = test.nested.doc.Doc.Sec.Case.readCase(in); break; + case Figure.FIGURE__TYPE: result = test.nested.doc.Figure.readFigure(in); break; + default: in.skipValue(); result = null; break; + } + in.endArray(); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.doc.Doc.Sec.Block readBlock(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + int typeField = in.nextName(); + assert typeField == 0; + int type = in.nextInt(); + test.nested.doc.Doc.Sec.Block result; + switch (type) { + case test.nested.doc.Doc.Sec.Para.PARA__TYPE_ID: result = test.nested.doc.impl.Doc_Impl.Sec_Impl.Para_Impl.readPara_Content(in); break; + case test.nested.doc.Doc.Sec.Case.CASE__TYPE_ID: result = test.nested.doc.impl.Doc_Impl.Sec_Impl.Case_Impl.readCase_Content(in); break; + case test.nested.doc.Figure.FIGURE__TYPE_ID: result = test.nested.doc.impl.Figure_Impl.readFigure_Content(in); break; + default: result = null; while (in.hasNext()) {in.skipValue(); } + } + in.endObject(); + return result; + } + + /** Creates a new {@link Block} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Block readBlock(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.doc.impl.Doc_Impl.Sec_Impl.Block_Impl.readBlock_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + + } + public interface Para extends test.nested.doc.Doc.Sec.Block { + + /** + * Creates a {@link test.nested.doc.Doc.Sec.Para} instance. + */ + static test.nested.doc.Doc.Sec.Para create() { + return new test.nested.doc.impl.Doc_Impl.Sec_Impl.Para_Impl(); + } + + /** Identifier for the {@link test.nested.doc.Doc.Sec.Para} type in JSON format. */ + String PARA__TYPE = "Para"; + + /** @see #getText() */ + String TEXT__PROP = "text"; + + /** Identifier for the {@link test.nested.doc.Doc.Sec.Para} type in binary format. */ + static final int PARA__TYPE_ID = 1; + + /** Identifier for the property {@link #getText()} in binary format. */ + static final int TEXT__ID = 4; + + String getText(); + + /** + * @see #getText() + */ + test.nested.doc.Doc.Sec.Para setText(String value); + + @Override + test.nested.doc.Doc.Sec.Para setWeight(int value); + + @Override + test.nested.doc.Doc.Sec.Para setKind(test.nested.doc.Doc.Sec.Item.Kind value); + + @Override + test.nested.doc.Doc.Sec.Para setPackage(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.doc.Doc.Sec.Para readPara(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.doc.impl.Doc_Impl.Sec_Impl.Para_Impl result = new test.nested.doc.impl.Doc_Impl.Sec_Impl.Para_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.doc.Doc.Sec.Para readPara(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.doc.Doc.Sec.Para result = test.nested.doc.impl.Doc_Impl.Sec_Impl.Para_Impl.readPara_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Para} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Para readPara(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.doc.impl.Doc_Impl.Sec_Impl.Para_Impl.readPara_XmlContent(in); + } + + } + public interface Case extends test.nested.doc.Doc.Sec.Block { + + /** + * Creates a {@link test.nested.doc.Doc.Sec.Case} instance. + */ + static test.nested.doc.Doc.Sec.Case create() { + return new test.nested.doc.impl.Doc_Impl.Sec_Impl.Case_Impl(); + } + + /** Identifier for the {@link test.nested.doc.Doc.Sec.Case} type in JSON format. */ + String CASE__TYPE = "Case"; + + /** @see #getChildren() */ + String CHILDREN__PROP = "children"; + + /** Identifier for the {@link test.nested.doc.Doc.Sec.Case} type in binary format. */ + static final int CASE__TYPE_ID = 2; + + /** Identifier for the property {@link #getChildren()} in binary format. */ + static final int CHILDREN__ID = 4; + + java.util.List getChildren(); + + /** + * @see #getChildren() + */ + test.nested.doc.Doc.Sec.Case setChildren(java.util.List value); + + /** + * Adds a value to the {@link #getChildren()} list. + */ + test.nested.doc.Doc.Sec.Case addChildren(test.nested.doc.Doc.Sec.Item value); + + /** + * Removes a value from the {@link #getChildren()} list. + */ + void removeChildren(test.nested.doc.Doc.Sec.Item value); + + @Override + test.nested.doc.Doc.Sec.Case setWeight(int value); + + @Override + test.nested.doc.Doc.Sec.Case setKind(test.nested.doc.Doc.Sec.Item.Kind value); + + @Override + test.nested.doc.Doc.Sec.Case setPackage(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.doc.Doc.Sec.Case readCase(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.doc.impl.Doc_Impl.Sec_Impl.Case_Impl result = new test.nested.doc.impl.Doc_Impl.Sec_Impl.Case_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.doc.Doc.Sec.Case readCase(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.doc.Doc.Sec.Case result = test.nested.doc.impl.Doc_Impl.Sec_Impl.Case_Impl.readCase_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Case} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Case readCase(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.doc.impl.Doc_Impl.Sec_Impl.Case_Impl.readCase_XmlContent(in); + } + + } + + /** + * Creates a {@link test.nested.doc.Doc.Sec} instance. + */ + static test.nested.doc.Doc.Sec create() { + return new test.nested.doc.impl.Doc_Impl.Sec_Impl(); + } + + /** Identifier for the {@link test.nested.doc.Doc.Sec} type in JSON format. */ + String SEC__TYPE = "Sec"; + + @Override + public test.nested.doc.Doc.Sec registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.doc.Doc.Sec unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.doc.Doc.Sec readSec(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.doc.impl.Doc_Impl.Sec_Impl result = new test.nested.doc.impl.Doc_Impl.Sec_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.doc.Doc.Sec readSec(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.doc.Doc.Sec result = test.nested.doc.impl.Doc_Impl.Sec_Impl.readSec_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Sec} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Sec readSec(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.doc.impl.Doc_Impl.Sec_Impl.readSec_XmlContent(in); + } + + } + + /** + * Creates a {@link test.nested.doc.Doc} instance. + */ + static test.nested.doc.Doc create() { + return new test.nested.doc.impl.Doc_Impl(); + } + + /** Identifier for the {@link test.nested.doc.Doc} type in JSON format. */ + String DOC__TYPE = "Doc"; + + /** @see #getItems() */ + String ITEMS__PROP = "items"; + + /** @see #getByName() */ + String BY_NAME__PROP = "byName"; + + /** @see #getMaybe() */ + String MAYBE__PROP = "maybe"; + + /** Identifier for the property {@link #getItems()} in binary format. */ + static final int ITEMS__ID = 1; + + /** Identifier for the property {@link #getByName()} in binary format. */ + static final int BY_NAME__ID = 2; + + /** Identifier for the property {@link #getMaybe()} in binary format. */ + static final int MAYBE__ID = 3; + + java.util.List getItems(); + + /** + * @see #getItems() + */ + test.nested.doc.Doc setItems(java.util.List value); + + /** + * Adds a value to the {@link #getItems()} list. + */ + test.nested.doc.Doc addItem(test.nested.doc.Doc.Sec.Item value); + + /** + * Removes a value from the {@link #getItems()} list. + */ + void removeItem(test.nested.doc.Doc.Sec.Item value); + + java.util.Map getByName(); + + /** + * @see #getByName() + */ + test.nested.doc.Doc setByName(java.util.Map value); + + /** + * Adds a key value pair to the {@link #getByName()} map. + */ + test.nested.doc.Doc putByName(String key, test.nested.doc.Doc.Sec.Item value); + + /** + * Removes a key from the {@link #getByName()} map. + */ + void removeByName(String key); + + test.nested.doc.Doc.Sec.Item getMaybe(); + + /** + * @see #getMaybe() + */ + test.nested.doc.Doc setMaybe(test.nested.doc.Doc.Sec.Item value); + + /** + * Checks, whether {@link #getMaybe()} has a value. + */ + boolean hasMaybe(); + + @Override + public test.nested.doc.Doc registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.doc.Doc unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.doc.Doc readDoc(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.doc.impl.Doc_Impl result = new test.nested.doc.impl.Doc_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.doc.Doc readDoc(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.doc.Doc result = test.nested.doc.impl.Doc_Impl.readDoc_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Doc} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Doc readDoc(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.doc.impl.Doc_Impl.readDoc_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/Figure.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/Figure.java new file mode 100644 index 00000000..75e0a679 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/Figure.java @@ -0,0 +1,64 @@ +package test.nested.doc; + +/** + * A top-level specialization of a nested abstract intermediate. + */ +public interface Figure extends test.nested.doc.Doc.Sec.Block { + + /** + * Creates a {@link test.nested.doc.Figure} instance. + */ + static test.nested.doc.Figure create() { + return new test.nested.doc.impl.Figure_Impl(); + } + + /** Identifier for the {@link test.nested.doc.Figure} type in JSON format. */ + String FIGURE__TYPE = "Figure"; + + /** @see #getSrc() */ + String SRC__PROP = "src"; + + /** Identifier for the {@link test.nested.doc.Figure} type in binary format. */ + static final int FIGURE__TYPE_ID = 3; + + /** Identifier for the property {@link #getSrc()} in binary format. */ + static final int SRC__ID = 4; + + String getSrc(); + + /** + * @see #getSrc() + */ + test.nested.doc.Figure setSrc(String value); + + @Override + test.nested.doc.Figure setWeight(int value); + + @Override + test.nested.doc.Figure setKind(test.nested.doc.Doc.Sec.Item.Kind value); + + @Override + test.nested.doc.Figure setPackage(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.doc.Figure readFigure(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.doc.impl.Figure_Impl result = new test.nested.doc.impl.Figure_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.doc.Figure readFigure(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.doc.Figure result = test.nested.doc.impl.Figure_Impl.readFigure_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Figure} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Figure readFigure(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.doc.impl.Figure_Impl.readFigure_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/doc.proto b/de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/doc.proto new file mode 100644 index 00000000..407ecab6 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/doc.proto @@ -0,0 +1,32 @@ +package test.nested.doc; + +/** + * A hierarchy nested two levels deep with an abstract intermediate, a nested enum, a reserved-word + * property and message name, and fields holding it as repeated, map and nullable values (issue #16). + */ +message Doc { + message Sec { + abstract message Item { + enum Kind { PLAIN; RICH; } + Kind kind; + string `package`; + } + abstract message Block extends Item { + int weight; + } + message Para extends Block { + string text; + } + message `Case` extends Block { + repeated Item children; + } + } + repeated Sec.Item items; + map byName; + @Nullable Sec.Item maybe; +} + +/** A top-level specialization of a nested abstract intermediate. */ +message Figure extends Doc.Sec.Block { + string src; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/impl/Doc_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/impl/Doc_Impl.java new file mode 100644 index 00000000..75a80d96 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/impl/Doc_Impl.java @@ -0,0 +1,1640 @@ +package test.nested.doc.impl; + +/** + * Implementation of {@link test.nested.doc.Doc}. + */ +public class Doc_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.doc.Doc { + /** + * Implementation of {@link test.nested.doc.Doc.Sec}. + */ + public static class Sec_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.doc.Doc.Sec { + /** + * Implementation of {@link test.nested.doc.Doc.Sec.Item}. + */ + public static abstract class Item_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.doc.Doc.Sec.Item { + + private test.nested.doc.Doc.Sec.Item.Kind _kind = test.nested.doc.Doc.Sec.Item.Kind.PLAIN; + + private String _package = ""; + + /** + * Creates a {@link Item_Impl} instance. + */ + public Item_Impl() { + super(); + } + + @Override + public final test.nested.doc.Doc.Sec.Item.Kind getKind() { + return _kind; + } + + @Override + public test.nested.doc.Doc.Sec.Item setKind(test.nested.doc.Doc.Sec.Item.Kind value) { + internalSetKind(value); + return this; + } + + /** Internal setter for {@link #getKind()} without chain call utility. */ + protected final void internalSetKind(test.nested.doc.Doc.Sec.Item.Kind value) { + if (value == null) throw new IllegalArgumentException("Property 'kind' cannot be null."); + _listener.beforeSet(this, KIND__PROP, value); + _kind = value; + _listener.afterChanged(this, KIND__PROP); + } + + @Override + public final String getPackage() { + return _package; + } + + @Override + public test.nested.doc.Doc.Sec.Item setPackage(String value) { + internalSetPackage(value); + return this; + } + + /** Internal setter for {@link #getPackage()} without chain call utility. */ + protected final void internalSetPackage(String value) { + _listener.beforeSet(this, PACKAGE__PROP, value); + _package = value; + _listener.afterChanged(this, PACKAGE__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.doc.Doc.Sec.Item registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.doc.Doc.Sec.Item unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + KIND__PROP, + PACKAGE__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case KIND__PROP: return getKind(); + case PACKAGE__PROP: return getPackage(); + default: return test.nested.doc.Doc.Sec.Item.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case KIND__PROP: internalSetKind((test.nested.doc.Doc.Sec.Item.Kind) value); break; + case PACKAGE__PROP: internalSetPackage((String) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.beginArray(); + out.value(jsonType()); + writeContent(out); + out.endArray(); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(KIND__PROP); + getKind().writeTo(out); + out.name(PACKAGE__PROP); + out.value(getPackage()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case KIND__PROP: setKind(test.nested.doc.Doc.Sec.Item.Kind.readKind(in)); break; + case PACKAGE__PROP: setPackage(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + out.name(0); + out.value(typeId()); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(KIND__ID); + getKind().writeTo(out); + out.name(PACKAGE__ID); + out.value(getPackage()); + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case KIND__ID: setKind(test.nested.doc.Doc.Sec.Item.Kind.readKind(in)); break; + case PACKAGE__ID: setPackage(in.nextString()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.doc.Doc.Sec.Item} type. */ + public static final String ITEM__XML_ELEMENT = "item"; + + /** XML attribute or element name of a {@link #getKind} property. */ + private static final String KIND__XML_ATTR = "kind"; + + /** XML attribute or element name of a {@link #getPackage} property. */ + private static final String PACKAGE__XML_ATTR = "package"; + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(KIND__XML_ATTR, getKind().protocolName()); + out.writeAttribute(PACKAGE__XML_ATTR, getPackage()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.nested.doc.Doc.Sec.Item} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Item_Impl readItem_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case test.nested.doc.impl.Doc_Impl.Sec_Impl.Para_Impl.PARA__XML_ELEMENT: { + return test.nested.doc.impl.Doc_Impl.Sec_Impl.Para_Impl.readPara_XmlContent(in); + } + + case test.nested.doc.impl.Doc_Impl.Sec_Impl.Case_Impl.CASE__XML_ELEMENT: { + return test.nested.doc.impl.Doc_Impl.Sec_Impl.Case_Impl.readCase_XmlContent(in); + } + + case Figure_Impl.FIGURE__XML_ELEMENT: { + return test.nested.doc.impl.Figure_Impl.readFigure_XmlContent(in); + } + + default: { + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case KIND__XML_ATTR: { + setKind(test.nested.doc.Doc.Sec.Item.Kind.valueOfProtocol(value)); + break; + } + case PACKAGE__XML_ATTR: { + setPackage(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case KIND__XML_ATTR: { + setKind(test.nested.doc.Doc.Sec.Item.Kind.valueOfProtocol(in.getElementText())); + break; + } + case PACKAGE__XML_ATTR: { + setPackage(in.getElementText()); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + } + /** + * Implementation of {@link test.nested.doc.Doc.Sec.Block}. + */ + public static abstract class Block_Impl extends test.nested.doc.impl.Doc_Impl.Sec_Impl.Item_Impl implements test.nested.doc.Doc.Sec.Block { + + private int _weight = 0; + + /** + * Creates a {@link Block_Impl} instance. + */ + public Block_Impl() { + super(); + } + + @Override + public final int getWeight() { + return _weight; + } + + @Override + public test.nested.doc.Doc.Sec.Block setWeight(int value) { + internalSetWeight(value); + return this; + } + + /** Internal setter for {@link #getWeight()} without chain call utility. */ + protected final void internalSetWeight(int value) { + _listener.beforeSet(this, WEIGHT__PROP, value); + _weight = value; + _listener.afterChanged(this, WEIGHT__PROP); + } + + @Override + public test.nested.doc.Doc.Sec.Block setKind(test.nested.doc.Doc.Sec.Item.Kind value) { + internalSetKind(value); + return this; + } + + @Override + public test.nested.doc.Doc.Sec.Block setPackage(String value) { + internalSetPackage(value); + return this; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + WEIGHT__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.doc.impl.Doc_Impl.Sec_Impl.Item_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.doc.impl.Doc_Impl.Sec_Impl.Item_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case WEIGHT__PROP: return getWeight(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case WEIGHT__PROP: internalSetWeight((int) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(WEIGHT__PROP); + out.value(getWeight()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case WEIGHT__PROP: setWeight(in.nextInt()); break; + default: super.readField(in, field); + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(WEIGHT__ID); + out.value(getWeight()); + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case WEIGHT__ID: setWeight(in.nextInt()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.doc.Doc.Sec.Block} type. */ + public static final String BLOCK__XML_ELEMENT = "block"; + + /** XML attribute or element name of a {@link #getWeight} property. */ + private static final String WEIGHT__XML_ATTR = "weight"; + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WEIGHT__XML_ATTR, Integer.toString(getWeight())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.doc.Doc.Sec.Block} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Block_Impl readBlock_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case test.nested.doc.impl.Doc_Impl.Sec_Impl.Para_Impl.PARA__XML_ELEMENT: { + return test.nested.doc.impl.Doc_Impl.Sec_Impl.Para_Impl.readPara_XmlContent(in); + } + + case test.nested.doc.impl.Doc_Impl.Sec_Impl.Case_Impl.CASE__XML_ELEMENT: { + return test.nested.doc.impl.Doc_Impl.Sec_Impl.Case_Impl.readCase_XmlContent(in); + } + + case Figure_Impl.FIGURE__XML_ELEMENT: { + return test.nested.doc.impl.Figure_Impl.readFigure_XmlContent(in); + } + + default: { + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case WEIGHT__XML_ATTR: { + setWeight(Integer.parseInt(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case WEIGHT__XML_ATTR: { + setWeight(Integer.parseInt(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public final R visit(test.nested.doc.Doc.Sec.Item.Visitor v, A arg) throws E { + return visit((test.nested.doc.Doc.Sec.Block.Visitor) v, arg); + } + + } + /** + * Implementation of {@link test.nested.doc.Doc.Sec.Para}. + */ + public static class Para_Impl extends test.nested.doc.impl.Doc_Impl.Sec_Impl.Block_Impl implements test.nested.doc.Doc.Sec.Para { + + private String _text = ""; + + /** + * Creates a {@link Para_Impl} instance. + * + * @see test.nested.doc.Doc.Sec.Para#create() + */ + public Para_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.PARA; + } + + @Override + public final String getText() { + return _text; + } + + @Override + public test.nested.doc.Doc.Sec.Para setText(String value) { + internalSetText(value); + return this; + } + + /** Internal setter for {@link #getText()} without chain call utility. */ + protected final void internalSetText(String value) { + _listener.beforeSet(this, TEXT__PROP, value); + _text = value; + _listener.afterChanged(this, TEXT__PROP); + } + + @Override + public test.nested.doc.Doc.Sec.Para setWeight(int value) { + internalSetWeight(value); + return this; + } + + @Override + public test.nested.doc.Doc.Sec.Para setKind(test.nested.doc.Doc.Sec.Item.Kind value) { + internalSetKind(value); + return this; + } + + @Override + public test.nested.doc.Doc.Sec.Para setPackage(String value) { + internalSetPackage(value); + return this; + } + + @Override + public String jsonType() { + return PARA__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + TEXT__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.doc.impl.Doc_Impl.Sec_Impl.Block_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.doc.impl.Doc_Impl.Sec_Impl.Block_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case TEXT__PROP: return getText(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case TEXT__PROP: internalSetText((String) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(TEXT__PROP); + out.value(getText()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case TEXT__PROP: setText(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + @Override + public int typeId() { + return PARA__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(TEXT__ID); + out.value(getText()); + } + + /** Helper for creating an object of type {@link test.nested.doc.Doc.Sec.Para} from a polymorphic composition. */ + public static test.nested.doc.Doc.Sec.Para readPara_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.doc.impl.Doc_Impl.Sec_Impl.Para_Impl result = new Para_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case TEXT__ID: setText(in.nextString()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.doc.Doc.Sec.Para} type. */ + public static final String PARA__XML_ELEMENT = "para"; + + /** XML attribute or element name of a {@link #getText} property. */ + private static final String TEXT__XML_ATTR = "text"; + + @Override + public String getXmlTagName() { + return PARA__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(TEXT__XML_ATTR, getText()); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.doc.Doc.Sec.Para} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Para_Impl readPara_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Para_Impl result = new Para_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case TEXT__XML_ATTR: { + setText(value); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case TEXT__XML_ATTR: { + setText(in.getElementText()); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.nested.doc.Doc.Sec.Block.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + + } + /** + * Implementation of {@link test.nested.doc.Doc.Sec.Case}. + */ + public static class Case_Impl extends test.nested.doc.impl.Doc_Impl.Sec_Impl.Block_Impl implements test.nested.doc.Doc.Sec.Case { + + private final java.util.List _children = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.nested.doc.Doc.Sec.Item element) { + _listener.beforeAdd(Case_Impl.this, CHILDREN__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.nested.doc.Doc.Sec.Item element) { + _listener.afterRemove(Case_Impl.this, CHILDREN__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Case_Impl.this, CHILDREN__PROP); + } + }; + + /** + * Creates a {@link Case_Impl} instance. + * + * @see test.nested.doc.Doc.Sec.Case#create() + */ + public Case_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.CASE; + } + + @Override + public final java.util.List getChildren() { + return _children; + } + + @Override + public test.nested.doc.Doc.Sec.Case setChildren(java.util.List value) { + internalSetChildren(value); + return this; + } + + /** Internal setter for {@link #getChildren()} without chain call utility. */ + protected final void internalSetChildren(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'children' cannot be null."); + _children.clear(); + _children.addAll(value); + } + + @Override + public test.nested.doc.Doc.Sec.Case addChildren(test.nested.doc.Doc.Sec.Item value) { + internalAddChildren(value); + return this; + } + + /** Implementation of {@link #addChildren(test.nested.doc.Doc.Sec.Item)} without chain call utility. */ + protected final void internalAddChildren(test.nested.doc.Doc.Sec.Item value) { + _children.add(value); + } + + @Override + public final void removeChildren(test.nested.doc.Doc.Sec.Item value) { + _children.remove(value); + } + + @Override + public test.nested.doc.Doc.Sec.Case setWeight(int value) { + internalSetWeight(value); + return this; + } + + @Override + public test.nested.doc.Doc.Sec.Case setKind(test.nested.doc.Doc.Sec.Item.Kind value) { + internalSetKind(value); + return this; + } + + @Override + public test.nested.doc.Doc.Sec.Case setPackage(String value) { + internalSetPackage(value); + return this; + } + + @Override + public String jsonType() { + return CASE__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + CHILDREN__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.doc.impl.Doc_Impl.Sec_Impl.Block_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.doc.impl.Doc_Impl.Sec_Impl.Block_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case CHILDREN__PROP: return getChildren(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case CHILDREN__PROP: internalSetChildren(de.haumacher.msgbuf.util.Conversions.asList(test.nested.doc.Doc.Sec.Item.class, value)); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(CHILDREN__PROP); + out.beginArray(); + for (test.nested.doc.Doc.Sec.Item x : getChildren()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case CHILDREN__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.nested.doc.Doc.Sec.Item.readItem(in)); + } + in.endArray(); + setChildren(newValue); + } + break; + default: super.readField(in, field); + } + } + + @Override + public int typeId() { + return CASE__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(CHILDREN__ID); + { + java.util.List values = getChildren(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.nested.doc.Doc.Sec.Item x : values) { + x.writeTo(out); + } + out.endArray(); + } + } + + /** Helper for creating an object of type {@link test.nested.doc.Doc.Sec.Case} from a polymorphic composition. */ + public static test.nested.doc.Doc.Sec.Case readCase_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.doc.impl.Doc_Impl.Sec_Impl.Case_Impl result = new Case_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case CHILDREN__ID: { + in.beginArray(); + while (in.hasNext()) { + addChildren(test.nested.doc.Doc.Sec.Item.readItem(in)); + } + in.endArray(); + } + break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.doc.Doc.Sec.Case} type. */ + public static final String CASE__XML_ELEMENT = "case"; + + /** XML attribute or element name of a {@link #getChildren} property. */ + private static final String CHILDREN__XML_ATTR = "children"; + + @Override + public String getXmlTagName() { + return CASE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + out.writeStartElement(CHILDREN__XML_ATTR); + for (test.nested.doc.Doc.Sec.Item element : getChildren()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.nested.doc.Doc.Sec.Case} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Case_Impl readCase_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Case_Impl result = new Case_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case CHILDREN__XML_ATTR: { + internalReadChildrenListXml(in); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + private void internalReadChildrenListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addChildren(test.nested.doc.impl.Doc_Impl.Sec_Impl.Item_Impl.readItem_XmlContent(in)); + } + } + + @Override + public R visit(test.nested.doc.Doc.Sec.Block.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + + } + + /** + * Creates a {@link Sec_Impl} instance. + * + * @see test.nested.doc.Doc.Sec#create() + */ + public Sec_Impl() { + super(); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.doc.Doc.Sec registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.doc.Doc.Sec unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return SEC__TYPE; + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + // No fields to write, hook for subclasses. + } + + /** Helper for creating an object of type {@link test.nested.doc.Doc.Sec} from a polymorphic composition. */ + public static test.nested.doc.Doc.Sec readSec_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.doc.impl.Doc_Impl.Sec_Impl result = new Sec_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.doc.Doc.Sec} type. */ + public static final String SEC__XML_ELEMENT = "sec"; + + @Override + public String getXmlTagName() { + return SEC__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.nested.doc.Doc.Sec} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Sec_Impl readSec_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Sec_Impl result = new Sec_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + } + + private final java.util.List _items = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.nested.doc.Doc.Sec.Item element) { + _listener.beforeAdd(Doc_Impl.this, ITEMS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.nested.doc.Doc.Sec.Item element) { + _listener.afterRemove(Doc_Impl.this, ITEMS__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Doc_Impl.this, ITEMS__PROP); + } + }; + + private final java.util.Map _byName = new de.haumacher.msgbuf.util.ReferenceMap() { + @Override + protected void beforeAdd(String index, test.nested.doc.Doc.Sec.Item element) { + _listener.beforeAdd(Doc_Impl.this, BY_NAME__PROP, index, element); + } + + @Override + protected void afterRemove(String index, test.nested.doc.Doc.Sec.Item element) { + _listener.afterRemove(Doc_Impl.this, BY_NAME__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Doc_Impl.this, BY_NAME__PROP); + } + }; + + private test.nested.doc.Doc.Sec.Item _maybe = null; + + /** + * Creates a {@link Doc_Impl} instance. + * + * @see test.nested.doc.Doc#create() + */ + public Doc_Impl() { + super(); + } + + @Override + public final java.util.List getItems() { + return _items; + } + + @Override + public test.nested.doc.Doc setItems(java.util.List value) { + internalSetItems(value); + return this; + } + + /** Internal setter for {@link #getItems()} without chain call utility. */ + protected final void internalSetItems(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'items' cannot be null."); + _items.clear(); + _items.addAll(value); + } + + @Override + public test.nested.doc.Doc addItem(test.nested.doc.Doc.Sec.Item value) { + internalAddItem(value); + return this; + } + + /** Implementation of {@link #addItem(test.nested.doc.Doc.Sec.Item)} without chain call utility. */ + protected final void internalAddItem(test.nested.doc.Doc.Sec.Item value) { + _items.add(value); + } + + @Override + public final void removeItem(test.nested.doc.Doc.Sec.Item value) { + _items.remove(value); + } + + @Override + public final java.util.Map getByName() { + return _byName; + } + + @Override + public test.nested.doc.Doc setByName(java.util.Map value) { + internalSetByName(value); + return this; + } + + /** Internal setter for {@link #getByName()} without chain call utility. */ + protected final void internalSetByName(java.util.Map value) { + if (value == null) throw new IllegalArgumentException("Property 'byName' cannot be null."); + _byName.clear(); + _byName.putAll(value); + } + + @Override + public test.nested.doc.Doc putByName(String key, test.nested.doc.Doc.Sec.Item value) { + internalPutByName(key, value); + return this; + } + + /** Implementation of {@link #putByName(String, test.nested.doc.Doc.Sec.Item)} without chain call utility. */ + protected final void internalPutByName(String key, test.nested.doc.Doc.Sec.Item value) { + if (_byName.containsKey(key)) { + throw new IllegalArgumentException("Property 'byName' already contains a value for key '" + key + "'."); + } + _byName.put(key, value); + } + + @Override + public final void removeByName(String key) { + _byName.remove(key); + } + + @Override + public final test.nested.doc.Doc.Sec.Item getMaybe() { + return _maybe; + } + + @Override + public test.nested.doc.Doc setMaybe(test.nested.doc.Doc.Sec.Item value) { + internalSetMaybe(value); + return this; + } + + /** Internal setter for {@link #getMaybe()} without chain call utility. */ + protected final void internalSetMaybe(test.nested.doc.Doc.Sec.Item value) { + _listener.beforeSet(this, MAYBE__PROP, value); + _maybe = value; + _listener.afterChanged(this, MAYBE__PROP); + } + + @Override + public final boolean hasMaybe() { + return _maybe != null; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.doc.Doc registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.doc.Doc unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return DOC__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + ITEMS__PROP, + BY_NAME__PROP, + MAYBE__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case ITEMS__PROP: return getItems(); + case BY_NAME__PROP: return getByName(); + case MAYBE__PROP: return getMaybe(); + default: return test.nested.doc.Doc.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case ITEMS__PROP: internalSetItems(de.haumacher.msgbuf.util.Conversions.asList(test.nested.doc.Doc.Sec.Item.class, value)); break; + case BY_NAME__PROP: internalSetByName((java.util.Map) value); break; + case MAYBE__PROP: internalSetMaybe((test.nested.doc.Doc.Sec.Item) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(ITEMS__PROP); + out.beginArray(); + for (test.nested.doc.Doc.Sec.Item x : getItems()) { + x.writeTo(out); + } + out.endArray(); + out.name(BY_NAME__PROP); + out.beginObject(); + for (java.util.Map.Entry entry : getByName().entrySet()) { + out.name(entry.getKey()); + entry.getValue().writeTo(out); + } + out.endObject(); + if (hasMaybe()) { + out.name(MAYBE__PROP); + getMaybe().writeTo(out); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case ITEMS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.nested.doc.Doc.Sec.Item.readItem(in)); + } + in.endArray(); + setItems(newValue); + } + break; + case BY_NAME__PROP: { + java.util.Map newValue = new java.util.LinkedHashMap<>(); + in.beginObject(); + while (in.hasNext()) { + newValue.put(in.nextName(), test.nested.doc.Doc.Sec.Item.readItem(in)); + } + in.endObject(); + setByName(newValue); + break; + } + case MAYBE__PROP: setMaybe(test.nested.doc.Doc.Sec.Item.readItem(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(ITEMS__ID); + { + java.util.List values = getItems(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.nested.doc.Doc.Sec.Item x : values) { + x.writeTo(out); + } + out.endArray(); + } + out.name(BY_NAME__ID); + { + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, getByName().size()); + for (java.util.Map.Entry entry : getByName().entrySet()) { + out.beginObject(); + out.name(1); + out.value(entry.getKey()); + out.name(2); + entry.getValue().writeTo(out); + out.endObject(); + } + out.endArray(); + } + if (hasMaybe()) { + out.name(MAYBE__ID); + getMaybe().writeTo(out); + } + } + + /** Helper for creating an object of type {@link test.nested.doc.Doc} from a polymorphic composition. */ + public static test.nested.doc.Doc readDoc_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.doc.impl.Doc_Impl result = new Doc_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case ITEMS__ID: { + in.beginArray(); + while (in.hasNext()) { + addItem(test.nested.doc.Doc.Sec.Item.readItem(in)); + } + in.endArray(); + } + break; + case BY_NAME__ID: { + in.beginArray(); + while (in.hasNext()) { + in.beginObject(); + String key = ""; + test.nested.doc.Doc.Sec.Item value = null; + while (in.hasNext()) { + switch (in.nextName()) { + case 1: key = in.nextString(); break; + case 2: value = test.nested.doc.Doc.Sec.Item.readItem(in); break; + default: in.skipValue(); break; + } + } + putByName(key, value); + in.endObject(); + } + in.endArray(); + break; + } + case MAYBE__ID: setMaybe(test.nested.doc.Doc.Sec.Item.readItem(in)); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.doc.Doc} type. */ + public static final String DOC__XML_ELEMENT = "doc"; + + /** XML attribute or element name of a {@link #getItems} property. */ + private static final String ITEMS__XML_ATTR = "items"; + + /** XML attribute or element name of a {@link #getByName} property. */ + private static final String BY_NAME__XML_ATTR = "by-name"; + + /** XML attribute or element name of a {@link #getMaybe} property. */ + private static final String MAYBE__XML_ATTR = "maybe"; + + @Override + public String getXmlTagName() { + return DOC__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeStartElement(ITEMS__XML_ATTR); + for (test.nested.doc.Doc.Sec.Item element : getItems()) { + element.writeTo(out); + } + out.writeEndElement(); + if (hasMaybe()) { + out.writeStartElement(MAYBE__XML_ATTR); + getMaybe().writeTo(out); + out.writeEndElement(); + } + } + + /** Creates a new {@link test.nested.doc.Doc} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Doc_Impl readDoc_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Doc_Impl result = new Doc_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case ITEMS__XML_ATTR: { + internalReadItemsListXml(in); + break; + } + case MAYBE__XML_ATTR: { + in.nextTag(); + setMaybe(test.nested.doc.impl.Doc_Impl.Sec_Impl.Item_Impl.readItem_XmlContent(in)); + internalSkipUntilMatchingEndElement(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadItemsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addItem(test.nested.doc.impl.Doc_Impl.Sec_Impl.Item_Impl.readItem_XmlContent(in)); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/impl/Figure_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/impl/Figure_Impl.java new file mode 100644 index 00000000..b790f83e --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/doc/impl/Figure_Impl.java @@ -0,0 +1,217 @@ +package test.nested.doc.impl; + +/** + * Implementation of {@link test.nested.doc.Figure}. + */ +public class Figure_Impl extends test.nested.doc.impl.Doc_Impl.Sec_Impl.Block_Impl implements test.nested.doc.Figure { + + private String _src = ""; + + /** + * Creates a {@link Figure_Impl} instance. + * + * @see test.nested.doc.Figure#create() + */ + public Figure_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.FIGURE; + } + + @Override + public final String getSrc() { + return _src; + } + + @Override + public test.nested.doc.Figure setSrc(String value) { + internalSetSrc(value); + return this; + } + + /** Internal setter for {@link #getSrc()} without chain call utility. */ + protected final void internalSetSrc(String value) { + _listener.beforeSet(this, SRC__PROP, value); + _src = value; + _listener.afterChanged(this, SRC__PROP); + } + + @Override + public test.nested.doc.Figure setWeight(int value) { + internalSetWeight(value); + return this; + } + + @Override + public test.nested.doc.Figure setKind(test.nested.doc.Doc.Sec.Item.Kind value) { + internalSetKind(value); + return this; + } + + @Override + public test.nested.doc.Figure setPackage(String value) { + internalSetPackage(value); + return this; + } + + @Override + public String jsonType() { + return FIGURE__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + SRC__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.doc.impl.Doc_Impl.Sec_Impl.Block_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.doc.impl.Doc_Impl.Sec_Impl.Block_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case SRC__PROP: return getSrc(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case SRC__PROP: internalSetSrc((String) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(SRC__PROP); + out.value(getSrc()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case SRC__PROP: setSrc(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + @Override + public int typeId() { + return FIGURE__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(SRC__ID); + out.value(getSrc()); + } + + /** Helper for creating an object of type {@link test.nested.doc.Figure} from a polymorphic composition. */ + public static test.nested.doc.Figure readFigure_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.doc.impl.Figure_Impl result = new Figure_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case SRC__ID: setSrc(in.nextString()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.doc.Figure} type. */ + public static final String FIGURE__XML_ELEMENT = "figure"; + + /** XML attribute or element name of a {@link #getSrc} property. */ + private static final String SRC__XML_ATTR = "src"; + + @Override + public String getXmlTagName() { + return FIGURE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(SRC__XML_ATTR, getSrc()); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.doc.Figure} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Figure_Impl readFigure_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Figure_Impl result = new Figure_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case SRC__XML_ATTR: { + setSrc(value); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case SRC__XML_ATTR: { + setSrc(in.getElementText()); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.nested.doc.Doc.Sec.Block.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/note/Note.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/note/Note.java new file mode 100644 index 00000000..45619068 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/note/Note.java @@ -0,0 +1,144 @@ +package test.nested.note; + +/** + * References to a nested polymorphic hierarchy of another file (issue #16). + */ +public interface Note extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + public interface Inner extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.nested.note.Note.Inner} instance. + */ + static test.nested.note.Note.Inner create() { + return new test.nested.note.impl.Note_Impl.Inner_Impl(); + } + + /** Identifier for the {@link test.nested.note.Note.Inner} type in JSON format. */ + String INNER__TYPE = "Inner"; + + /** @see #getRefs() */ + String REFS__PROP = "refs"; + + /** Identifier for the property {@link #getRefs()} in binary format. */ + static final int REFS__ID = 1; + + java.util.List getRefs(); + + /** + * @see #getRefs() + */ + test.nested.note.Note.Inner setRefs(java.util.List value); + + /** + * Adds a value to the {@link #getRefs()} list. + */ + test.nested.note.Note.Inner addRef(test.nested.doc.Doc.Sec.Item value); + + /** + * Removes a value from the {@link #getRefs()} list. + */ + void removeRef(test.nested.doc.Doc.Sec.Item value); + + @Override + public test.nested.note.Note.Inner registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.note.Note.Inner unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.note.Note.Inner readInner(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.note.impl.Note_Impl.Inner_Impl result = new test.nested.note.impl.Note_Impl.Inner_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.note.Note.Inner readInner(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.note.Note.Inner result = test.nested.note.impl.Note_Impl.Inner_Impl.readInner_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Inner} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Inner readInner(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.note.impl.Note_Impl.Inner_Impl.readInner_XmlContent(in); + } + + } + + /** + * Creates a {@link test.nested.note.Note} instance. + */ + static test.nested.note.Note create() { + return new test.nested.note.impl.Note_Impl(); + } + + /** Identifier for the {@link test.nested.note.Note} type in JSON format. */ + String NOTE__TYPE = "Note"; + + /** @see #getTarget() */ + String TARGET__PROP = "target"; + + /** @see #getInner() */ + String INNER__PROP = "inner"; + + /** Identifier for the property {@link #getTarget()} in binary format. */ + static final int TARGET__ID = 1; + + /** Identifier for the property {@link #getInner()} in binary format. */ + static final int INNER__ID = 2; + + test.nested.doc.Doc.Sec.Item getTarget(); + + /** + * @see #getTarget() + */ + test.nested.note.Note setTarget(test.nested.doc.Doc.Sec.Item value); + + /** + * Checks, whether {@link #getTarget()} has a value. + */ + boolean hasTarget(); + + test.nested.note.Note.Inner getInner(); + + /** + * @see #getInner() + */ + test.nested.note.Note setInner(test.nested.note.Note.Inner value); + + /** + * Checks, whether {@link #getInner()} has a value. + */ + boolean hasInner(); + + @Override + public test.nested.note.Note registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.note.Note unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.note.Note readNote(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.note.impl.Note_Impl result = new test.nested.note.impl.Note_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.note.Note readNote(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.note.Note result = test.nested.note.impl.Note_Impl.readNote_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Note} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Note readNote(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.note.impl.Note_Impl.readNote_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/note/impl/Note_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/note/impl/Note_Impl.java new file mode 100644 index 00000000..5a63ebbe --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/note/impl/Note_Impl.java @@ -0,0 +1,638 @@ +package test.nested.note.impl; + +/** + * Implementation of {@link test.nested.note.Note}. + */ +public class Note_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.note.Note { + /** + * Implementation of {@link test.nested.note.Note.Inner}. + */ + public static class Inner_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.note.Note.Inner { + + private final java.util.List _refs = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.nested.doc.Doc.Sec.Item element) { + _listener.beforeAdd(Inner_Impl.this, REFS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.nested.doc.Doc.Sec.Item element) { + _listener.afterRemove(Inner_Impl.this, REFS__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Inner_Impl.this, REFS__PROP); + } + }; + + /** + * Creates a {@link Inner_Impl} instance. + * + * @see test.nested.note.Note.Inner#create() + */ + public Inner_Impl() { + super(); + } + + @Override + public final java.util.List getRefs() { + return _refs; + } + + @Override + public test.nested.note.Note.Inner setRefs(java.util.List value) { + internalSetRefs(value); + return this; + } + + /** Internal setter for {@link #getRefs()} without chain call utility. */ + protected final void internalSetRefs(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'refs' cannot be null."); + _refs.clear(); + _refs.addAll(value); + } + + @Override + public test.nested.note.Note.Inner addRef(test.nested.doc.Doc.Sec.Item value) { + internalAddRef(value); + return this; + } + + /** Implementation of {@link #addRef(test.nested.doc.Doc.Sec.Item)} without chain call utility. */ + protected final void internalAddRef(test.nested.doc.Doc.Sec.Item value) { + _refs.add(value); + } + + @Override + public final void removeRef(test.nested.doc.Doc.Sec.Item value) { + _refs.remove(value); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.note.Note.Inner registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.note.Note.Inner unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return INNER__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + REFS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case REFS__PROP: return getRefs(); + default: return test.nested.note.Note.Inner.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case REFS__PROP: internalSetRefs(de.haumacher.msgbuf.util.Conversions.asList(test.nested.doc.Doc.Sec.Item.class, value)); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(REFS__PROP); + out.beginArray(); + for (test.nested.doc.Doc.Sec.Item x : getRefs()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case REFS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.nested.doc.Doc.Sec.Item.readItem(in)); + } + in.endArray(); + setRefs(newValue); + } + break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(REFS__ID); + { + java.util.List values = getRefs(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.nested.doc.Doc.Sec.Item x : values) { + x.writeTo(out); + } + out.endArray(); + } + } + + /** Helper for creating an object of type {@link test.nested.note.Note.Inner} from a polymorphic composition. */ + public static test.nested.note.Note.Inner readInner_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.note.impl.Note_Impl.Inner_Impl result = new Inner_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case REFS__ID: { + in.beginArray(); + while (in.hasNext()) { + addRef(test.nested.doc.Doc.Sec.Item.readItem(in)); + } + in.endArray(); + } + break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.note.Note.Inner} type. */ + public static final String INNER__XML_ELEMENT = "inner"; + + /** XML attribute or element name of a {@link #getRefs} property. */ + private static final String REFS__XML_ATTR = "refs"; + + @Override + public String getXmlTagName() { + return INNER__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeStartElement(REFS__XML_ATTR); + for (test.nested.doc.Doc.Sec.Item element : getRefs()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.nested.note.Note.Inner} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Inner_Impl readInner_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Inner_Impl result = new Inner_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case REFS__XML_ATTR: { + internalReadRefsListXml(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadRefsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addRef(test.nested.doc.impl.Doc_Impl.Sec_Impl.Item_Impl.readItem_XmlContent(in)); + } + } + + } + + private test.nested.doc.Doc.Sec.Item _target = null; + + private test.nested.note.Note.Inner _inner = null; + + /** + * Creates a {@link Note_Impl} instance. + * + * @see test.nested.note.Note#create() + */ + public Note_Impl() { + super(); + } + + @Override + public final test.nested.doc.Doc.Sec.Item getTarget() { + return _target; + } + + @Override + public test.nested.note.Note setTarget(test.nested.doc.Doc.Sec.Item value) { + internalSetTarget(value); + return this; + } + + /** Internal setter for {@link #getTarget()} without chain call utility. */ + protected final void internalSetTarget(test.nested.doc.Doc.Sec.Item value) { + _listener.beforeSet(this, TARGET__PROP, value); + _target = value; + _listener.afterChanged(this, TARGET__PROP); + } + + @Override + public final boolean hasTarget() { + return _target != null; + } + + @Override + public final test.nested.note.Note.Inner getInner() { + return _inner; + } + + @Override + public test.nested.note.Note setInner(test.nested.note.Note.Inner value) { + internalSetInner(value); + return this; + } + + /** Internal setter for {@link #getInner()} without chain call utility. */ + protected final void internalSetInner(test.nested.note.Note.Inner value) { + _listener.beforeSet(this, INNER__PROP, value); + _inner = value; + _listener.afterChanged(this, INNER__PROP); + } + + @Override + public final boolean hasInner() { + return _inner != null; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.note.Note registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.note.Note unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return NOTE__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + TARGET__PROP, + INNER__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case TARGET__PROP: return getTarget(); + case INNER__PROP: return getInner(); + default: return test.nested.note.Note.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case TARGET__PROP: internalSetTarget((test.nested.doc.Doc.Sec.Item) value); break; + case INNER__PROP: internalSetInner((test.nested.note.Note.Inner) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + if (hasTarget()) { + out.name(TARGET__PROP); + getTarget().writeTo(out); + } + if (hasInner()) { + out.name(INNER__PROP); + getInner().writeTo(out); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case TARGET__PROP: setTarget(test.nested.doc.Doc.Sec.Item.readItem(in)); break; + case INNER__PROP: setInner(test.nested.note.Note.Inner.readInner(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + if (hasTarget()) { + out.name(TARGET__ID); + getTarget().writeTo(out); + } + if (hasInner()) { + out.name(INNER__ID); + getInner().writeTo(out); + } + } + + /** Helper for creating an object of type {@link test.nested.note.Note} from a polymorphic composition. */ + public static test.nested.note.Note readNote_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.note.impl.Note_Impl result = new Note_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case TARGET__ID: setTarget(test.nested.doc.Doc.Sec.Item.readItem(in)); break; + case INNER__ID: setInner(test.nested.note.Note.Inner.readInner(in)); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.note.Note} type. */ + public static final String NOTE__XML_ELEMENT = "note"; + + /** XML attribute or element name of a {@link #getTarget} property. */ + private static final String TARGET__XML_ATTR = "target"; + + /** XML attribute or element name of a {@link #getInner} property. */ + private static final String INNER__XML_ATTR = "inner"; + + @Override + public String getXmlTagName() { + return NOTE__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasTarget()) { + out.writeStartElement(TARGET__XML_ATTR); + getTarget().writeTo(out); + out.writeEndElement(); + } + if (hasInner()) { + out.writeStartElement(INNER__XML_ATTR); + getInner().writeContent(out); + out.writeEndElement(); + } + } + + /** Creates a new {@link test.nested.note.Note} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Note_Impl readNote_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Note_Impl result = new Note_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case TARGET__XML_ATTR: { + in.nextTag(); + setTarget(test.nested.doc.impl.Doc_Impl.Sec_Impl.Item_Impl.readItem_XmlContent(in)); + internalSkipUntilMatchingEndElement(in); + break; + } + case INNER__XML_ATTR: { + setInner(test.nested.note.impl.Note_Impl.Inner_Impl.readInner_XmlContent(in)); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/note/note.proto b/de.haumacher.msgbuf.generator/src/test/java/test/nested/note/note.proto new file mode 100644 index 00000000..c576a8e4 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/note/note.proto @@ -0,0 +1,13 @@ +package test.nested.note; +import "../doc/doc.proto"; + +/** + * References to a nested polymorphic hierarchy of another file (issue #16). + */ +message Note { + message Inner { + repeated test.nested.doc.Doc.Sec.Item refs; + } + test.nested.doc.Doc.Sec.Item target; + Inner inner; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/Events.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/Events.java new file mode 100644 index 00000000..84f9f31d --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/Events.java @@ -0,0 +1,182 @@ +package test.nested.owbase; + +/** + * An OpenWorld hierarchy with a nested abstract root (issue #16). + */ +public interface Events extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + /** + * Nested abstract root, extended from another file. + */ + public interface Event extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** Type codes for the {@link test.nested.owbase.Events.Event} hierarchy. */ + public enum TypeKind { + + /** Type literal for {@link test.nested.owbase.Events.TextEvent}. */ + TEXT_EVENT, + ; + + } + + /** Registry for dynamically registered subtypes. */ + static final java.util.Map> REGISTRY = new java.util.HashMap<>(); + + /** + * Registers a subtype factory for polymorphic deserialization. + */ + static void register(String typeId, de.haumacher.msgbuf.data.Factory factory) { + REGISTRY.put(typeId, factory); + } + + /** Visitor interface for the {@link test.nested.owbase.Events.Event} hierarchy.*/ + public interface Visitor { + + /** Visit case for {@link test.nested.owbase.Events.TextEvent}.*/ + R visit(test.nested.owbase.Events.TextEvent self, A arg) throws E; + + /** Fallback for visiting subtypes not known at compile time. */ + R visitDefault(test.nested.owbase.Events.Event self, A arg) throws E; + + } + + /** @see #getTimestamp() */ + String TIMESTAMP__PROP = "timestamp"; + + /** The type code of this instance. */ + TypeKind kind(); + + long getTimestamp(); + + /** + * @see #getTimestamp() + */ + test.nested.owbase.Events.Event setTimestamp(long value); + + @Override + public test.nested.owbase.Events.Event registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.owbase.Events.Event unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.owbase.Events.Event readEvent(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.owbase.Events.Event result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case test.nested.owbase.Events.TextEvent.TEXT_EVENT__TYPE: result = test.nested.owbase.Events.TextEvent.readTextEvent(in); break; + default: { + de.haumacher.msgbuf.data.Factory factory = test.nested.owbase.Events.Event.REGISTRY.get(type); + if (factory != null) { + result = factory.create(); + result.readContent(in); + } else { + in.skipValue(); + result = null; + } + } break; + } + in.endArray(); + return result; + } + + /** Creates a new {@link Event} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Event readEvent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.owbase.impl.Events_Impl.Event_Impl.readEvent_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + + } + public interface TextEvent extends test.nested.owbase.Events.Event { + + /** + * Creates a {@link test.nested.owbase.Events.TextEvent} instance. + */ + static test.nested.owbase.Events.TextEvent create() { + return new test.nested.owbase.impl.Events_Impl.TextEvent_Impl(); + } + + /** Identifier for the {@link test.nested.owbase.Events.TextEvent} type in JSON format. */ + String TEXT_EVENT__TYPE = "TextEvent"; + + /** @see #getText() */ + String TEXT__PROP = "text"; + + String getText(); + + /** + * @see #getText() + */ + test.nested.owbase.Events.TextEvent setText(String value); + + @Override + test.nested.owbase.Events.TextEvent setTimestamp(long value); + + /** Reads a new instance from the given reader. */ + static test.nested.owbase.Events.TextEvent readTextEvent(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.owbase.impl.Events_Impl.TextEvent_Impl result = new test.nested.owbase.impl.Events_Impl.TextEvent_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link TextEvent} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static TextEvent readTextEvent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.owbase.impl.Events_Impl.TextEvent_Impl.readTextEvent_XmlContent(in); + } + + } + + /** + * Creates a {@link test.nested.owbase.Events} instance. + */ + static test.nested.owbase.Events create() { + return new test.nested.owbase.impl.Events_Impl(); + } + + /** Identifier for the {@link test.nested.owbase.Events} type in JSON format. */ + String EVENTS__TYPE = "Events"; + + /** @see #getEvents() */ + String EVENTS__PROP = "events"; + + java.util.List getEvents(); + + /** + * @see #getEvents() + */ + test.nested.owbase.Events setEvents(java.util.List value); + + /** + * Adds a value to the {@link #getEvents()} list. + */ + test.nested.owbase.Events addEvent(test.nested.owbase.Events.Event value); + + /** + * Removes a value from the {@link #getEvents()} list. + */ + void removeEvent(test.nested.owbase.Events.Event value); + + @Override + public test.nested.owbase.Events registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.owbase.Events unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.owbase.Events readEvents(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.owbase.impl.Events_Impl result = new test.nested.owbase.impl.Events_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Events} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Events readEvents(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.owbase.impl.Events_Impl.readEvents_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/impl/Events_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/impl/Events_Impl.java new file mode 100644 index 00000000..547e6ed4 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/impl/Events_Impl.java @@ -0,0 +1,658 @@ +package test.nested.owbase.impl; + +/** + * Implementation of {@link test.nested.owbase.Events}. + */ +public class Events_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.owbase.Events { + /** + * Implementation of {@link test.nested.owbase.Events.Event}. + */ + public static abstract class Event_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.owbase.Events.Event { + + static { + de.haumacher.msgbuf.data.TypeRegistryLoader.ensureLoaded(); + } + + private long _timestamp = 0L; + + /** + * Creates a {@link Event_Impl} instance. + */ + public Event_Impl() { + super(); + } + + @Override + public final long getTimestamp() { + return _timestamp; + } + + @Override + public test.nested.owbase.Events.Event setTimestamp(long value) { + internalSetTimestamp(value); + return this; + } + + /** Internal setter for {@link #getTimestamp()} without chain call utility. */ + protected final void internalSetTimestamp(long value) { + _listener.beforeSet(this, TIMESTAMP__PROP, value); + _timestamp = value; + _listener.afterChanged(this, TIMESTAMP__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.owbase.Events.Event registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.owbase.Events.Event unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + TIMESTAMP__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case TIMESTAMP__PROP: return getTimestamp(); + default: return test.nested.owbase.Events.Event.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case TIMESTAMP__PROP: internalSetTimestamp((long) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.beginArray(); + out.value(jsonType()); + writeContent(out); + out.endArray(); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(TIMESTAMP__PROP); + out.value(getTimestamp()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case TIMESTAMP__PROP: setTimestamp(in.nextLong()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.owbase.Events.Event} type. */ + public static final String EVENT__XML_ELEMENT = "event"; + + /** XML attribute or element name of a {@link #getTimestamp} property. */ + private static final String TIMESTAMP__XML_ATTR = "timestamp"; + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(TIMESTAMP__XML_ATTR, Long.toString(getTimestamp())); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.nested.owbase.Events.Event} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Event_Impl readEvent_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case test.nested.owbase.impl.Events_Impl.TextEvent_Impl.TEXT_EVENT__XML_ELEMENT: { + return test.nested.owbase.impl.Events_Impl.TextEvent_Impl.readTextEvent_XmlContent(in); + } + + default: { + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case TIMESTAMP__XML_ATTR: { + setTimestamp(Long.parseLong(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case TIMESTAMP__XML_ATTR: { + setTimestamp(Long.parseLong(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + } + /** + * Implementation of {@link test.nested.owbase.Events.TextEvent}. + */ + public static class TextEvent_Impl extends test.nested.owbase.impl.Events_Impl.Event_Impl implements test.nested.owbase.Events.TextEvent { + + private String _text = ""; + + /** + * Creates a {@link TextEvent_Impl} instance. + * + * @see test.nested.owbase.Events.TextEvent#create() + */ + public TextEvent_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.TEXT_EVENT; + } + + @Override + public final String getText() { + return _text; + } + + @Override + public test.nested.owbase.Events.TextEvent setText(String value) { + internalSetText(value); + return this; + } + + /** Internal setter for {@link #getText()} without chain call utility. */ + protected final void internalSetText(String value) { + _listener.beforeSet(this, TEXT__PROP, value); + _text = value; + _listener.afterChanged(this, TEXT__PROP); + } + + @Override + public test.nested.owbase.Events.TextEvent setTimestamp(long value) { + internalSetTimestamp(value); + return this; + } + + @Override + public String jsonType() { + return TEXT_EVENT__TYPE; + } + + @SuppressWarnings("hiding") + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + TEXT__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.owbase.impl.Events_Impl.Event_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.owbase.impl.Events_Impl.Event_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case TEXT__PROP: return getText(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case TEXT__PROP: internalSetText((String) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(TEXT__PROP); + out.value(getText()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case TEXT__PROP: setText(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.owbase.Events.TextEvent} type. */ + public static final String TEXT_EVENT__XML_ELEMENT = "text-event"; + + /** XML attribute or element name of a {@link #getText} property. */ + private static final String TEXT__XML_ATTR = "text"; + + @Override + public String getXmlTagName() { + return TEXT_EVENT__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(TEXT__XML_ATTR, getText()); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.owbase.Events.TextEvent} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static TextEvent_Impl readTextEvent_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + TextEvent_Impl result = new TextEvent_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case TEXT__XML_ATTR: { + setText(value); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case TEXT__XML_ATTR: { + setText(in.getElementText()); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.nested.owbase.Events.Event.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + + } + + private final java.util.List _events = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.nested.owbase.Events.Event element) { + _listener.beforeAdd(Events_Impl.this, EVENTS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.nested.owbase.Events.Event element) { + _listener.afterRemove(Events_Impl.this, EVENTS__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Events_Impl.this, EVENTS__PROP); + } + }; + + /** + * Creates a {@link Events_Impl} instance. + * + * @see test.nested.owbase.Events#create() + */ + public Events_Impl() { + super(); + } + + @Override + public final java.util.List getEvents() { + return _events; + } + + @Override + public test.nested.owbase.Events setEvents(java.util.List value) { + internalSetEvents(value); + return this; + } + + /** Internal setter for {@link #getEvents()} without chain call utility. */ + protected final void internalSetEvents(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'events' cannot be null."); + _events.clear(); + _events.addAll(value); + } + + @Override + public test.nested.owbase.Events addEvent(test.nested.owbase.Events.Event value) { + internalAddEvent(value); + return this; + } + + /** Implementation of {@link #addEvent(test.nested.owbase.Events.Event)} without chain call utility. */ + protected final void internalAddEvent(test.nested.owbase.Events.Event value) { + _events.add(value); + } + + @Override + public final void removeEvent(test.nested.owbase.Events.Event value) { + _events.remove(value); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.owbase.Events registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.owbase.Events unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return EVENTS__TYPE; + } + + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + EVENTS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case EVENTS__PROP: return getEvents(); + default: return test.nested.owbase.Events.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case EVENTS__PROP: internalSetEvents(de.haumacher.msgbuf.util.Conversions.asList(test.nested.owbase.Events.Event.class, value)); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(EVENTS__PROP); + out.beginArray(); + for (test.nested.owbase.Events.Event x : getEvents()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case EVENTS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.nested.owbase.Events.Event.readEvent(in)); + } + in.endArray(); + setEvents(newValue); + } + break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.owbase.Events} type. */ + public static final String EVENTS__XML_ELEMENT = "events"; + + /** XML attribute or element name of a {@link #getEvents} property. */ + private static final String EVENTS__XML_ATTR = "events"; + + @Override + public String getXmlTagName() { + return EVENTS__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeStartElement(EVENTS__XML_ATTR); + for (test.nested.owbase.Events.Event element : getEvents()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.nested.owbase.Events} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Events_Impl readEvents_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Events_Impl result = new Events_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case EVENTS__XML_ATTR: { + internalReadEventsListXml(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadEventsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addEvent(test.nested.owbase.impl.Events_Impl.Event_Impl.readEvent_XmlContent(in)); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/owbase.proto b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/owbase.proto new file mode 100644 index 00000000..369a7ddd --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/owbase.proto @@ -0,0 +1,19 @@ +package test.nested.owbase; + +option OpenWorld; + +/** + * An OpenWorld hierarchy with a nested abstract root (issue #16). + */ +message Events { + /** Nested abstract root, extended from another file. */ + abstract message Event { + long timestamp; + } + + message TextEvent extends Event { + string text; + } + + repeated Event events; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/CountEvent.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/CountEvent.java new file mode 100644 index 00000000..2761922d --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/CountEvent.java @@ -0,0 +1,52 @@ +package test.nested.owcount; + +/** + * A top-level extension of a nested OpenWorld root declared in another file. + */ +public interface CountEvent extends test.nested.owbase.Events.Event { + + /** Extended visitor that can handle {@link CountEvent}. */ + public interface Visitor extends test.nested.owbase.Events.Event.Visitor { + + /** Visit case for {@link CountEvent}. */ + R visit(test.nested.owcount.CountEvent self, A arg) throws E; + + } + + /** + * Creates a {@link test.nested.owcount.CountEvent} instance. + */ + static test.nested.owcount.CountEvent create() { + return new test.nested.owcount.impl.CountEvent_Impl(); + } + + /** Identifier for the {@link test.nested.owcount.CountEvent} type in JSON format. */ + String COUNT_EVENT__TYPE = "CountEvent"; + + /** @see #getCount() */ + String COUNT__PROP = "count"; + + int getCount(); + + /** + * @see #getCount() + */ + test.nested.owcount.CountEvent setCount(int value); + + @Override + test.nested.owcount.CountEvent setTimestamp(long value); + + /** Reads a new instance from the given reader. */ + static test.nested.owcount.CountEvent readCountEvent(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.owcount.impl.CountEvent_Impl result = new test.nested.owcount.impl.CountEvent_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link CountEvent} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static CountEvent readCountEvent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.owcount.impl.CountEvent_Impl.readCountEvent_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/OwcountTypes.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/OwcountTypes.java new file mode 100644 index 00000000..ac890314 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/OwcountTypes.java @@ -0,0 +1,19 @@ +package test.nested.owcount; + +/** + * Registration of extension types for the OpenWorld protocol. + */ +public class OwcountTypes implements de.haumacher.msgbuf.data.TypeRegistration { + + @Override + public void register() { + test.nested.owbase.Events.Event.register(test.nested.owcount.CountEvent.COUNT_EVENT__TYPE, test.nested.owcount.CountEvent::create); + } + + /** + * Explicit initialization for GWT or manual use. + */ + public static void init() { + new OwcountTypes().register(); + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/impl/CountEvent_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/impl/CountEvent_Impl.java new file mode 100644 index 00000000..c7147658 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/impl/CountEvent_Impl.java @@ -0,0 +1,181 @@ +package test.nested.owcount.impl; + +/** + * Implementation of {@link test.nested.owcount.CountEvent}. + */ +public class CountEvent_Impl extends test.nested.owbase.impl.Events_Impl.Event_Impl implements test.nested.owcount.CountEvent { + + private int _count = 0; + + /** + * Creates a {@link CountEvent_Impl} instance. + * + * @see test.nested.owcount.CountEvent#create() + */ + public CountEvent_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return null; + } + + @Override + public final int getCount() { + return _count; + } + + @Override + public test.nested.owcount.CountEvent setCount(int value) { + internalSetCount(value); + return this; + } + + /** Internal setter for {@link #getCount()} without chain call utility. */ + protected final void internalSetCount(int value) { + _listener.beforeSet(this, COUNT__PROP, value); + _count = value; + _listener.afterChanged(this, COUNT__PROP); + } + + @Override + public test.nested.owcount.CountEvent setTimestamp(long value) { + internalSetTimestamp(value); + return this; + } + + @Override + public String jsonType() { + return COUNT_EVENT__TYPE; + } + + @SuppressWarnings("hiding") + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + COUNT__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.owbase.impl.Events_Impl.Event_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.owbase.impl.Events_Impl.Event_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case COUNT__PROP: return getCount(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case COUNT__PROP: internalSetCount((int) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(COUNT__PROP); + out.value(getCount()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case COUNT__PROP: setCount(in.nextInt()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.owcount.CountEvent} type. */ + public static final String COUNT_EVENT__XML_ELEMENT = "count-event"; + + /** XML attribute or element name of a {@link #getCount} property. */ + private static final String COUNT__XML_ATTR = "count"; + + @Override + public String getXmlTagName() { + return COUNT_EVENT__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(COUNT__XML_ATTR, Integer.toString(getCount())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.owcount.CountEvent} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static CountEvent_Impl readCountEvent_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + CountEvent_Impl result = new CountEvent_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case COUNT__XML_ATTR: { + setCount(Integer.parseInt(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case COUNT__XML_ATTR: { + setCount(Integer.parseInt(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.nested.owbase.Events.Event.Visitor v, A arg) throws E { + if (v instanceof test.nested.owcount.CountEvent.Visitor) { + return ((test.nested.owcount.CountEvent.Visitor) v).visit(this, arg); + } + return v.visitDefault(this, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/owcount.proto b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/owcount.proto new file mode 100644 index 00000000..f788d511 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/owcount.proto @@ -0,0 +1,8 @@ +package test.nested.owcount; + +import "../owbase/owbase.proto"; + +/** A top-level extension of a nested OpenWorld root declared in another file. */ +message CountEvent extends test.nested.owbase.Events.Event { + int32 count; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/OwextTypes.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/OwextTypes.java new file mode 100644 index 00000000..e792e17e --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/OwextTypes.java @@ -0,0 +1,19 @@ +package test.nested.owext; + +/** + * Registration of extension types for the OpenWorld protocol. + */ +public class OwextTypes implements de.haumacher.msgbuf.data.TypeRegistration { + + @Override + public void register() { + test.nested.owbase.Events.Event.register(test.nested.owext.Patches.PatchEvent.PATCH_EVENT__TYPE, test.nested.owext.Patches.PatchEvent::create); + } + + /** + * Explicit initialization for GWT or manual use. + */ + public static void init() { + new OwextTypes().register(); + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/Patches.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/Patches.java new file mode 100644 index 00000000..0a9fbb77 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/Patches.java @@ -0,0 +1,89 @@ +package test.nested.owext; + +/** + * Nested extensions of a nested OpenWorld root declared in another file. + * + *

+ * No top-level definition of this file extends the OpenWorld root: the implied NoBinary must be + * detected from the nested extension. + *

+ */ +public interface Patches extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + public interface PatchEvent extends test.nested.owbase.Events.Event { + + /** Extended visitor that can handle {@link PatchEvent}. */ + public interface Visitor extends test.nested.owbase.Events.Event.Visitor { + + /** Visit case for {@link PatchEvent}. */ + R visit(test.nested.owext.Patches.PatchEvent self, A arg) throws E; + + } + + /** + * Creates a {@link test.nested.owext.Patches.PatchEvent} instance. + */ + static test.nested.owext.Patches.PatchEvent create() { + return new test.nested.owext.impl.Patches_Impl.PatchEvent_Impl(); + } + + /** Identifier for the {@link test.nested.owext.Patches.PatchEvent} type in JSON format. */ + String PATCH_EVENT__TYPE = "PatchEvent"; + + /** @see #getPatch() */ + String PATCH__PROP = "patch"; + + String getPatch(); + + /** + * @see #getPatch() + */ + test.nested.owext.Patches.PatchEvent setPatch(String value); + + @Override + test.nested.owext.Patches.PatchEvent setTimestamp(long value); + + /** Reads a new instance from the given reader. */ + static test.nested.owext.Patches.PatchEvent readPatchEvent(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.owext.impl.Patches_Impl.PatchEvent_Impl result = new test.nested.owext.impl.Patches_Impl.PatchEvent_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link PatchEvent} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static PatchEvent readPatchEvent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.owext.impl.Patches_Impl.PatchEvent_Impl.readPatchEvent_XmlContent(in); + } + + } + + /** + * Creates a {@link test.nested.owext.Patches} instance. + */ + static test.nested.owext.Patches create() { + return new test.nested.owext.impl.Patches_Impl(); + } + + /** Identifier for the {@link test.nested.owext.Patches} type in JSON format. */ + String PATCHES__TYPE = "Patches"; + + @Override + public test.nested.owext.Patches registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.owext.Patches unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.owext.Patches readPatches(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.owext.impl.Patches_Impl result = new test.nested.owext.impl.Patches_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Patches} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Patches readPatches(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.owext.impl.Patches_Impl.readPatches_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/impl/Patches_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/impl/Patches_Impl.java new file mode 100644 index 00000000..ab4131b1 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/impl/Patches_Impl.java @@ -0,0 +1,306 @@ +package test.nested.owext.impl; + +/** + * Implementation of {@link test.nested.owext.Patches}. + */ +public class Patches_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.owext.Patches { + /** + * Implementation of {@link test.nested.owext.Patches.PatchEvent}. + */ + public static class PatchEvent_Impl extends test.nested.owbase.impl.Events_Impl.Event_Impl implements test.nested.owext.Patches.PatchEvent { + + private String _patch = ""; + + /** + * Creates a {@link PatchEvent_Impl} instance. + * + * @see test.nested.owext.Patches.PatchEvent#create() + */ + public PatchEvent_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return null; + } + + @Override + public final String getPatch() { + return _patch; + } + + @Override + public test.nested.owext.Patches.PatchEvent setPatch(String value) { + internalSetPatch(value); + return this; + } + + /** Internal setter for {@link #getPatch()} without chain call utility. */ + protected final void internalSetPatch(String value) { + _listener.beforeSet(this, PATCH__PROP, value); + _patch = value; + _listener.afterChanged(this, PATCH__PROP); + } + + @Override + public test.nested.owext.Patches.PatchEvent setTimestamp(long value) { + internalSetTimestamp(value); + return this; + } + + @Override + public String jsonType() { + return PATCH_EVENT__TYPE; + } + + @SuppressWarnings("hiding") + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + PATCH__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.owbase.impl.Events_Impl.Event_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.owbase.impl.Events_Impl.Event_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case PATCH__PROP: return getPatch(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case PATCH__PROP: internalSetPatch((String) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(PATCH__PROP); + out.value(getPatch()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case PATCH__PROP: setPatch(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.owext.Patches.PatchEvent} type. */ + public static final String PATCH_EVENT__XML_ELEMENT = "patch-event"; + + /** XML attribute or element name of a {@link #getPatch} property. */ + private static final String PATCH__XML_ATTR = "patch"; + + @Override + public String getXmlTagName() { + return PATCH_EVENT__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(PATCH__XML_ATTR, getPatch()); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.owext.Patches.PatchEvent} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static PatchEvent_Impl readPatchEvent_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + PatchEvent_Impl result = new PatchEvent_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case PATCH__XML_ATTR: { + setPatch(value); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case PATCH__XML_ATTR: { + setPatch(in.getElementText()); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.nested.owbase.Events.Event.Visitor v, A arg) throws E { + if (v instanceof test.nested.owext.Patches.PatchEvent.Visitor) { + return ((test.nested.owext.Patches.PatchEvent.Visitor) v).visit(this, arg); + } + return v.visitDefault(this, arg); + } + + } + + /** + * Creates a {@link Patches_Impl} instance. + * + * @see test.nested.owext.Patches#create() + */ + public Patches_Impl() { + super(); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.owext.Patches registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.owext.Patches unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return PATCHES__TYPE; + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + /** XML element name representing a {@link test.nested.owext.Patches} type. */ + public static final String PATCHES__XML_ELEMENT = "patches"; + + @Override + public String getXmlTagName() { + return PATCHES__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.nested.owext.Patches} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Patches_Impl readPatches_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Patches_Impl result = new Patches_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/owext.proto b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/owext.proto new file mode 100644 index 00000000..1fd191d5 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/owext.proto @@ -0,0 +1,17 @@ +package test.nested.owext; + +import "../owbase/owbase.proto"; + +/** + * Nested extensions of a nested OpenWorld root declared in another file. + * + *

+ * No top-level definition of this file extends the OpenWorld root: the implied NoBinary must be + * detected from the nested extension. + *

+ */ +message Patches { + message PatchEvent extends test.nested.owbase.Events.Event { + string patch; + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/shapes.proto b/de.haumacher.msgbuf.generator/src/test/java/test/nested/shapes.proto new file mode 100644 index 00000000..5741f41f --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/shapes.proto @@ -0,0 +1,100 @@ +package test.nested.data; + +/** + * Hierarchies with an abstract root declared inside other messages (issue #16). + */ +message Outer { + /** Abstract root of a hierarchy nested in a top-level message. */ + abstract message Shape { + string name; + } + + message Circle extends Shape { + int32 radius; + } + + message Square extends Shape { + int32 side; + } + + /** A sibling message holding values of the nested abstract type. */ + message Drawing { + Shape main; + repeated Shape shapes; + } + + /** A field of the nested abstract type in the outer message itself. */ + Shape shape; +} + +/** + * A hierarchy nested two levels deep. + */ +message Level1 { + message Level2 { + abstract message Node { + string label; + } + + /** Abstract intermediate. */ + abstract message Composite extends Node { + repeated Node children; + } + + message Leaf extends Node { + int32 value; + } + + message Branch extends Composite { + bool expanded; + } + + message Root extends Composite { + string title; + } + } + + Level2.Node node; + repeated Level2.Node nodes; +} + +/** + * A top-level abstract root. + */ +abstract message Animal { + string name; +} + +/** + * A container for sub-messages extending a top-level abstract message. + */ +message Zoo { + message Cat extends Animal { + bool indoor; + } + + /** A nested abstract intermediate below a top-level root. */ + abstract message Bird extends Animal { + double wingspan; + } + + message Parrot extends Bird { + repeated string words; + } + + repeated Animal animals; +} + +/** A top-level message extending a nested abstract message. */ +message Triangle extends Outer.Shape { + int32 base; + int32 height; +} + +/** A top-level holder of values of nested abstract types. */ +message Holder { + Outer.Shape shape; + repeated Outer.Shape shapes; + Level1.Level2.Node node; + repeated Animal animals; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/META-INF/services/de.haumacher.msgbuf.data.TypeRegistration b/de.haumacher.msgbuf.generator/src/test/resources/META-INF/services/de.haumacher.msgbuf.data.TypeRegistration index e8bcff82..a3eef857 100644 --- a/de.haumacher.msgbuf.generator/src/test/resources/META-INF/services/de.haumacher.msgbuf.data.TypeRegistration +++ b/de.haumacher.msgbuf.generator/src/test/resources/META-INF/services/de.haumacher.msgbuf.data.TypeRegistration @@ -1,2 +1,4 @@ test.openworld.ext1.Ext1Types +test.nested.owcount.OwcountTypes test.openworld.ext2.Ext2Types +test.nested.owext.OwextTypes From dc8ebcf5b68a1a712614070b46827a5190552659 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 15:52:44 +0200 Subject: [PATCH 192/207] Honor the format options for enums and reject cross-file references to disabled formats. `EnumGenerator` had no options and always emitted the JSON and binary methods, so `option NoBinary` and `option NoJson` did not apply to enums (#20). It now uses the same format rules as `MessageGenerator`, which gets the rules for both. With that change, a file that uses an enum of another file in a format that file disables would get uncompilable code. The same already happened on main for messages of such files and for references between SharedGraph and non-SharedGraph files. As decided by the maintainer, the generator now rejects these references in a validation stage before writing any code, naming both files and the option to change. It reports them in a `GeneratorException`; the CLI prints them and exits with status 1. The formats a field needs come from the generator for JSON and binary and from the new `GeneratorPlugin.addFormats()` / `addFieldFormats()` for plug-in formats. The XML plugin reports its actual behavior: it skips maps and, unlike JSON and binary, serializes transient fields (#29). Closes #20 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 6 + README.md | 12 +- .../msgbuf/generator/EnumGenerator.java | 31 +- .../haumacher/msgbuf/generator/Generator.java | 191 +++++++++++- .../msgbuf/generator/GeneratorException.java | 36 +++ .../msgbuf/generator/GeneratorPlugin.java | 54 ++++ .../msgbuf/generator/MessageGenerator.java | 20 +- .../generator/plugins/XmlStreamingPlugin.java | 22 ++ .../test/enumoptions/TestEnumOptions.java | 79 +++++ .../enumoptions/TestFormatReferences.java | 89 ++++++ .../test/java/test/enumoptions/nobinary.proto | 18 ++ .../java/test/enumoptions/nobinary/M.java | 102 +++++++ .../test/enumoptions/nobinary/TopLevel.java | 46 +++ .../enumoptions/nobinary/impl/M_Impl.java | 254 ++++++++++++++++ .../test/java/test/enumoptions/nojson.proto | 18 ++ .../test/java/test/enumoptions/nojson/M.java | 117 ++++++++ .../test/enumoptions/nojson/TopLevel.java | 54 ++++ .../test/enumoptions/nojson/impl/M_Impl.java | 276 ++++++++++++++++++ .../java/test/enumoptions/sharedgraph.proto | 18 ++ .../java/test/enumoptions/sharedgraph/M.java | 104 +++++++ .../enumoptions/sharedgraph/TopLevel.java | 46 +++ .../enumoptions/sharedgraph/impl/M_Impl.java | 242 +++++++++++++++ .../reject/formats/colors/colors.proto | 13 + .../reject/formats/graph/graph.proto | 10 + .../reject/formats/paint/paint-nobinary.proto | 10 + .../reject/formats/paint/paint.proto | 14 + 26 files changed, 1871 insertions(+), 11 deletions(-) create mode 100644 de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorException.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/TestEnumOptions.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/TestFormatReferences.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary/M.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary/TopLevel.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary/impl/M_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson/M.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson/TopLevel.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson/impl/M_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph/M.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph/TopLevel.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph/impl/M_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/formats/colors/colors.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/formats/graph/graph.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/formats/paint/paint-nobinary.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/formats/paint/paint.proto diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bc58689..1d8e08c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,12 @@ their qualified names in the generated JSON and XML readers (previously uncompilable). For `option OpenWorld`, the "same file" test for local subtypes and the implied `NoBinary` of extension files now also hold for nested definitions. +- **Format options for enums** (#20): `option NoBinary` and `option NoJson` (and the implied `NoBinary` of + `option SharedGraph` and `option OpenWorld`) now also suppress the binary and JSON methods of enums. + **Source compatibility:** a file that uses an enum of another file in a format the other file disables did compile + before, because enums always had all methods. It is now rejected with an error naming both files and the option, + as are references to messages of such files and mixed `option SharedGraph` references, which generated uncompilable + code before. The generator (CLI and Maven plugin) now stops without writing code when it finds such errors. ## 1.2.1 diff --git a/README.md b/README.md index fe703035..30daccc2 100644 --- a/README.md +++ b/README.md @@ -196,14 +196,22 @@ For binary serialization, json values are wrapped in a `JsonValue` message envel ## Global protocol options ### `option NoJson` -Disables generation of read and write methods for the JSON format. +Disables generation of read and write methods for the JSON format (for messages and enums). ### `option NoBinary` -Disables generation of read and write methods for binary format. +Disables generation of read and write methods for binary format (for messages and enums). ### `option NoXml` Disables generation of read and write methods for XML format. +The format options apply to all messages and enums of a file. A message that references a message or enum of another +file (as field type or with `extends`) needs the read and write methods of each format it generates itself in that +other file. The generator rejects a reference to a definition generated without such a format, and generates no code +in that case. Either disable the format in the referencing file as well, or enable it in the referenced one. The same +holds for `option SharedGraph`, which has its own JSON methods for messages: a message can reference messages of +another file only if both files use `option SharedGraph`, or neither does. Enums are not affected by +`option SharedGraph`. `transient` fields are not written in JSON or binary format, so they don't need these formats. + ### `option NoXmlNames` Disables generation of constants for the XML format. diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/EnumGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/EnumGenerator.java index 08d3dafd..cc14f4a1 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/EnumGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/EnumGenerator.java @@ -8,11 +8,13 @@ import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import de.haumacher.msgbuf.generator.ast.Constant; import de.haumacher.msgbuf.generator.ast.DefinitionFile; import de.haumacher.msgbuf.generator.ast.EnumDef; +import de.haumacher.msgbuf.generator.ast.Option; import de.haumacher.msgbuf.generator.ast.QName; import de.haumacher.msgbuf.generator.common.MsgBufJsonProtocol; import de.haumacher.msgbuf.generator.util.AbstractJavaGenerator; @@ -25,13 +27,22 @@ public class EnumGenerator extends AbstractJavaGenerator { private EnumDef _def; + private final boolean _json; + + private final boolean _binary; + /** * Creates a {@link EnumGenerator}. * + * @param options + * The options of the file defining the enumeration, selecting the serialization formats. * @param def + * The enumeration to generate. */ - public EnumGenerator(EnumDef def) { + public EnumGenerator(Map options, EnumDef def) { _def = def; + _json = MessageGenerator.isJson(options); + _binary = MessageGenerator.isBinary(options); } @Override @@ -87,6 +98,17 @@ protected void generate() { } line("}"); + if (_json) { + generateJsonIO(); + } + if (_binary) { + generateBinaryIO(); + } + + line("}"); + } + + private void generateJsonIO() { nl(); line("/** Writes this instance to the given output. */"); line("public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException {"); @@ -102,7 +124,10 @@ protected void generate() { line("return " + CodeConvention.ENUM_VALUE_OF_PROTOCOL + "(in.nextString());"); } line("}"); - + } + + private void generateBinaryIO() { + List constants = _def.getConstants(); nl(); line("/** Writes this instance to the given binary output. */"); line("public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException {"); @@ -131,8 +156,6 @@ protected void generate() { line("}"); } line("}"); - - line("}"); } private void generateConstants() { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java index 194879f4..38565465 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java @@ -41,6 +41,7 @@ import de.haumacher.msgbuf.generator.parser.ProtobufParser; import de.haumacher.msgbuf.generator.parser.ProtobufParserConstants; import de.haumacher.msgbuf.generator.parser.Token; +import de.haumacher.msgbuf.generator.plugins.XmlStreamingPlugin; import de.haumacher.msgbuf.generator.ts.TypeScriptGenerator; import de.haumacher.msgbuf.generator.util.FileGenerator; @@ -182,6 +183,16 @@ public void generate(GeneratorPlugin plugin) { propagateOpenWorldOptions(file); } + List errors = new ArrayList<>(); + for (DefinitionFile file : _files) { + if (!_importedFiles.contains(file)) { + validateFormatReferences(file, plugin, errors); + } + } + if (!errors.isEmpty()) { + throw new GeneratorException(errors); + } + TypeIdSynthesizer typeIdSynthesizer = new TypeIdSynthesizer(); for (DefinitionFile file : _files) { if (!Util.getFlag(file, "OpenWorld")) { @@ -337,6 +348,175 @@ private static boolean extendsOpenWorldFromOtherFile(DefinitionFile file, List + * The generated read and write methods of a message call the corresponding methods of the + * messages and enums of its fields and of its generalization. If one of these is defined in + * another file that disables the format, the generated code would not compile. + *

+ */ + private void validateFormatReferences(DefinitionFile file, GeneratorPlugin plugin, List errors) { + for (Definition def : file.getDefinitions()) { + validateFormatReferences(file, def, plugin, errors); + } + } + + private void validateFormatReferences(DefinitionFile file, Definition def, GeneratorPlugin plugin, List errors) { + if (!(def instanceof MessageDef)) { + return; + } + MessageDef message = (MessageDef) def; + Set formats = formats(file, plugin); + + MessageDef extended = message.getExtendedDef(); + if (extended != null) { + checkFormats(file, formats, "Message '" + Util.toString(message) + "' extends", extended, plugin, errors); + } + + for (Field field : message.getFields()) { + Set fieldFormats = fieldFormats(file, field, plugin); + for (Definition target : referencedDefinitions(field.getType())) { + checkFormats(file, fieldFormats, + "Field '" + Util.toString(message) + "." + field.getName() + "' references", target, plugin, errors); + } + } + + for (Definition inner : message.getDefinitions()) { + validateFormatReferences(file, inner, plugin, errors); + } + } + + private void checkFormats(DefinitionFile file, Set formats, String reference, Definition target, + GeneratorPlugin plugin, List errors) { + DefinitionFile targetFile = Util.definingFile(target); + if (targetFile == file) { + return; + } + boolean isEnum = target instanceof EnumDef; + Set targetFormats = isEnum ? enumFormats(targetFile.getOptions()) : formats(targetFile, plugin); + String prefix = sourceDescription(file) + ": " + reference + (isEnum ? " enum '" : " message '") + + Util.toString(target) + "' of '" + sourceDescription(targetFile) + "'"; + for (String format : formats) { + if (isEnum) { + if (format.equals(GRAPH_JSON_FORMAT)) { + // The JSON methods of an enum do not depend on the graph mode. + format = JSON_FORMAT; + } else if (!format.equals(JSON_FORMAT) && !format.equals(BINARY_FORMAT)) { + // Enums are serialized in plug-in formats through their protocol names. + continue; + } + } + if (targetFormats.contains(format)) { + continue; + } + if (format.equals(GRAPH_JSON_FORMAT) || (format.equals(JSON_FORMAT) && targetFormats.contains(GRAPH_JSON_FORMAT))) { + errors.add(prefix + ", but only one of the files uses option SharedGraph. Use option SharedGraph in both" + + " files or in neither."); + } else { + errors.add(prefix + ", which is generated without " + format + " serialization (" + + disabledBy(targetFile, format) + "). Add 'option " + DISABLE_OPTION.get(format) + ";' to '" + + sourceDescription(file) + "', or enable " + format + " serialization in '" + + sourceDescription(targetFile) + "'."); + } + } + } + + private static final String JSON_FORMAT = "JSON"; + + /** + * JSON of the SharedGraph mode, which has its own read and write methods. + */ + private static final String GRAPH_JSON_FORMAT = "SharedGraph JSON"; + + private static final String BINARY_FORMAT = "binary"; + + private static final Map DISABLE_OPTION = + Map.of(JSON_FORMAT, "NoJson", BINARY_FORMAT, "NoBinary", XmlStreamingPlugin.XML_FORMAT, "NoXml"); + + private static Set formats(DefinitionFile file, GeneratorPlugin plugin) { + Set result = coreFormats(file.getOptions()); + plugin.addFormats(file.getOptions(), result); + return result; + } + + private static Set fieldFormats(DefinitionFile file, Field field, GeneratorPlugin plugin) { + Set result = new HashSet<>(); + if (!field.isTransient() && !field.isDerived()) { + result.addAll(coreFormats(file.getOptions())); + } + plugin.addFieldFormats(file.getOptions(), field, result); + return result; + } + + /** + * The formats of the generated read and write methods of messages. + */ + private static Set coreFormats(Map options) { + Set result = new HashSet<>(); + if (MessageGenerator.isJson(options)) { + result.add(MessageGenerator.isTrue(options.get("SharedGraph"), false) ? GRAPH_JSON_FORMAT : JSON_FORMAT); + } + if (MessageGenerator.isBinary(options)) { + result.add(BINARY_FORMAT); + } + return result; + } + + /** + * The formats of the generated read and write methods of enums. + */ + private static Set enumFormats(Map options) { + Set result = new HashSet<>(); + if (MessageGenerator.isJson(options)) { + result.add(JSON_FORMAT); + } + if (MessageGenerator.isBinary(options)) { + result.add(BINARY_FORMAT); + } + return result; + } + + private static String disabledBy(DefinitionFile file, String format) { + if (format.equals(BINARY_FORMAT)) { + if (Util.getFlag(file, "SharedGraph")) { + return "option SharedGraph"; + } + if (Util.getFlag(file, "OpenWorld")) { + return "option OpenWorld implies NoBinary"; + } + } + return "option " + DISABLE_OPTION.get(format); + } + + private static List referencedDefinitions(Type type) { + List result = new ArrayList<>(); + type.visit(new Type.Visitor() { + @Override + public Void visit(CustomType self, Void arg) { + if (self.getDefinition() != null) { + result.add(self.getDefinition()); + } + return null; + } + + @Override + public Void visit(PrimitiveType self, Void arg) { + return null; + } + + @Override + public Void visit(MapType self, Void arg) { + self.getKeyType().visit(this, arg); + self.getValueType().visit(this, arg); + return null; + } + }, null); + return result; + } + private void resolveImports(DefinitionFile file, File sourceFile) throws IOException, ParseException { for (String importPath : file.getImports()) { // Try file system first @@ -613,7 +793,7 @@ public PackageGenerator(File dir, Map options, GeneratorPlugin p @Override public Void visit(EnumDef def, Void arg) { - return generateJava(CodeConvention.typeName(def), null, new EnumGenerator(def)); + return generateJava(CodeConvention.typeName(def), null, new EnumGenerator(_options, def)); } @Override @@ -715,7 +895,14 @@ public static void main(String... args) throws ParseException, IOException, Inst generator.setOut(out); } - generator.generate(loadPlugins()); + try { + generator.generate(loadPlugins()); + } catch (GeneratorException ex) { + for (String error : ex.getErrors()) { + System.err.println("ERROR: " + error); + } + System.exit(1); + } } /** diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorException.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorException.java new file mode 100644 index 00000000..7df8fecb --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorException.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2026 Bernhard Haumacher et al. All Rights Reserved. + */ +package de.haumacher.msgbuf.generator; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Rejection of the input definitions: code generation was not started, because the definitions + * are invalid. + */ +public class GeneratorException extends RuntimeException { + + private final List _errors; + + /** + * Creates a {@link GeneratorException}. + * + * @param errors + * The problems found, each naming the file and the definition concerned. + */ + public GeneratorException(List errors) { + super(String.join("\n", errors)); + _errors = Collections.unmodifiableList(new ArrayList<>(errors)); + } + + /** + * The problems found, each naming the file and the definition concerned. + */ + public List getErrors() { + return _errors; + } + +} diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java index b27322bb..a96a328d 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java @@ -5,7 +5,9 @@ import java.util.List; import java.util.Map; +import java.util.Set; +import de.haumacher.msgbuf.generator.ast.Field; import de.haumacher.msgbuf.generator.ast.MessageDef; import de.haumacher.msgbuf.generator.ast.Option; import de.haumacher.msgbuf.generator.util.FileGenerator; @@ -58,6 +60,46 @@ default FileGenerator messageImplContents(Map options, MessageDe return (out, indent) -> {/*ignore*/}; } + /** + * Adds the names of the serialization formats this plug-in generates code for. + * + *

+ * A message referencing a message of another file requires all formats of its own file in the + * other file, since its generated code calls the other message's generated read and write + * methods. + *

+ * + * @param options + * The options of a definition file. + * @param formats + * The set of format names to add to. + */ + default void addFormats(Map options, Set formats) { + // No additional formats by default. + } + + /** + * Adds the names of the serialization formats in which the code generated by this plug-in + * writes and reads the value of the given field. + * + *

+ * If the field references a message or enum of another file, that file must generate code for + * these formats. + *

+ * + * @param options + * The options of the file defining the field. + * @param field + * The field to check. + * @param formats + * The set of format names to add to. + * + * @see #addFormats(Map, Set) + */ + default void addFieldFormats(Map options, Field field, Set formats) { + // No additional formats by default. + } + /** * {@link GeneratorPlugin} that does not generate any output. */ @@ -88,6 +130,18 @@ public void addInterfaces(Map options, MessageDef def, List options, Set formats) { + self.addFormats(options, formats); + next.addFormats(options, formats); + } + + @Override + public void addFieldFormats(Map options, Field field, Set formats) { + self.addFieldFormats(options, field, formats); + next.addFieldFormats(options, field, formats); + } @Override public FileGenerator messageImplContents(Map options, MessageDef def) { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 853c60f6..4804f3a0 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -66,8 +66,8 @@ public MessageGenerator(NameTable table, Map options, boolean is _plugin = plugin; _defaultValues = new DefaultValueGenerator(options); _graph = isTrue(options.get("SharedGraph"), false); - _json = _graph || !isTrue(options.get("NoJson"), false); - _binary = !_graph && !isTrue(options.get("NoBinary"), false); + _json = isJson(options); + _binary = isBinary(options); _listener = _graph || !isTrue(options.get("NoListener"), false); _reflection = _listener || !isTrue(options.get("NoReflection"), false); _visitor = !isTrue(options.get("NoVisitor"), false); @@ -434,10 +434,24 @@ private void generateInnerDefinitions() { } } + /** + * Whether JSON serialization code is generated for the given file options. + */ + public static boolean isJson(Map options) { + return isTrue(options.get("SharedGraph"), false) || !isTrue(options.get("NoJson"), false); + } + + /** + * Whether binary serialization code is generated for the given file options. + */ + public static boolean isBinary(Map options) { + return !isTrue(options.get("SharedGraph"), false) && !isTrue(options.get("NoBinary"), false); + } + @Override public Void visit(EnumDef def, Void arg) { if (_interface || _noInterfaces) { - include(new EnumGenerator(def)); + include(new EnumGenerator(getOptions(), def)); } return null; } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java index bac45eef..0a2d1068 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java @@ -32,6 +32,13 @@ * {@link GeneratorPlugin} generating XML reading code for the {@link javax.xml.stream.XMLStreamReader} interface. */ public class XmlStreamingPlugin implements GeneratorPlugin { + + /** + * Name of the XML format. + * + * @see #addFormats(Map, Set) + */ + public static final String XML_FORMAT = "XML"; private boolean _noXmlNames; @@ -40,6 +47,21 @@ public void init(Map options) { _noXmlNames = noXmlNames(options); } + @Override + public void addFormats(Map options, Set formats) { + if (!noXml(options)) { + formats.add(XML_FORMAT); + } + } + + @Override + public void addFieldFormats(Map options, Field field, Set formats) { + // All fields except maps are written and read, including transient ones. + if (!noXml(options) && field.getType().kind() != Type.TypeKind.MAP_TYPE) { + formats.add(XML_FORMAT); + } + } + @Override public void addInterfaces(Map options, MessageDef def, List generalizations) { if (noXml(options)) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/TestEnumOptions.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/TestEnumOptions.java new file mode 100644 index 00000000..4d2c9b3d --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/TestEnumOptions.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2026 Bernhard Haumacher et al. All Rights Reserved. + */ +package test.enumoptions; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.lang.reflect.Method; + +import de.haumacher.msgbuf.binary.DataReader; +import de.haumacher.msgbuf.binary.DataWriter; +import de.haumacher.msgbuf.binary.OctetDataReader; +import de.haumacher.msgbuf.binary.OctetDataWriter; +import de.haumacher.msgbuf.io.StringR; +import de.haumacher.msgbuf.json.JsonReader; +import de.haumacher.msgbuf.json.JsonWriter; +import junit.framework.TestCase; + +/** + * Test case for enums honoring the serialization options of their file, like messages do (issue #20). + */ +@SuppressWarnings("javadoc") +public class TestEnumOptions extends TestCase { + + public void testNoBinary() throws IOException { + assertFormats(test.enumoptions.nobinary.M.Nested.class, true, false); + assertFormats(test.enumoptions.nobinary.TopLevel.class, true, false); + + test.enumoptions.nobinary.M value = test.enumoptions.nobinary.M.create() + .setNested(test.enumoptions.nobinary.M.Nested.B) + .setTop(test.enumoptions.nobinary.TopLevel.Y); + String json = value.toString(); + assertEquals("{\"nested\":\"B\",\"top\":\"Y\"}", json); + test.enumoptions.nobinary.M copy = test.enumoptions.nobinary.M.readM(new JsonReader(new StringR(json))); + assertEquals(test.enumoptions.nobinary.M.Nested.B, copy.getNested()); + assertEquals(test.enumoptions.nobinary.TopLevel.Y, copy.getTop()); + } + + public void testNoJson() throws IOException { + assertFormats(test.enumoptions.nojson.M.Nested.class, false, true); + assertFormats(test.enumoptions.nojson.TopLevel.class, false, true); + + test.enumoptions.nojson.M value = test.enumoptions.nojson.M.create() + .setNested(test.enumoptions.nojson.M.Nested.B) + .setTop(test.enumoptions.nojson.TopLevel.Y); + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + value.writeTo(new OctetDataWriter(buffer)); + test.enumoptions.nojson.M copy = test.enumoptions.nojson.M.readM( + new OctetDataReader(new ByteArrayInputStream(buffer.toByteArray()))); + assertEquals(test.enumoptions.nojson.M.Nested.B, copy.getNested()); + assertEquals(test.enumoptions.nojson.TopLevel.Y, copy.getTop()); + } + + public void testSharedGraph() { + // SharedGraph implies JSON and excludes binary. + assertFormats(test.enumoptions.sharedgraph.M.Nested.class, true, false); + assertFormats(test.enumoptions.sharedgraph.TopLevel.class, true, false); + } + + private static void assertFormats(Class> type, boolean json, boolean binary) { + String name = type.getSimpleName(); + assertEquals("JSON writer of " + name, json, hasMethod(type, "writeTo", JsonWriter.class)); + assertEquals("JSON reader of " + name, json, hasMethod(type, "read" + name, JsonReader.class)); + assertEquals("Binary writer of " + name, binary, hasMethod(type, "writeTo", DataWriter.class)); + assertEquals("Binary reader of " + name, binary, hasMethod(type, "read" + name, DataReader.class)); + } + + private static boolean hasMethod(Class type, String name, Class parameterType) { + for (Method method : type.getMethods()) { + if (method.getName().equals(name) && method.getParameterCount() == 1 + && method.getParameterTypes()[0] == parameterType) { + return true; + } + } + return false; + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/TestFormatReferences.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/TestFormatReferences.java new file mode 100644 index 00000000..a79b9e01 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/TestFormatReferences.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2026 Bernhard Haumacher et al. All Rights Reserved. + */ +package test.enumoptions; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.List; + +import de.haumacher.msgbuf.generator.Generator; +import de.haumacher.msgbuf.generator.GeneratorException; +import de.haumacher.msgbuf.generator.parser.ParseException; +import de.haumacher.msgbuf.generator.plugins.XmlStreamingPlugin; +import junit.framework.TestCase; + +/** + * Test case for rejecting references to definitions of other files that are generated without a + * serialization format the referencing file needs (issue #20). + */ +@SuppressWarnings("javadoc") +public class TestFormatReferences extends TestCase { + + private static final File FIXTURES = new File("src/test/resources/reject/formats"); + + public void testRejectMissingBinary() throws IOException, ParseException { + List errors = reject("paint/paint.proto"); + assertEquals(Arrays.asList( + "reject/formats/paint/paint.proto: Field 'reject.formats.paint.Paint.color' references enum" + + " 'reject.formats.colors.Color' of 'reject/formats/colors/colors.proto', which is generated without" + + " binary serialization (option NoBinary). Add 'option NoBinary;' to" + + " 'reject/formats/paint/paint.proto', or enable binary serialization in" + + " 'reject/formats/colors/colors.proto'.", + "reject/formats/paint/paint.proto: Field 'reject.formats.paint.Paint.shades' references message" + + " 'reject.formats.colors.Shade' of 'reject/formats/colors/colors.proto', which is generated without" + + " binary serialization (option NoBinary). Add 'option NoBinary;' to" + + " 'reject/formats/paint/paint.proto', or enable binary serialization in" + + " 'reject/formats/colors/colors.proto'.", + "reject/formats/paint/paint.proto: Field 'reject.formats.paint.Paint.Layer.colors' references enum" + + " 'reject.formats.colors.Color' of 'reject/formats/colors/colors.proto', which is generated without" + + " binary serialization (option NoBinary). Add 'option NoBinary;' to" + + " 'reject/formats/paint/paint.proto', or enable binary serialization in" + + " 'reject/formats/colors/colors.proto'."), + errors); + } + + public void testRejectSharedGraphMismatch() throws IOException, ParseException { + List errors = reject("graph/graph.proto"); + assertEquals(Arrays.asList( + "reject/formats/graph/graph.proto: Field 'reject.formats.graph.Node.shade' references message" + + " 'reject.formats.colors.Shade' of 'reject/formats/colors/colors.proto', but only one of the files" + + " uses option SharedGraph. Use option SharedGraph in both files or in neither."), + errors); + } + + public void testAcceptMatchingFormats() throws IOException, ParseException { + File out = newOutputDir(); + generator(out, "paint/paint-nobinary.proto").generate(new XmlStreamingPlugin()); + assertTrue(new File(out, "reject/formats/paint/PaintNoBinary.java").isFile()); + } + + private List reject(String proto) throws IOException, ParseException { + File out = newOutputDir(); + try { + generator(out, proto).generate(new XmlStreamingPlugin()); + fail("Expected rejection of '" + proto + "'."); + return null; + } catch (GeneratorException ex) { + String[] written = out.list(); + assertTrue("No code must be generated for rejected definitions.", written == null || written.length == 0); + return ex.getErrors(); + } + } + + private static Generator generator(File out, String proto) throws IOException, ParseException { + Generator generator = new Generator(); + generator.setOut(out); + generator.load(new File(FIXTURES, proto)); + return generator; + } + + private File newOutputDir() throws IOException { + File target = new File("target"); + target.mkdirs(); + return Files.createTempDirectory(target.toPath(), getName()).toFile(); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary.proto b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary.proto new file mode 100644 index 00000000..9ddc7e27 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary.proto @@ -0,0 +1,18 @@ +package test.enumoptions.nobinary; + +option NoBinary; + +/** Enums honor `option NoBinary` like messages do (issue #20). */ +message M { + enum Nested { + A; + B; + } + Nested nested; + TopLevel top; +} + +enum TopLevel { + X; + Y; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary/M.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary/M.java new file mode 100644 index 00000000..1e965591 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary/M.java @@ -0,0 +1,102 @@ +package test.enumoptions.nobinary; + +/** + * Enums honor `option NoBinary` like messages do (issue #20). + */ +public interface M extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + public enum Nested implements de.haumacher.msgbuf.data.ProtocolEnum { + + A("A"), + + B("B"), + + ; + + private final String _protocolName; + + private Nested(String protocolName) { + _protocolName = protocolName; + } + + /** + * The protocol name of a {@link Nested} constant. + * + * @see #valueOfProtocol(String) + */ + @Override + public String protocolName() { + return _protocolName; + } + + /** Looks up a {@link Nested} constant by it's protocol name. */ + public static Nested valueOfProtocol(String protocolName) { + if (protocolName == null) { return null; } + switch (protocolName) { + case "A": return A; + case "B": return B; + } + return A; + } + + /** Writes this instance to the given output. */ + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.value(protocolName()); + } + + /** Reads a new instance from the given reader. */ + public static Nested readNested(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + return valueOfProtocol(in.nextString()); + } + } + + /** + * Creates a {@link test.enumoptions.nobinary.M} instance. + */ + static test.enumoptions.nobinary.M create() { + return new test.enumoptions.nobinary.impl.M_Impl(); + } + + /** Identifier for the {@link test.enumoptions.nobinary.M} type in JSON format. */ + String M__TYPE = "M"; + + /** @see #getNested() */ + String NESTED__PROP = "nested"; + + /** @see #getTop() */ + String TOP__PROP = "top"; + + test.enumoptions.nobinary.M.Nested getNested(); + + /** + * @see #getNested() + */ + test.enumoptions.nobinary.M setNested(test.enumoptions.nobinary.M.Nested value); + + test.enumoptions.nobinary.TopLevel getTop(); + + /** + * @see #getTop() + */ + test.enumoptions.nobinary.M setTop(test.enumoptions.nobinary.TopLevel value); + + @Override + public test.enumoptions.nobinary.M registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.enumoptions.nobinary.M unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.enumoptions.nobinary.M readM(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.enumoptions.nobinary.impl.M_Impl result = new test.enumoptions.nobinary.impl.M_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link M} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static M readM(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.enumoptions.nobinary.impl.M_Impl.readM_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary/TopLevel.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary/TopLevel.java new file mode 100644 index 00000000..b86d5e69 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary/TopLevel.java @@ -0,0 +1,46 @@ +package test.enumoptions.nobinary; + +public enum TopLevel implements de.haumacher.msgbuf.data.ProtocolEnum { + + X("X"), + + Y("Y"), + + ; + + private final String _protocolName; + + private TopLevel(String protocolName) { + _protocolName = protocolName; + } + + /** + * The protocol name of a {@link TopLevel} constant. + * + * @see #valueOfProtocol(String) + */ + @Override + public String protocolName() { + return _protocolName; + } + + /** Looks up a {@link TopLevel} constant by it's protocol name. */ + public static TopLevel valueOfProtocol(String protocolName) { + if (protocolName == null) { return null; } + switch (protocolName) { + case "X": return X; + case "Y": return Y; + } + return X; + } + + /** Writes this instance to the given output. */ + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.value(protocolName()); + } + + /** Reads a new instance from the given reader. */ + public static TopLevel readTopLevel(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + return valueOfProtocol(in.nextString()); + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary/impl/M_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary/impl/M_Impl.java new file mode 100644 index 00000000..0a8c89f2 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nobinary/impl/M_Impl.java @@ -0,0 +1,254 @@ +package test.enumoptions.nobinary.impl; + +/** + * Implementation of {@link test.enumoptions.nobinary.M}. + */ +public class M_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.enumoptions.nobinary.M { + + private test.enumoptions.nobinary.M.Nested _nested = test.enumoptions.nobinary.M.Nested.A; + + private test.enumoptions.nobinary.TopLevel _top = test.enumoptions.nobinary.TopLevel.X; + + /** + * Creates a {@link M_Impl} instance. + * + * @see test.enumoptions.nobinary.M#create() + */ + public M_Impl() { + super(); + } + + @Override + public final test.enumoptions.nobinary.M.Nested getNested() { + return _nested; + } + + @Override + public test.enumoptions.nobinary.M setNested(test.enumoptions.nobinary.M.Nested value) { + internalSetNested(value); + return this; + } + + /** Internal setter for {@link #getNested()} without chain call utility. */ + protected final void internalSetNested(test.enumoptions.nobinary.M.Nested value) { + if (value == null) throw new IllegalArgumentException("Property 'nested' cannot be null."); + _listener.beforeSet(this, NESTED__PROP, value); + _nested = value; + _listener.afterChanged(this, NESTED__PROP); + } + + @Override + public final test.enumoptions.nobinary.TopLevel getTop() { + return _top; + } + + @Override + public test.enumoptions.nobinary.M setTop(test.enumoptions.nobinary.TopLevel value) { + internalSetTop(value); + return this; + } + + /** Internal setter for {@link #getTop()} without chain call utility. */ + protected final void internalSetTop(test.enumoptions.nobinary.TopLevel value) { + if (value == null) throw new IllegalArgumentException("Property 'top' cannot be null."); + _listener.beforeSet(this, TOP__PROP, value); + _top = value; + _listener.afterChanged(this, TOP__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.enumoptions.nobinary.M registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.enumoptions.nobinary.M unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return M__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + NESTED__PROP, + TOP__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NESTED__PROP: return getNested(); + case TOP__PROP: return getTop(); + default: return test.enumoptions.nobinary.M.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NESTED__PROP: internalSetNested((test.enumoptions.nobinary.M.Nested) value); break; + case TOP__PROP: internalSetTop((test.enumoptions.nobinary.TopLevel) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NESTED__PROP); + getNested().writeTo(out); + out.name(TOP__PROP); + getTop().writeTo(out); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NESTED__PROP: setNested(test.enumoptions.nobinary.M.Nested.readNested(in)); break; + case TOP__PROP: setTop(test.enumoptions.nobinary.TopLevel.readTopLevel(in)); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.enumoptions.nobinary.M} type. */ + public static final String M__XML_ELEMENT = "m"; + + /** XML attribute or element name of a {@link #getNested} property. */ + private static final String NESTED__XML_ATTR = "nested"; + + /** XML attribute or element name of a {@link #getTop} property. */ + private static final String TOP__XML_ATTR = "top"; + + @Override + public String getXmlTagName() { + return M__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NESTED__XML_ATTR, getNested().protocolName()); + out.writeAttribute(TOP__XML_ATTR, getTop().protocolName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.enumoptions.nobinary.M} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static M_Impl readM_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + M_Impl result = new M_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NESTED__XML_ATTR: { + setNested(test.enumoptions.nobinary.M.Nested.valueOfProtocol(value)); + break; + } + case TOP__XML_ATTR: { + setTop(test.enumoptions.nobinary.TopLevel.valueOfProtocol(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NESTED__XML_ATTR: { + setNested(test.enumoptions.nobinary.M.Nested.valueOfProtocol(in.getElementText())); + break; + } + case TOP__XML_ATTR: { + setTop(test.enumoptions.nobinary.TopLevel.valueOfProtocol(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson.proto b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson.proto new file mode 100644 index 00000000..dd2c6d8e --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson.proto @@ -0,0 +1,18 @@ +package test.enumoptions.nojson; + +option NoJson; + +/** Enums honor `option NoJson` like messages do (issue #20). */ +message M { + enum Nested { + A; + B; + } + Nested nested; + TopLevel top; +} + +enum TopLevel { + X; + Y; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson/M.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson/M.java new file mode 100644 index 00000000..90127067 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson/M.java @@ -0,0 +1,117 @@ +package test.enumoptions.nojson; + +/** + * Enums honor `option NoJson` like messages do (issue #20). + */ +public interface M extends de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + public enum Nested implements de.haumacher.msgbuf.data.ProtocolEnum { + + A("A"), + + B("B"), + + ; + + private final String _protocolName; + + private Nested(String protocolName) { + _protocolName = protocolName; + } + + /** + * The protocol name of a {@link Nested} constant. + * + * @see #valueOfProtocol(String) + */ + @Override + public String protocolName() { + return _protocolName; + } + + /** Looks up a {@link Nested} constant by it's protocol name. */ + public static Nested valueOfProtocol(String protocolName) { + if (protocolName == null) { return null; } + switch (protocolName) { + case "A": return A; + case "B": return B; + } + return A; + } + + /** Writes this instance to the given binary output. */ + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + switch (this) { + case A: out.value(1); break; + case B: out.value(2); break; + default: out.value(0); + } + } + + /** Reads a new instance from the given binary reader. */ + public static Nested readNested(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + switch (in.nextInt()) { + case 1: return A; + case 2: return B; + default: return A; + } + } + } + + /** + * Creates a {@link test.enumoptions.nojson.M} instance. + */ + static test.enumoptions.nojson.M create() { + return new test.enumoptions.nojson.impl.M_Impl(); + } + + /** Identifier for the {@link test.enumoptions.nojson.M} type in JSON format. */ + String M__TYPE = "M"; + + /** @see #getNested() */ + String NESTED__PROP = "nested"; + + /** @see #getTop() */ + String TOP__PROP = "top"; + + /** Identifier for the property {@link #getNested()} in binary format. */ + static final int NESTED__ID = 1; + + /** Identifier for the property {@link #getTop()} in binary format. */ + static final int TOP__ID = 2; + + test.enumoptions.nojson.M.Nested getNested(); + + /** + * @see #getNested() + */ + test.enumoptions.nojson.M setNested(test.enumoptions.nojson.M.Nested value); + + test.enumoptions.nojson.TopLevel getTop(); + + /** + * @see #getTop() + */ + test.enumoptions.nojson.M setTop(test.enumoptions.nojson.TopLevel value); + + @Override + public test.enumoptions.nojson.M registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.enumoptions.nojson.M unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.enumoptions.nojson.M readM(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.enumoptions.nojson.M result = test.enumoptions.nojson.impl.M_Impl.readM_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link M} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static M readM(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.enumoptions.nojson.impl.M_Impl.readM_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson/TopLevel.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson/TopLevel.java new file mode 100644 index 00000000..2452fbf0 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson/TopLevel.java @@ -0,0 +1,54 @@ +package test.enumoptions.nojson; + +public enum TopLevel implements de.haumacher.msgbuf.data.ProtocolEnum { + + X("X"), + + Y("Y"), + + ; + + private final String _protocolName; + + private TopLevel(String protocolName) { + _protocolName = protocolName; + } + + /** + * The protocol name of a {@link TopLevel} constant. + * + * @see #valueOfProtocol(String) + */ + @Override + public String protocolName() { + return _protocolName; + } + + /** Looks up a {@link TopLevel} constant by it's protocol name. */ + public static TopLevel valueOfProtocol(String protocolName) { + if (protocolName == null) { return null; } + switch (protocolName) { + case "X": return X; + case "Y": return Y; + } + return X; + } + + /** Writes this instance to the given binary output. */ + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + switch (this) { + case X: out.value(1); break; + case Y: out.value(2); break; + default: out.value(0); + } + } + + /** Reads a new instance from the given binary reader. */ + public static TopLevel readTopLevel(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + switch (in.nextInt()) { + case 1: return X; + case 2: return Y; + default: return X; + } + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson/impl/M_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson/impl/M_Impl.java new file mode 100644 index 00000000..aef7bc47 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/nojson/impl/M_Impl.java @@ -0,0 +1,276 @@ +package test.enumoptions.nojson.impl; + +/** + * Implementation of {@link test.enumoptions.nojson.M}. + */ +public class M_Impl implements test.enumoptions.nojson.M { + + private test.enumoptions.nojson.M.Nested _nested = test.enumoptions.nojson.M.Nested.A; + + private test.enumoptions.nojson.TopLevel _top = test.enumoptions.nojson.TopLevel.X; + + /** + * Creates a {@link M_Impl} instance. + * + * @see test.enumoptions.nojson.M#create() + */ + public M_Impl() { + super(); + } + + @Override + public final test.enumoptions.nojson.M.Nested getNested() { + return _nested; + } + + @Override + public test.enumoptions.nojson.M setNested(test.enumoptions.nojson.M.Nested value) { + internalSetNested(value); + return this; + } + + /** Internal setter for {@link #getNested()} without chain call utility. */ + protected final void internalSetNested(test.enumoptions.nojson.M.Nested value) { + if (value == null) throw new IllegalArgumentException("Property 'nested' cannot be null."); + _listener.beforeSet(this, NESTED__PROP, value); + _nested = value; + _listener.afterChanged(this, NESTED__PROP); + } + + @Override + public final test.enumoptions.nojson.TopLevel getTop() { + return _top; + } + + @Override + public test.enumoptions.nojson.M setTop(test.enumoptions.nojson.TopLevel value) { + internalSetTop(value); + return this; + } + + /** Internal setter for {@link #getTop()} without chain call utility. */ + protected final void internalSetTop(test.enumoptions.nojson.TopLevel value) { + if (value == null) throw new IllegalArgumentException("Property 'top' cannot be null."); + _listener.beforeSet(this, TOP__PROP, value); + _top = value; + _listener.afterChanged(this, TOP__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.enumoptions.nojson.M registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.enumoptions.nojson.M unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return M__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + NESTED__PROP, + TOP__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NESTED__PROP: return getNested(); + case TOP__PROP: return getTop(); + default: return test.enumoptions.nojson.M.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NESTED__PROP: internalSetNested((test.enumoptions.nojson.M.Nested) value); break; + case TOP__PROP: internalSetTop((test.enumoptions.nojson.TopLevel) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(NESTED__ID); + getNested().writeTo(out); + out.name(TOP__ID); + getTop().writeTo(out); + } + + /** Helper for creating an object of type {@link test.enumoptions.nojson.M} from a polymorphic composition. */ + public static test.enumoptions.nojson.M readM_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.enumoptions.nojson.impl.M_Impl result = new M_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case NESTED__ID: setNested(test.enumoptions.nojson.M.Nested.readNested(in)); break; + case TOP__ID: setTop(test.enumoptions.nojson.TopLevel.readTopLevel(in)); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.enumoptions.nojson.M} type. */ + public static final String M__XML_ELEMENT = "m"; + + /** XML attribute or element name of a {@link #getNested} property. */ + private static final String NESTED__XML_ATTR = "nested"; + + /** XML attribute or element name of a {@link #getTop} property. */ + private static final String TOP__XML_ATTR = "top"; + + @Override + public String getXmlTagName() { + return M__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NESTED__XML_ATTR, getNested().protocolName()); + out.writeAttribute(TOP__XML_ATTR, getTop().protocolName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.enumoptions.nojson.M} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static M_Impl readM_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + M_Impl result = new M_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NESTED__XML_ATTR: { + setNested(test.enumoptions.nojson.M.Nested.valueOfProtocol(value)); + break; + } + case TOP__XML_ATTR: { + setTop(test.enumoptions.nojson.TopLevel.valueOfProtocol(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NESTED__XML_ATTR: { + setNested(test.enumoptions.nojson.M.Nested.valueOfProtocol(in.getElementText())); + break; + } + case TOP__XML_ATTR: { + setTop(test.enumoptions.nojson.TopLevel.valueOfProtocol(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph.proto b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph.proto new file mode 100644 index 00000000..8fc7aefd --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph.proto @@ -0,0 +1,18 @@ +package test.enumoptions.sharedgraph; + +option SharedGraph; + +/** Enums honor `option SharedGraph` like messages do (issue #20). */ +message M { + enum Nested { + A; + B; + } + Nested nested; + TopLevel top; +} + +enum TopLevel { + X; + Y; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph/M.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph/M.java new file mode 100644 index 00000000..8f9cc85c --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph/M.java @@ -0,0 +1,104 @@ +package test.enumoptions.sharedgraph; + +/** + * Enums honor `option SharedGraph` like messages do (issue #20). + */ +public interface M extends de.haumacher.msgbuf.graph.SharedGraphNode, de.haumacher.msgbuf.xml.XmlSerializable { + + public enum Nested implements de.haumacher.msgbuf.data.ProtocolEnum { + + A("A"), + + B("B"), + + ; + + private final String _protocolName; + + private Nested(String protocolName) { + _protocolName = protocolName; + } + + /** + * The protocol name of a {@link Nested} constant. + * + * @see #valueOfProtocol(String) + */ + @Override + public String protocolName() { + return _protocolName; + } + + /** Looks up a {@link Nested} constant by it's protocol name. */ + public static Nested valueOfProtocol(String protocolName) { + if (protocolName == null) { return null; } + switch (protocolName) { + case "A": return A; + case "B": return B; + } + return A; + } + + /** Writes this instance to the given output. */ + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.value(protocolName()); + } + + /** Reads a new instance from the given reader. */ + public static Nested readNested(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + return valueOfProtocol(in.nextString()); + } + } + + /** + * Creates a {@link test.enumoptions.sharedgraph.M} instance. + */ + static test.enumoptions.sharedgraph.M create() { + return new test.enumoptions.sharedgraph.impl.M_Impl(); + } + + /** Identifier for the {@link test.enumoptions.sharedgraph.M} type in JSON format. */ + String M__TYPE = "M"; + + /** @see #getNested() */ + String NESTED__PROP = "nested"; + + /** @see #getTop() */ + String TOP__PROP = "top"; + + test.enumoptions.sharedgraph.M.Nested getNested(); + + /** + * @see #getNested() + */ + test.enumoptions.sharedgraph.M setNested(test.enumoptions.sharedgraph.M.Nested value); + + test.enumoptions.sharedgraph.TopLevel getTop(); + + /** + * @see #getTop() + */ + test.enumoptions.sharedgraph.M setTop(test.enumoptions.sharedgraph.TopLevel value); + + /** Reads a new instance from the given reader. */ + static test.enumoptions.sharedgraph.M readM(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + if (in.peek() == de.haumacher.msgbuf.json.JsonToken.NUMBER) { + return (test.enumoptions.sharedgraph.M) scope.resolveOrFail(in.nextInt()); + } + in.beginArray(); + String type = in.nextString(); + assert M__TYPE.equals(type); + int id = in.nextInt(); + test.enumoptions.sharedgraph.impl.M_Impl result = new test.enumoptions.sharedgraph.impl.M_Impl(); + scope.readData(result, id, in); + in.endArray(); + return result; + } + + /** Creates a new {@link M} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static M readM(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.enumoptions.sharedgraph.impl.M_Impl.readM_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph/TopLevel.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph/TopLevel.java new file mode 100644 index 00000000..32ab400b --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph/TopLevel.java @@ -0,0 +1,46 @@ +package test.enumoptions.sharedgraph; + +public enum TopLevel implements de.haumacher.msgbuf.data.ProtocolEnum { + + X("X"), + + Y("Y"), + + ; + + private final String _protocolName; + + private TopLevel(String protocolName) { + _protocolName = protocolName; + } + + /** + * The protocol name of a {@link TopLevel} constant. + * + * @see #valueOfProtocol(String) + */ + @Override + public String protocolName() { + return _protocolName; + } + + /** Looks up a {@link TopLevel} constant by it's protocol name. */ + public static TopLevel valueOfProtocol(String protocolName) { + if (protocolName == null) { return null; } + switch (protocolName) { + case "X": return X; + case "Y": return Y; + } + return X; + } + + /** Writes this instance to the given output. */ + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.value(protocolName()); + } + + /** Reads a new instance from the given reader. */ + public static TopLevel readTopLevel(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + return valueOfProtocol(in.nextString()); + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph/impl/M_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph/impl/M_Impl.java new file mode 100644 index 00000000..2baa7cd3 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/sharedgraph/impl/M_Impl.java @@ -0,0 +1,242 @@ +package test.enumoptions.sharedgraph.impl; + +/** + * Implementation of {@link test.enumoptions.sharedgraph.M}. + */ +public class M_Impl extends de.haumacher.msgbuf.graph.AbstractSharedGraphNode implements test.enumoptions.sharedgraph.M { + + private test.enumoptions.sharedgraph.M.Nested _nested = test.enumoptions.sharedgraph.M.Nested.A; + + private test.enumoptions.sharedgraph.TopLevel _top = test.enumoptions.sharedgraph.TopLevel.X; + + /** + * Creates a {@link M_Impl} instance. + * + * @see test.enumoptions.sharedgraph.M#create() + */ + public M_Impl() { + super(); + } + + @Override + public final test.enumoptions.sharedgraph.M.Nested getNested() { + return _nested; + } + + @Override + public test.enumoptions.sharedgraph.M setNested(test.enumoptions.sharedgraph.M.Nested value) { + internalSetNested(value); + return this; + } + + /** Internal setter for {@link #getNested()} without chain call utility. */ + protected final void internalSetNested(test.enumoptions.sharedgraph.M.Nested value) { + if (value == null) throw new IllegalArgumentException("Property 'nested' cannot be null."); + _listener.beforeSet(this, NESTED__PROP, value); + _nested = value; + _listener.afterChanged(this, NESTED__PROP); + } + + @Override + public final test.enumoptions.sharedgraph.TopLevel getTop() { + return _top; + } + + @Override + public test.enumoptions.sharedgraph.M setTop(test.enumoptions.sharedgraph.TopLevel value) { + internalSetTop(value); + return this; + } + + /** Internal setter for {@link #getTop()} without chain call utility. */ + protected final void internalSetTop(test.enumoptions.sharedgraph.TopLevel value) { + if (value == null) throw new IllegalArgumentException("Property 'top' cannot be null."); + _listener.beforeSet(this, TOP__PROP, value); + _top = value; + _listener.afterChanged(this, TOP__PROP); + } + + @Override + public String jsonType() { + return M__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + NESTED__PROP, + TOP__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NESTED__PROP: return getNested(); + case TOP__PROP: return getTop(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NESTED__PROP: internalSetNested((test.enumoptions.sharedgraph.M.Nested) value); break; + case TOP__PROP: internalSetTop((test.enumoptions.sharedgraph.TopLevel) value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(scope, out); + out.name(NESTED__PROP); + getNested().writeTo(out); + out.name(TOP__PROP); + getTop().writeTo(out); + } + + @Override + public void writeFieldValue(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonWriter out, String field) throws java.io.IOException { + switch (field) { + case NESTED__PROP: { + getNested().writeTo(out); + break; + } + case TOP__PROP: { + getTop().writeTo(out); + break; + } + default: super.writeFieldValue(scope, out, field); + } + } + + @Override + public void readField(de.haumacher.msgbuf.graph.Scope scope, de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NESTED__PROP: setNested(test.enumoptions.sharedgraph.M.Nested.readNested(in)); break; + case TOP__PROP: setTop(test.enumoptions.sharedgraph.TopLevel.readTopLevel(in)); break; + default: super.readField(scope, in, field); + } + } + + /** XML element name representing a {@link test.enumoptions.sharedgraph.M} type. */ + public static final String M__XML_ELEMENT = "m"; + + /** XML attribute or element name of a {@link #getNested} property. */ + private static final String NESTED__XML_ATTR = "nested"; + + /** XML attribute or element name of a {@link #getTop} property. */ + private static final String TOP__XML_ATTR = "top"; + + @Override + public String getXmlTagName() { + return M__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NESTED__XML_ATTR, getNested().protocolName()); + out.writeAttribute(TOP__XML_ATTR, getTop().protocolName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.enumoptions.sharedgraph.M} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static M_Impl readM_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + M_Impl result = new M_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NESTED__XML_ATTR: { + setNested(test.enumoptions.sharedgraph.M.Nested.valueOfProtocol(value)); + break; + } + case TOP__XML_ATTR: { + setTop(test.enumoptions.sharedgraph.TopLevel.valueOfProtocol(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NESTED__XML_ATTR: { + setNested(test.enumoptions.sharedgraph.M.Nested.valueOfProtocol(in.getElementText())); + break; + } + case TOP__XML_ATTR: { + setTop(test.enumoptions.sharedgraph.TopLevel.valueOfProtocol(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/formats/colors/colors.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/formats/colors/colors.proto new file mode 100644 index 00000000..4c34f3c9 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/formats/colors/colors.proto @@ -0,0 +1,13 @@ +package reject.formats.colors; + +option NoBinary; + +/** Shared enums of a file without binary serialization. */ +enum Color { + RED; + GREEN; +} + +message Shade { + string name; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/formats/graph/graph.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/formats/graph/graph.proto new file mode 100644 index 00000000..e48be389 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/formats/graph/graph.proto @@ -0,0 +1,10 @@ +package reject.formats.graph; +import "../colors/colors.proto"; + +option SharedGraph; + +/** A shared graph can use the enum, but not the message, of a file without SharedGraph. */ +message Node { + reject.formats.colors.Color color; + reject.formats.colors.Shade shade; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/formats/paint/paint-nobinary.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/formats/paint/paint-nobinary.proto new file mode 100644 index 00000000..2b1e606d --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/formats/paint/paint-nobinary.proto @@ -0,0 +1,10 @@ +package reject.formats.paint; +import "../colors/colors.proto"; + +option NoBinary; + +/** Uses the enum and message of a NoBinary file without binary serialization itself. */ +message PaintNoBinary { + reject.formats.colors.Color color; + reject.formats.colors.Shade shade; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/formats/paint/paint.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/formats/paint/paint.proto new file mode 100644 index 00000000..8675b337 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/formats/paint/paint.proto @@ -0,0 +1,14 @@ +package reject.formats.paint; +import "../colors/colors.proto"; + +/** Uses the enum of a NoBinary file, but generates binary serialization itself. */ +message Paint { + message Layer { + repeated reject.formats.colors.Color colors; + } + reject.formats.colors.Color color; + map shades; + + /** Not serialized in binary format, not a problem. */ + transient reject.formats.colors.Shade cached; +} From 05ca6ca5e1700901cb14da24436cc712dbb8579c Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 16:27:00 +0200 Subject: [PATCH 193/207] Stop writing transient and derived fields in XML format. The XML plugin wrote and read every field, while JSON and binary skip transient and derived fields. Transient values ended up in XML documents (#29, a bug by the maintainer's decision). For `@Container`, a contained object wrote its container, which wrote the object again, until the stack overflowed, so XML never worked for containment. The plugin now uses the same filter as the other formats in its writers, readers and field name constants. Readers of the default branches skip the attributes and elements of such fields in documents of earlier versions. `addFieldFormats()` follows, so a transient reference to a message of a NoXml file is accepted. Closes #29 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++ README.md | 9 ++-- .../generator/plugins/XmlStreamingPlugin.java | 32 ++++++++++++- .../java/test/container/TestContainer.java | 27 +++++++++++ .../container/model/impl/MyContent_Impl.java | 13 +---- .../nointerfaces/model/MyContent.java | 13 +---- .../test/references/data/impl/A_Impl.java | 46 ------------------ .../test/references/data/impl/B_Impl.java | 47 +------------------ .../transientprops/TestTransientProps.java | 41 ++++++++++++++++ .../test/transientprops/data/impl/A_Impl.java | 12 ----- .../test/transientprops/data/impl/B_Impl.java | 12 ----- .../test/transientprops/data/impl/C_Impl.java | 12 ----- 12 files changed, 111 insertions(+), 157 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d8e08c4..331b4c61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,10 @@ before, because enums always had all methods. It is now rejected with an error naming both files and the option, as are references to messages of such files and mixed `option SharedGraph` references, which generated uncompilable code before. The generator (CLI and Maven plugin) now stops without writing code when it finds such errors. +- **XML format: transient and derived fields** (#29): `transient` fields are no longer written in XML format, like in + JSON and binary format. **Wire format change:** XML documents no longer contain these attributes and elements; + readers ignore them in documents of earlier versions. The same applies to derived references (`@Container`, + `@Reverse`): writing an object whose container was set to XML recursed endlessly (`StackOverflowError`). ## 1.2.1 diff --git a/README.md b/README.md index 30daccc2..49648620 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,8 @@ message SearchResponse { ### Transient fields -Fields marked with `transient` are not serialized. They exist only in the in-memory representation: +Fields marked with `transient` are not serialized in any format (JSON, binary, XML). They exist only in the in-memory +representation. Readers ignore values of transient fields, e.g. in XML documents written by versions before 1.2.3: ```protobuf message A { @@ -210,7 +211,8 @@ other file. The generator rejects a reference to a definition generated without in that case. Either disable the format in the referencing file as well, or enable it in the referenced one. The same holds for `option SharedGraph`, which has its own JSON methods for messages: a message can reference messages of another file only if both files use `option SharedGraph`, or neither does. Enums are not affected by -`option SharedGraph`. `transient` fields are not written in JSON or binary format, so they don't need these formats. +`option SharedGraph`. `transient` fields and derived references (`@Container`, `@Reverse`) are not serialized, so they +don't need these formats. ### `option NoXmlNames` Disables generation of constants for the XML format. @@ -383,7 +385,8 @@ Sets a custom tag name for XML serialization. Marks a reference to be the reverse end of the reference with the given name in the target type. ### `@Container` -Marks a reference point to the container of the current object. +Marks a reference point to the container of the current object. The container reference is derived from the +containment and not serialized. ### `@Ref` Marks a reference as cross reference (non-composition). When setting values to fields marked as cross reference, container properties are not updated. diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java index 0a2d1068..a40b0999 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java @@ -56,12 +56,25 @@ public void addFormats(Map options, Set formats) { @Override public void addFieldFormats(Map options, Field field, Set formats) { - // All fields except maps are written and read, including transient ones. - if (!noXml(options) && field.getType().kind() != Type.TypeKind.MAP_TYPE) { + // Maps are not supported in XML. + if (!noXml(options) && xmlSerialized(field) && field.getType().kind() != Type.TypeKind.MAP_TYPE) { formats.add(XML_FORMAT); } } + /** + * Whether the given field is written and read in XML format. + * + *

+ * Like in JSON and binary format, transient and derived fields (container and reverse + * references) are not serialized. Readers skip such attributes and elements in documents of + * earlier versions. + *

+ */ + static boolean xmlSerialized(Field field) { + return !field.isTransient() && !field.isDerived(); + } + @Override public void addInterfaces(Map options, MessageDef def, List generalizations) { if (noXml(options)) { @@ -108,6 +121,9 @@ protected void generate() { line("public static final String " + xmlTypeNameConstant(def) + " = \"" + xmlTypeName(def) + "\";"); for (Field field : def.getFields()) { + if (!xmlSerialized(field)) { + continue; + } nl(); line("/** XML attribute or element name of a {@link #" + getterName(field) + "} property. */"); line("private static final String " + xmlFieldNameConstant(field) + " = \"" + xmlFieldName(field) + "\";"); @@ -145,6 +161,9 @@ protected void generate() { line("super.writeAttributes(out);"); } for (Field field : def.getFields()) { + if (!xmlSerialized(field)) { + continue; + } if (field.getType().kind() == Type.TypeKind.PRIMITIVE_TYPE || isEnum(field.getType())) { line("out.writeAttribute(" + xmlFieldNameConstant(field) + ", " + asString(field, CodeConvention.getterName(field) + "()") + ");"); } @@ -165,6 +184,9 @@ protected void generate() { boolean hasElementFields = false; for (Field field : def.getFields()) { + if (!xmlSerialized(field)) { + continue; + } Type type = field.getType(); switch (type.kind()) { case PRIMITIVE_TYPE: { @@ -290,6 +312,9 @@ protected void generate() { line("switch (name) {"); { for (Field field : def.getFields()) { + if (!xmlSerialized(field)) { + continue; + } if (field.getType().kind() == Type.TypeKind.PRIMITIVE_TYPE || isEnum(field.getType())) { line("case " + xmlFieldNameConstant(field) + ": {"); { @@ -328,6 +353,9 @@ protected void generate() { { Set names = new HashSet<>(); for (Field field : def.getFields()) { + if (!xmlSerialized(field)) { + continue; + } if (!names.add(xmlFieldName(field))) { System.err.println("ERROR: Ambiguous element name '" + xmlFieldName(field) + "' in type '" + def.getName() + "'."); continue; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java index b2b122b1..aecac4b4 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/TestContainer.java @@ -3,9 +3,15 @@ */ package test.container; +import java.io.StringReader; +import java.io.StringWriter; import java.util.Arrays; import java.util.Collections; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; + import junit.framework.TestCase; import test.container.model.MyContainer; import test.container.model.MyContent; @@ -189,4 +195,25 @@ public void testUpdateRef() { assertEquals(container, c.getContainer()); } + /** + * The container reference is derived and not written in XML format. Writing it made XML + * serialization recurse endlessly (issue #29). + */ + public void testXml() throws XMLStreamException { + MyContainer container = MyContainer.create().setName("c"); + container.setContent1(MyContent.create().setName("x")); + container.addContentList(MyContent.create().setName("y")); + + StringWriter buffer = new StringWriter(); + container.writeTo(XMLOutputFactory.newDefaultFactory().createXMLStreamWriter(buffer)); + String xml = buffer.toString(); + assertEquals("" + + "", xml); + + MyContainer copy = MyContainer.readMyContainer(XMLInputFactory.newFactory().createXMLStreamReader(new StringReader(xml))); + assertEquals("x", copy.getContent1().getName()); + assertSame(copy, copy.getContent1().getContainer()); + assertSame(copy, copy.getContentList().get(0).getContainer()); + } + } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java index b0fc6d0e..da7ba8e0 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/model/impl/MyContent_Impl.java @@ -198,9 +198,6 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML element name representing a {@link test.container.model.MyContent} type. */ public static final String MY_CONTENT__XML_ELEMENT = "my-content"; - /** XML attribute or element name of a {@link #getContainer} property. */ - private static final String CONTAINER__XML_ATTR = "container"; - /** XML attribute or element name of a {@link #getName} property. */ private static final String NAME__XML_ATTR = "name"; @@ -222,11 +219,7 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - if (hasContainer()) { - out.writeStartElement(CONTAINER__XML_ATTR); - getContainer().writeContent(out); - out.writeEndElement(); - } + // No element fields. } /** Creates a new {@link test.container.model.MyContent} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ @@ -272,10 +265,6 @@ protected void readFieldXmlAttribute(String name, String value) { /** Reads the element under the cursor and assigns its contents to the field with the given name. */ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { - case CONTAINER__XML_ATTR: { - setContainer(test.container.model.impl.MyContainer_Impl.readMyContainer_XmlContent(in)); - break; - } case NAME__XML_ATTR: { setName(in.getElementText()); break; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java index df8cbdb3..87dbce0e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/container/nointerfaces/model/MyContent.java @@ -231,9 +231,6 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML element name representing a {@link test.container.nointerfaces.model.MyContent} type. */ public static final String MY_CONTENT__XML_ELEMENT = "my-content"; - /** XML attribute or element name of a {@link #getContainer} property. */ - private static final String CONTAINER__XML_ATTR = "container"; - /** XML attribute or element name of a {@link #getName} property. */ private static final String NAME__XML_ATTR = "name"; @@ -255,11 +252,7 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - if (hasContainer()) { - out.writeStartElement(CONTAINER__XML_ATTR); - getContainer().writeContent(out); - out.writeEndElement(); - } + // No element fields. } /** Creates a new {@link test.container.nointerfaces.model.MyContent} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ @@ -305,10 +298,6 @@ protected void readFieldXmlAttribute(String name, String value) { /** Reads the element under the cursor and assigns its contents to the field with the given name. */ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { switch (localName) { - case CONTAINER__XML_ATTR: { - setContainer(test.container.nointerfaces.model.MyContainer.readMyContainer_XmlContent(in)); - break; - } case NAME__XML_ATTR: { setName(in.getElementText()); break; diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java index 8a76a6df..34762e70 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/A_Impl.java @@ -692,12 +692,6 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getOthers} property. */ private static final String OTHERS__XML_ATTR = "others"; - /** XML attribute or element name of a {@link #getInOther} property. */ - private static final String IN_OTHER__XML_ATTR = "in-other"; - - /** XML attribute or element name of a {@link #getInOthers} property. */ - private static final String IN_OTHERS__XML_ATTR = "in-others"; - @Override public String getXmlTagName() { return A__XML_ELEMENT; @@ -746,16 +740,6 @@ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax. element.writeTo(out); } out.writeEndElement(); - out.writeStartElement(IN_OTHER__XML_ATTR); - for (test.references.data.A element : getInOther()) { - element.writeTo(out); - } - out.writeEndElement(); - out.writeStartElement(IN_OTHERS__XML_ATTR); - for (test.references.data.A element : getInOthers()) { - element.writeTo(out); - } - out.writeEndElement(); } /** Creates a new {@link test.references.data.A} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ @@ -829,14 +813,6 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l internalReadOthersListXml(in); break; } - case IN_OTHER__XML_ATTR: { - internalReadInOtherListXml(in); - break; - } - case IN_OTHERS__XML_ATTR: { - internalReadInOthersListXml(in); - break; - } default: { internalSkipUntilMatchingEndElement(in); } @@ -886,26 +862,4 @@ private void internalReadOthersListXml(javax.xml.stream.XMLStreamReader in) thro } } - private void internalReadInOtherListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - while (true) { - int event = in.nextTag(); - if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { - break; - } - - addInOther(test.references.data.impl.A_Impl.readA_XmlContent(in)); - } - } - - private void internalReadInOthersListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - while (true) { - int event = in.nextTag(); - if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { - break; - } - - addInOthers(test.references.data.impl.A_Impl.readA_XmlContent(in)); - } - } - } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java index f196d9fd..aedc5913 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/references/data/impl/B_Impl.java @@ -275,12 +275,6 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getName} property. */ private static final String NAME__XML_ATTR = "name"; - /** XML attribute or element name of a {@link #getInBs} property. */ - private static final String IN_BS__XML_ATTR = "in-bs"; - - /** XML attribute or element name of a {@link #getInB} property. */ - private static final String IN_B__XML_ATTR = "in-b"; - @Override public String getXmlTagName() { return B__XML_ELEMENT; @@ -299,16 +293,7 @@ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML elements. */ protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { - out.writeStartElement(IN_BS__XML_ATTR); - for (test.references.data.A element : getInBs()) { - element.writeTo(out); - } - out.writeEndElement(); - out.writeStartElement(IN_B__XML_ATTR); - for (test.references.data.A element : getInB()) { - element.writeTo(out); - } - out.writeEndElement(); + // No element fields. } /** Creates a new {@link test.references.data.B} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ @@ -358,14 +343,6 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l setName(in.getElementText()); break; } - case IN_BS__XML_ATTR: { - internalReadInBsListXml(in); - break; - } - case IN_B__XML_ATTR: { - internalReadInBListXml(in); - break; - } default: { internalSkipUntilMatchingEndElement(in); } @@ -382,26 +359,4 @@ protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream } } - private void internalReadInBsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - while (true) { - int event = in.nextTag(); - if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { - break; - } - - addInBs(test.references.data.impl.A_Impl.readA_XmlContent(in)); - } - } - - private void internalReadInBListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { - while (true) { - int event = in.nextTag(); - if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { - break; - } - - addInB(test.references.data.impl.A_Impl.readA_XmlContent(in)); - } - } - } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/TestTransientProps.java b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/TestTransientProps.java index 88284748..5f7465f3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/TestTransientProps.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/TestTransientProps.java @@ -5,10 +5,16 @@ */ package test.transientprops; +import java.io.StringReader; +import java.io.StringWriter; import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; + import junit.framework.TestCase; import test.transientprops.data.A; import test.transientprops.data.B; @@ -34,6 +40,41 @@ public void testC() { assertEquals(Arrays.asList(A.X_1__PROP, A.X_2__PROP, B.Y_1__PROP, B.Y_2__PROP, C.Z_1__PROP, C.Z_2__PROP), C.create().properties()); } + /** Transient properties are not written in XML format (issue #29). */ + public void testXml() throws XMLStreamException { + C value = C.create().setX1("a").setX2("t").setY1("b").setY2("tt").setZ1("c").setZ2("ttt"); + String xml = xml(value); + assertEquals("", xml); + + C copy = C.readC(xmlReader(xml)); + assertEquals("a", copy.getX1()); + assertEquals("b", copy.getY1()); + assertEquals("c", copy.getZ1()); + assertEquals("", copy.getX2()); + assertEquals("", copy.getZ2()); + } + + /** Documents of earlier versions that contain transient properties can still be read. */ + public void testXmlReadLegacy() throws XMLStreamException { + C copy = C.readC(xmlReader("")); + assertEquals("a", copy.getX1()); + assertEquals("b", copy.getY1()); + assertEquals("c", copy.getZ1()); + assertEquals("", copy.getX2()); + assertEquals("", copy.getY2()); + assertEquals("", copy.getZ2()); + } + + private static String xml(C value) throws XMLStreamException { + StringWriter buffer = new StringWriter(); + value.writeTo(XMLOutputFactory.newDefaultFactory().createXMLStreamWriter(buffer)); + return buffer.toString(); + } + + private static javax.xml.stream.XMLStreamReader xmlReader(String xml) throws XMLStreamException { + return XMLInputFactory.newFactory().createXMLStreamReader(new StringReader(xml)); + } + private Set set(String ...s) { return new HashSet<>(Arrays.asList(s)); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/A_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/A_Impl.java index 00ec7a92..4f7d6797 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/A_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/A_Impl.java @@ -197,9 +197,6 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getX1} property. */ private static final String X_1__XML_ATTR = "x-1"; - /** XML attribute or element name of a {@link #getX2} property. */ - private static final String X_2__XML_ATTR = "x-2"; - @Override public String getXmlTagName() { return A__XML_ELEMENT; @@ -214,7 +211,6 @@ public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws java /** Serializes all fields that are written as XML attributes. */ protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { out.writeAttribute(X_1__XML_ATTR, getX1()); - out.writeAttribute(X_2__XML_ATTR, getX2()); } /** Serializes all fields that are written as XML elements. */ @@ -256,10 +252,6 @@ protected void readFieldXmlAttribute(String name, String value) { setX1(value); break; } - case X_2__XML_ATTR: { - setX2(value); - break; - } default: { // Skip unknown attribute. } @@ -273,10 +265,6 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l setX1(in.getElementText()); break; } - case X_2__XML_ATTR: { - setX2(in.getElementText()); - break; - } default: { internalSkipUntilMatchingEndElement(in); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/B_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/B_Impl.java index 89f9a5a8..313c5822 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/B_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/B_Impl.java @@ -169,9 +169,6 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getY1} property. */ private static final String Y_1__XML_ATTR = "y-1"; - /** XML attribute or element name of a {@link #getY2} property. */ - private static final String Y_2__XML_ATTR = "y-2"; - @Override public String getXmlTagName() { return B__XML_ELEMENT; @@ -182,7 +179,6 @@ public String getXmlTagName() { protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeAttributes(out); out.writeAttribute(Y_1__XML_ATTR, getY1()); - out.writeAttribute(Y_2__XML_ATTR, getY2()); } /** Serializes all fields that are written as XML elements. */ @@ -206,10 +202,6 @@ protected void readFieldXmlAttribute(String name, String value) { setY1(value); break; } - case Y_2__XML_ATTR: { - setY2(value); - break; - } default: { super.readFieldXmlAttribute(name, value); } @@ -223,10 +215,6 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l setY1(in.getElementText()); break; } - case Y_2__XML_ATTR: { - setY2(in.getElementText()); - break; - } default: { super.readFieldXmlElement(in, localName); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/C_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/C_Impl.java index bc857802..281119c5 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/C_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/transientprops/data/impl/C_Impl.java @@ -181,9 +181,6 @@ protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) th /** XML attribute or element name of a {@link #getZ1} property. */ private static final String Z_1__XML_ATTR = "z-1"; - /** XML attribute or element name of a {@link #getZ2} property. */ - private static final String Z_2__XML_ATTR = "z-2"; - @Override public String getXmlTagName() { return C__XML_ELEMENT; @@ -194,7 +191,6 @@ public String getXmlTagName() { protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { super.writeAttributes(out); out.writeAttribute(Z_1__XML_ATTR, getZ1()); - out.writeAttribute(Z_2__XML_ATTR, getZ2()); } /** Serializes all fields that are written as XML elements. */ @@ -218,10 +214,6 @@ protected void readFieldXmlAttribute(String name, String value) { setZ1(value); break; } - case Z_2__XML_ATTR: { - setZ2(value); - break; - } default: { super.readFieldXmlAttribute(name, value); } @@ -235,10 +227,6 @@ protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String l setZ1(in.getElementText()); break; } - case Z_2__XML_ATTR: { - setZ2(in.getElementText()); - break; - } default: { super.readFieldXmlElement(in, localName); } From f61ff0ed0e5923caa7415185fdb06aaa84780d44 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 16:30:07 +0200 Subject: [PATCH 194/207] Reject fields that redeclare inherited fields or clash in their generated names. A sub-message could redeclare a field of a generalization, e.g. to narrow its type. The generator accepted it silently and produced Java that did not compile: two getters with incompatible return types and ambiguous property constants (#21). As decided by the maintainer, redeclaration is not supported. It is rejected before any code is written, like the format references of #20, with an error that names the field and the message and file declaring the other one. The check compares the generated names (accessor suffix and property constant), so it also covers duplicate fields in one message and different names that generate the same Java names, like `foo_bar` and `fooBar`. It follows `extends` across files and guards against cycles. The rejection tests move to `test.validation`. Closes #21 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 + README.md | 5 + .../haumacher/msgbuf/generator/Generator.java | 97 +++++++++++++++++++ .../java/test/validation/TestFieldNames.java | 75 ++++++++++++++ .../TestFormatReferences.java | 2 +- .../test/resources/reject/fields/base.proto | 7 ++ .../resources/reject/fields/extension.proto | 6 ++ .../resources/reject/fields/hierarchy.proto | 37 +++++++ .../resources/reject/fields/redeclare.proto | 9 ++ 9 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/validation/TestFieldNames.java rename de.haumacher.msgbuf.generator/src/test/java/test/{enumoptions => validation}/TestFormatReferences.java (99%) create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/fields/base.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/fields/extension.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/fields/hierarchy.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/fields/redeclare.proto diff --git a/CHANGELOG.md b/CHANGELOG.md index 331b4c61..f9354651 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,9 @@ JSON and binary format. **Wire format change:** XML documents no longer contain these attributes and elements; readers ignore them in documents of earlier versions. The same applies to derived references (`@Container`, `@Reverse`): writing an object whose container was set to XML recursed endlessly (`StackOverflowError`). +- **Redeclared fields** (#21): A field that redeclares an inherited field (directly or through any generalization, + also across files), a field declared twice, and fields whose names generate the same Java names (e.g. `foo_bar` and + `fooBar`) are rejected with an error. Before, the generator silently produced Java code that did not compile. ## 1.2.1 diff --git a/README.md b/README.md index 49648620..7f044439 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,11 @@ message Group extends Shape { Passing these definitions to the `msgbuf` compiler gives you a class hierarchy with classes `Shape`, `Circle`, `Rectangle`, and `Group`. You can inspect the generation result in the test package [test.hierarchy](https://github.com/msgbuf/msgbuf/tree/main/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data) of the compiler. The source of the example data class definitions can be seen in the [hierarchy.proto](https://github.com/msgbuf/msgbuf/tree/main/de.haumacher.msgbuf.generator/src/test/java/test/hierarchy/data/hierarchy.proto) file. +A sub-message inherits all fields of its generalizations and cannot redeclare them, not even to narrow the type. The +names of all fields of a message, including the inherited ones, must also generate distinct Java names: `foo_bar` +and `fooBar` both generate `getFooBar()`. The generator rejects such definitions with an error naming the field and +the message declaring the other one. + ### Enum types Enums define a fixed set of named constants. Each constant is terminated with a semicolon. Constants can optionally diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java index 38565465..25ca5868 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java @@ -14,6 +14,7 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -186,6 +187,7 @@ public void generate(GeneratorPlugin plugin) { List errors = new ArrayList<>(); for (DefinitionFile file : _files) { if (!_importedFiles.contains(file)) { + validateFieldNames(file, errors); validateFormatReferences(file, plugin, errors); } } @@ -348,6 +350,101 @@ private static boolean extendsOpenWorldFromOtherFile(DefinitionFile file, List + * A sub-message cannot redeclare an inherited field (not even to narrow its type), since the + * generated accessors and property constants of both declarations would clash. + *

+ */ + private void validateFieldNames(DefinitionFile file, List errors) { + for (Definition def : file.getDefinitions()) { + validateFieldNames(def, errors); + } + } + + private void validateFieldNames(Definition def, List errors) { + if (!(def instanceof MessageDef)) { + return; + } + MessageDef message = (MessageDef) def; + + // Generated names of the inherited fields, most general first. + Map inherited = new HashMap<>(); + Map owners = new HashMap<>(); + List generalizations = new ArrayList<>(); + Set seen = new HashSet<>(); + seen.add(message); + for (MessageDef current = message.getExtendedDef(); current != null && seen.add(current); current = current.getExtendedDef()) { + generalizations.add(0, current); + } + for (MessageDef generalization : generalizations) { + for (Field field : generalization.getFields()) { + owners.put(field, generalization); + for (String name : generatedNames(field)) { + inherited.putIfAbsent(name, field); + } + } + } + + Map local = new HashMap<>(); + for (Field field : message.getFields()) { + Field clash = null; + for (String name : generatedNames(field)) { + clash = local.get(name); + if (clash != null) { + break; + } + } + if (clash != null) { + errors.add(fieldError(message, field) + (clash.getName().equals(field.getName()) + ? " is declared twice. Rename or remove one of the declarations." + : " clashes with field '" + clash.getName() + "' of the same message: both generate the same Java names ('" + + CodeConvention.getterName(field) + "()', '" + CodeConvention.constant(field) + + "'). Rename one of the fields.")); + } else { + for (String name : generatedNames(field)) { + clash = inherited.get(name); + if (clash != null) { + break; + } + } + if (clash != null) { + MessageDef owner = owners.get(clash); + String origin = "'" + Util.toString(owner) + "' of '" + sourceDescription(Util.definingFile(owner)) + "'"; + errors.add(fieldError(message, field) + (clash.getName().equals(field.getName()) + ? " redeclares the field inherited from " + origin + + ". A sub-message cannot redeclare an inherited field (not even to narrow its type)." + + " Remove the declaration or rename the field." + : " clashes with field '" + clash.getName() + "' inherited from " + origin + + ": both generate the same Java names ('" + CodeConvention.getterName(field) + "()', '" + + CodeConvention.constant(field) + "'). Rename the field.")); + } + } + for (String name : generatedNames(field)) { + local.putIfAbsent(name, field); + } + } + + for (Definition inner : message.getDefinitions()) { + validateFieldNames(inner, errors); + } + } + + private String fieldError(MessageDef message, Field field) { + return sourceDescription(Util.definingFile(message)) + ": Field '" + Util.toString(message) + "." + field.getName() + "'"; + } + + /** + * The names derived from a field that must be unique among all fields of a message and its + * generalizations. + */ + private static List generatedNames(Field field) { + return Arrays.asList("suffix:" + CodeConvention.suffix(field), "constant:" + CodeConvention.constant(field)); + } + /** * Rejects references to definitions of other files that are generated without a serialization * format that the referencing code needs. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/validation/TestFieldNames.java b/de.haumacher.msgbuf.generator/src/test/java/test/validation/TestFieldNames.java new file mode 100644 index 00000000..a5da8a35 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/validation/TestFieldNames.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2026 Bernhard Haumacher et al. All Rights Reserved. + */ +package test.validation; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.List; + +import de.haumacher.msgbuf.generator.Generator; +import de.haumacher.msgbuf.generator.GeneratorException; +import de.haumacher.msgbuf.generator.parser.ParseException; +import de.haumacher.msgbuf.generator.plugins.XmlStreamingPlugin; +import junit.framework.TestCase; + +/** + * Test case for rejecting fields that redeclare inherited fields or whose generated names clash + * (issue #21). + */ +@SuppressWarnings("javadoc") +public class TestFieldNames extends TestCase { + + private static final File FIXTURES = new File("src/test/resources/reject/fields"); + + /** The definition from the issue report. */ + public void testRedeclare() throws IOException, ParseException { + assertEquals(Arrays.asList( + "test/redeclare/redeclare.proto: Field 'test.redeclare.B.value' redeclares the field inherited from" + + " 'test.redeclare.A' of 'test/redeclare/redeclare.proto'. A sub-message cannot redeclare an inherited" + + " field (not even to narrow its type). Remove the declaration or rename the field."), + reject("redeclare.proto")); + } + + public void testHierarchy() throws IOException, ParseException { + assertEquals(Arrays.asList( + "reject/fields/hierarchy.proto: Field 'reject.fields.Outer.label' is declared twice. Rename or remove one of" + + " the declarations.", + "reject/fields/hierarchy.proto: Field 'reject.fields.Outer.Leaf.name' redeclares the field inherited from" + + " 'reject.fields.Root' of 'reject/fields/hierarchy.proto'. A sub-message cannot redeclare an inherited" + + " field (not even to narrow its type). Remove the declaration or rename the field.", + "reject/fields/hierarchy.proto: Field 'reject.fields.Outer.Other.foo_bar' clashes with field 'fooBar'" + + " inherited from 'reject.fields.Root' of 'reject/fields/hierarchy.proto': both generate the same Java" + + " names ('getFooBar()', 'FOO_BAR__PROP'). Rename the field."), + reject("hierarchy.proto")); + } + + public void testCrossFile() throws IOException, ParseException { + assertEquals(Arrays.asList( + "reject/fields/ext/extension.proto: Field 'reject.fields.ext.Ping.source' redeclares the field inherited" + + " from 'reject.fields.Event' of 'reject/fields/base.proto'. A sub-message cannot redeclare an" + + " inherited field (not even to narrow its type). Remove the declaration or rename the field."), + reject("extension.proto")); + } + + private List reject(String proto) throws IOException, ParseException { + File target = new File("target"); + target.mkdirs(); + File out = Files.createTempDirectory(target.toPath(), getName()).toFile(); + Generator generator = new Generator(); + generator.setOut(out); + generator.load(new File(FIXTURES, proto)); + try { + generator.generate(new XmlStreamingPlugin()); + fail("Expected rejection of '" + proto + "'."); + return null; + } catch (GeneratorException ex) { + String[] written = out.list(); + assertTrue("No code must be generated for rejected definitions.", written == null || written.length == 0); + return ex.getErrors(); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/TestFormatReferences.java b/de.haumacher.msgbuf.generator/src/test/java/test/validation/TestFormatReferences.java similarity index 99% rename from de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/TestFormatReferences.java rename to de.haumacher.msgbuf.generator/src/test/java/test/validation/TestFormatReferences.java index a79b9e01..4d2ef7bb 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/enumoptions/TestFormatReferences.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/validation/TestFormatReferences.java @@ -1,7 +1,7 @@ /* * Copyright (c) 2026 Bernhard Haumacher et al. All Rights Reserved. */ -package test.enumoptions; +package test.validation; import java.io.File; import java.io.IOException; diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/fields/base.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/fields/base.proto new file mode 100644 index 00000000..6f337e39 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/fields/base.proto @@ -0,0 +1,7 @@ +package reject.fields; + +option OpenWorld; + +abstract message Event { + string source; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/fields/extension.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/fields/extension.proto new file mode 100644 index 00000000..e00914cd --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/fields/extension.proto @@ -0,0 +1,6 @@ +package reject.fields.ext; +import "base.proto"; + +message Ping extends reject.fields.Event { + string source; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/fields/hierarchy.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/fields/hierarchy.proto new file mode 100644 index 00000000..1b52d966 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/fields/hierarchy.proto @@ -0,0 +1,37 @@ +package reject.fields; + +/** Redeclarations through an abstract intermediate, in nested messages, and clashing generated names. */ +abstract message Root { + string name; + int fooBar; +} + +abstract message Middle extends Root { + int weight; +} + +message Outer { + message Leaf extends Middle { + string name; + } + + message Other extends Root { + string foo_bar; + } + + string label; + int label; +} + +/** Siblings may declare the same field, and nested messages may reuse names of their outer message. */ +message Sibling1 extends Middle { + string extra; +} + +message Sibling2 extends Middle { + int extra; + + message Inner { + int extra; + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/fields/redeclare.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/fields/redeclare.proto new file mode 100644 index 00000000..f569042f --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/fields/redeclare.proto @@ -0,0 +1,9 @@ +package test.redeclare; + +message A { + json value; +} + +message B extends A { + string value; +} From 73fa1e8e988006bba7f4dda1f72f817ff0a7b56e Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 16:34:38 +0200 Subject: [PATCH 195/207] Accept the documented names of the Maven plugin parameters and make the plugin IT real. The Mojo fields are named `_outputDirectory`, `_input`, `_includePaths` and `_resourceOutputDirectory`, and Maven uses the field name as the configuration name unless an alias is declared. Only the user properties worked, and the README's `` was silently ignored (#17). The parameters now have aliases with their natural names, like `typeScriptOutputDirectory` already had, and the README lists all parameters. The integration test was the archetype template calling a non-existent `touch` goal (#18). It is now a consumer project that configures every parameter by its documented name, resolves an import through `includePaths`, generates an OpenWorld extension with its service descriptor, and compiles the result. The plugin testing harness does not resolve aliases, so the names can only be tested there. The IT fails when one alias is removed. Closes #17 Closes #18 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 5 ++ README.md | 17 ++++++- .../src/it/simple-it/pom.xml | 48 +++++++++++++++++-- .../simple-it/src/main/proto/base/base.proto | 7 +++ .../it/simple-it/src/main/proto/ext/ext.proto | 6 +++ .../src/it/simple-it/verify.groovy | 18 ++++++- .../maven/GenerateMessageClasses.java | 8 ++-- 7 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 msgbuf-generator-maven-plugin/src/it/simple-it/src/main/proto/base/base.proto create mode 100644 msgbuf-generator-maven-plugin/src/it/simple-it/src/main/proto/ext/ext.proto diff --git a/CHANGELOG.md b/CHANGELOG.md index 236509e0..77fff8dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ - **File documentation comment**: A doc comment before the `syntax` or `package` declaration is kept as the documentation of the `.proto` file (`DefinitionFile.comment`) and emitted as TSDoc `@packageDocumentation` of the TypeScript module. +### Bug Fixes +- **Maven plugin parameter names** (#17): The parameters `input`, `outputDirectory`, `resourceOutputDirectory` and + `includePaths` can be set under these names in the plugin ``. Before, only the user properties + (`-DoutputDir=…`) worked, and the README's `` was silently ignored. + ## 1.2.1 ### Bug Fixes diff --git a/README.md b/README.md index fe703035..c57c7dd1 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,21 @@ Now you are ready to create `*.proto` files in your source folder and build them Proto files are placed in your Java source folder (`src/main/java/`) inside the directory matching their `package` declaration. The generated Java files are written next to the proto file. For example, a proto file with `package my.app.model;` should be placed at `src/main/java/my/app/model/shape.proto`, and the generated classes will appear in `src/main/java/my/app/model/`. +### Plugin parameters + +All parameters are optional. Set them in the `` of the plugin (or its execution), or with the user +property on the command line (`-D=...`): + +| Parameter | User property | Default | Description | +|---|---|---|---| +| `input` | `input` | `${project.build.sourceDirectory}` | Directory searched for `.proto` files (or a single `.proto` file). | +| `outputDirectory` | `outputDir` | `${project.build.sourceDirectory}` | Directory the Java sources are generated to. | +| `resourceOutputDirectory` | `resourceOutputDir` | `${project.basedir}/src/main/resources` | Directory resource files (`META-INF/services`) are generated to. | +| `typeScriptOutputDirectory` | `typeScriptOutputDir` | none | Directory TypeScript types are generated to (see [TypeScript](#typescript-type-definitions)). | +| `includePaths` | `includePaths` | none | Additional directories searched for imported `.proto` files. | + +If `outputDirectory` is not a source folder of the project, add it as one (e.g. with the `build-helper-maven-plugin`). + ## Usage The `msgbuf` definition language is an extension of the [proto format](https://developers.google.com/protocol-buffers/docs/proto3) from `protobuf`. A defined message can `extend` another message type, or it can be marked `abstract`. @@ -291,7 +306,7 @@ Implications: Maven plugin configuration (extension module): ```xml - ${project.basedir}/src/main/resources + ${project.basedir}/src/main/resources ``` diff --git a/msgbuf-generator-maven-plugin/src/it/simple-it/pom.xml b/msgbuf-generator-maven-plugin/src/it/simple-it/pom.xml index 4e81df15..b257e6ac 100644 --- a/msgbuf-generator-maven-plugin/src/it/simple-it/pom.xml +++ b/msgbuf-generator-maven-plugin/src/it/simple-it/pom.xml @@ -7,12 +7,25 @@ simple-it 1.0-SNAPSHOT - A simple IT verifying the basic use case. + + Generates and compiles data classes in a consumer project, configuring the plugin with the parameter names + documented in the README. + UTF-8 + 11 + 11 + + + de.haumacher.msgbuf + msgbuf-api + @project.version@ + + + @@ -21,11 +34,38 @@ @project.version@ - touch - validate - touch + generate + + + ${project.basedir}/src/main/proto + + ${project.basedir}/src/main/proto + + ${project.build.directory}/generated-sources/msgbuf + ${project.build.directory}/generated-resources/msgbuf + ${project.build.directory}/generated-ts + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.6.0 + + + add-generated-sources + generate-sources + + add-source + + + ${project.build.directory}/generated-sources/msgbuf + + diff --git a/msgbuf-generator-maven-plugin/src/it/simple-it/src/main/proto/base/base.proto b/msgbuf-generator-maven-plugin/src/it/simple-it/src/main/proto/base/base.proto new file mode 100644 index 00000000..edf5aee1 --- /dev/null +++ b/msgbuf-generator-maven-plugin/src/it/simple-it/src/main/proto/base/base.proto @@ -0,0 +1,7 @@ +package it.base; + +option OpenWorld; + +abstract message Event { + string source; +} diff --git a/msgbuf-generator-maven-plugin/src/it/simple-it/src/main/proto/ext/ext.proto b/msgbuf-generator-maven-plugin/src/it/simple-it/src/main/proto/ext/ext.proto new file mode 100644 index 00000000..c595f0ab --- /dev/null +++ b/msgbuf-generator-maven-plugin/src/it/simple-it/src/main/proto/ext/ext.proto @@ -0,0 +1,6 @@ +package it.ext; +import "base/base.proto"; + +message Ping extends it.base.Event { + int count; +} diff --git a/msgbuf-generator-maven-plugin/src/it/simple-it/verify.groovy b/msgbuf-generator-maven-plugin/src/it/simple-it/verify.groovy index 7b307c78..05b591a1 100644 --- a/msgbuf-generator-maven-plugin/src/it/simple-it/verify.groovy +++ b/msgbuf-generator-maven-plugin/src/it/simple-it/verify.groovy @@ -1,3 +1,17 @@ -File touchFile = new File( basedir, "target/touch.txt" ); +// Generated to the configured directories (outputDirectory, resourceOutputDirectory, typeScriptOutputDirectory). +File java = new File(basedir, "target/generated-sources/msgbuf/it/ext/Ping.java") +assert java.isFile() : "Missing " + java -assert touchFile.isFile() +File services = new File(basedir, "target/generated-resources/msgbuf/META-INF/services/de.haumacher.msgbuf.data.TypeRegistration") +assert services.isFile() : "Missing " + services +assert services.text.contains("it.ext.ExtTypes") + +File ts = new File(basedir, "target/generated-ts/it/ext/ext.ts") +assert ts.isFile() : "Missing " + ts + +// Nothing generated to the default locations. +assert !new File(basedir, "src/main/java").exists() +assert !new File(basedir, "src/main/resources").exists() + +// The generated sources were compiled. +assert new File(basedir, "target/classes/it/ext/impl/Ping_Impl.class").isFile() diff --git a/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java b/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java index 544bcf1e..6754ac8f 100644 --- a/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java +++ b/msgbuf-generator-maven-plugin/src/main/java/de/haumacher/msgbuf/generator/maven/GenerateMessageClasses.java @@ -32,25 +32,25 @@ public class GenerateMessageClasses extends AbstractMojo { /** * Directory where to generate source code to. */ - @Parameter(defaultValue = "${project.build.sourceDirectory}", property = "outputDir", required = true) + @Parameter(alias = "outputDirectory", defaultValue = "${project.build.sourceDirectory}", property = "outputDir", required = true) private File _outputDirectory; /** * Input where to search for *.proto files. */ - @Parameter(defaultValue = "${project.build.sourceDirectory}", property = "input", required = true) + @Parameter(alias = "input", defaultValue = "${project.build.sourceDirectory}", property = "input", required = true) private File _input; /** * Additional directories to search for imported .proto files. */ - @Parameter(property = "includePaths") + @Parameter(alias = "includePaths", property = "includePaths") private List _includePaths; /** * Directory where to generate resource files (e.g. META-INF/services). */ - @Parameter(defaultValue = "${project.basedir}/src/main/resources", property = "resourceOutputDir") + @Parameter(alias = "resourceOutputDirectory", defaultValue = "${project.basedir}/src/main/resources", property = "resourceOutputDir") private File _resourceOutputDirectory; /** From a9a0f5e2199ebed5ba090ff14d87b8e709743f96 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 16:34:38 +0200 Subject: [PATCH 196/207] Remove the stale msgbuf-parent/ copy of the parent POM. msgbuf-parent/pom.xml was an outdated copy (1.0.3-SNAPSHOT) of the parent POM. The real parent is the root pom.xml. No module references it and the build never reads it, but it invited edits that have no effect (#19). Closes #19 Co-Authored-By: Claude Opus 5.5 --- msgbuf-parent/.gitignore | 1 - msgbuf-parent/.project | 17 -- .../.settings/org.eclipse.m2e.core.prefs | 4 - msgbuf-parent/pom.xml | 167 ------------------ 4 files changed, 189 deletions(-) delete mode 100644 msgbuf-parent/.gitignore delete mode 100644 msgbuf-parent/.project delete mode 100644 msgbuf-parent/.settings/org.eclipse.m2e.core.prefs delete mode 100644 msgbuf-parent/pom.xml diff --git a/msgbuf-parent/.gitignore b/msgbuf-parent/.gitignore deleted file mode 100644 index b83d2226..00000000 --- a/msgbuf-parent/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target/ diff --git a/msgbuf-parent/.project b/msgbuf-parent/.project deleted file mode 100644 index 892785de..00000000 --- a/msgbuf-parent/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - msgbuf-parent - - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.m2e.core.maven2Nature - - diff --git a/msgbuf-parent/.settings/org.eclipse.m2e.core.prefs b/msgbuf-parent/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index f897a7f1..00000000 --- a/msgbuf-parent/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/msgbuf-parent/pom.xml b/msgbuf-parent/pom.xml deleted file mode 100644 index d655569d..00000000 --- a/msgbuf-parent/pom.xml +++ /dev/null @@ -1,167 +0,0 @@ - - 4.0.0 - - de.haumacher.msgbuf - msgbuf-parent - 1.0.3-SNAPSHOT - - pom - - - https://github.com/msgbuf/msgbuf - scm:git:https://github.com/msgbuf/msgbuf.git - scm:git:https://github.com/msgbuf/msgbuf.git - HEAD - - - - - ossrh - https://s01.oss.sonatype.org/content/repositories/snapshots - - - - - 11 - 11 - utf-8 - 3.3.9 - - - - - - - - maven-clean-plugin - 3.1.0 - - - maven-resources-plugin - 3.2.0 - - - maven-compiler-plugin - 3.10.1 - - - maven-plugin-plugin - 3.6.4 - - - maven-surefire-plugin - 2.22.1 - - - maven-jar-plugin - 3.0.2 - - - maven-install-plugin - 2.5.2 - - - maven-deploy-plugin - 2.8.2 - - - maven-invoker-plugin - 3.1.0 - - - - - - - - maven-compiler-plugin - - 11 - 11 - UTF-8 - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.3.1 - - UTF-8 - -missing - - - - attach-javadocs - - jar - - - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - ${gpg.keyname} - - - - sign-artifacts - verify - - sign - - - - - - - org.apache.maven.plugins - maven-release-plugin - 2.5.3 - - true - false - ossrh - deploy - msgbuf-api-@{project.version} - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 - true - - ossrh - https://s01.oss.sonatype.org/ - false - - - - - \ No newline at end of file From 7091690ec907ac59542f03bc1ecab28b93cb7d4a Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 16:34:38 +0200 Subject: [PATCH 197/207] Document that the AST and the generated test sources are regenerated by hand. CLAUDE.md and the cross-file extension spec claimed that the Maven reactor regenerates the AST classes after a change to proto.proto. It does not: the generator pom only runs JavaCC and the shade plugin (#23). The docs now give the command (and the Eclipse launch configuration) for the AST and for the checked-in test sources. The workflow skill drops its notes on the fixed integration test (#18). A check that detects a forgotten regeneration, option 3 of #23, is left as an enhancement. Closes #23 Co-Authored-By: Claude Opus 5.5 --- .claude/skills/msgbuf-workflow/SKILL.md | 12 ++++++------ CLAUDE.md | 2 +- ...026-03-24-cross-file-protocol-extension-design.md | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.claude/skills/msgbuf-workflow/SKILL.md b/.claude/skills/msgbuf-workflow/SKILL.md index fbe92bfd..b703c149 100644 --- a/.claude/skills/msgbuf-workflow/SKILL.md +++ b/.claude/skills/msgbuf-workflow/SKILL.md @@ -132,9 +132,10 @@ general?" not "does the happy path work?". Keep passing probes as permanent test is installed — use `-am`, and then `-Dsurefire.failIfNoSpecifiedTests=false` with `-Dtest=…`. - **Stale jar**: `target/msgbuf-generator-*-full.jar` is whatever the last `install`/`package` built, possibly on another branch. Rebuild before probing a change. -- **A green unit build does not cover the plugin integration test**: `-Prun-its` runs it, and - `simple-it` is the archetype template calling a non-existent `touch` goal (#18) — it fails on - `main` too. Report it as known, don't chase it. +- **A green unit build does not cover the plugin integration test**: `-Prun-its` runs `simple-it`, + a consumer project that configures the plugin with the documented parameter names, generates and + compiles. The plugin testing harness (`MojoRule.lookupConfiguredMojo`) does not resolve parameter + aliases, so configuration names can only be tested there. - **CLAUDE.md is not always right about the wire format**: polymorphic values are written as `[typeId, {fields}]` (a two-element array whose second element is the object), and only when the hierarchy root is abstract; references to a concrete type use `writeContent()` without a tag. @@ -175,7 +176,7 @@ cd .. && mvn clean install # the regenerated sources compile and pa generated code: an unexplained change is a regression. - **AST change** (`ast/proto.proto`): regenerate the AST classes with the previous generator (`java -jar $J -out src/main/java src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto`), - then rebuild. The build does not do this for you (#23; CLAUDE.md still claims otherwise). + then rebuild. The build does not do this for you. - **Grammar change** (`parser/protobuf.jj`, next to the parser sources): the JavaCC plugin regenerates the parser into `src/main/java` during the build; the regenerated parser files are checked in and ride the same commit. @@ -184,8 +185,7 @@ cd .. && mvn clean install # the regenerated sources compile and pa rerun without the flag. Type-check the golden files plus a usage file with `@ts-expect-error` negative cases in the scratchpad: `npx -y -p typescript tsc --strict --noEmit --isolatedModules --verbatimModuleSyntax --moduleResolution bundler --module esnext --target es2020 `. -- **Maven plugin changes**: also run `mvn install -Prun-its -pl msgbuf-generator-maven-plugin` - (known failure #18 until fixed). +- **Maven plugin changes**: also run `mvn install -Prun-its -pl msgbuf-generator-maven-plugin`. - The Eclipse plugin (`de.haumacher.msgbuf.eclipse`, `de.haumacher.msgbuf.feature`) is not in the reactor; changes there need a separate Eclipse/PDE build and are rare. diff --git a/CLAUDE.md b/CLAUDE.md index 6b2ade22..4600bed1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -83,7 +83,7 @@ Extensions beyond standard protobuf: ## Key Gotchas -- **Self-bootstrapping**: Changes to `generator/ast/proto.proto` require regenerating the AST Java classes with an existing generator, then rebuilding. Maven reactor handles this automatically. +- **Self-bootstrapping**: Changes to `generator/ast/proto.proto` require regenerating the AST Java classes with an existing generator, then rebuilding. The build does **not** do this: run `java -jar de.haumacher.msgbuf.generator/target/msgbuf-generator-*-full.jar -out de.haumacher.msgbuf.generator/src/main/java de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ast/proto.proto` (or the Eclipse launch config `de.haumacher.msgbuf.generator/bin/Generate Compiler AST.launch`). Likewise, the checked-in generated test sources under `src/test/java/test/**` are regenerated by hand (`-out src/test/java` for each `.proto`). - **NoInterfaces mode**: When set, generates single classes instead of interface + impl. Changes package structure (no `impl` subpackage). Many conditionals in `MessageGenerator` depend on this flag. - **Polymorphic JSON**: In a hierarchy with an abstract root, a value is written as a two-element array `[typeId, {fields}]` (the root's final `writeTo()`). A field declared with a concrete type of such a hierarchy uses `writeContent()` and writes the plain object without type info. A hierarchy with a concrete root carries no type info at all. - **Field IDs**: Auto-synthesis starts at 1, skips manually assigned IDs, is inheritance-aware (child fields can't clash with parent IDs). Field ID 0 is reserved. diff --git a/docs/superpowers/specs/2026-03-24-cross-file-protocol-extension-design.md b/docs/superpowers/specs/2026-03-24-cross-file-protocol-extension-design.md index b4079c9a..258cfb40 100644 --- a/docs/superpowers/specs/2026-03-24-cross-file-protocol-extension-design.md +++ b/docs/superpowers/specs/2026-03-24-cross-file-protocol-extension-design.md @@ -66,7 +66,7 @@ message DefinitionFile extends WithOptions { } ``` -**Bootstrapping note:** Since the generator is self-bootstrapping, this change requires: (1) add the field to `proto.proto`, (2) regenerate AST Java classes with the existing generator, (3) rebuild the generator. The Maven reactor handles this automatically. +**Bootstrapping note:** Since the generator is self-bootstrapping, this change requires: (1) add the field to `proto.proto`, (2) regenerate AST Java classes with the existing generator, (3) rebuild the generator. The build does not regenerate the AST classes; step (2) is a manual run of the generator (see CLAUDE.md, "Self-bootstrapping"). ### 4. Dynamic Type Registry From e5d3389a47f58b6ded4876c5075dcc326591dd59 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 17:24:04 +0200 Subject: [PATCH 198/207] Merge verified PRs as part of the msgbuf workflow. The skill ended the loop at "open the PR", so verified PRs piled up unmerged. The maintainer expects verified PRs to be merged by the session. The skill now says so, including the order for stacked PRs and the gate on a merged tree. Co-Authored-By: Claude Opus 5.5 --- .claude/skills/msgbuf-workflow/SKILL.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.claude/skills/msgbuf-workflow/SKILL.md b/.claude/skills/msgbuf-workflow/SKILL.md index 2bf9964a..ebfb3529 100644 --- a/.claude/skills/msgbuf-workflow/SKILL.md +++ b/.claude/skills/msgbuf-workflow/SKILL.md @@ -34,8 +34,9 @@ Work is a pipeline, not a pile: 3. **Dispatch** one sub-agent per coherent package (§2), or do it yourself when the package is small. msgbuf has one toolchain and one reactor, so parallel work needs separate worktrees (§3). 4. **Review with a novel probe** (§4). Non-negotiable. -5. **Gate** (§5), **commit and open or update the PR** (§6), close the issue with the fixing - commit or PR plus a summary comment naming the regression test. +5. **Gate** (§5), **commit and open or update the PR** (§6), and **merge it** once review and gate + are green (§6). Close the issue with the fixing commit or PR plus a summary comment naming the + regression test. 6. **Before finishing: `gh issue list -R msgbuf/msgbuf`.** Anything you find and defer becomes an issue (like #16–#21, found while building the TypeScript target), so a crashed session loses nothing. @@ -208,6 +209,13 @@ check `git status` first. When reporting, give the numbers (tests per module) an description in the same step (§4 for the `gh` workaround). - **The agents don't commit; you do**, after review. Pushing and force-pushing a shared branch are the user's call; a history rewrite of a PR branch others may have checked out needs explicit consent. +- **Merge verified PRs yourself.** A PR that passed the probe review (§4) and the gate (§5) is + merged, not left open for the user. Use a merge commit, like the history (`gh api -X PUT + repos/msgbuf/msgbuf/pulls//merge -f merge_method=merge`; `gh pr merge` may hit the GraphQL error + of §4). Merge stacked PRs bottom-up, retargeting the next one to `main` first (`gh api -X PATCH + …/pulls/ -f base=main`), and delete a merged branch only after nothing is based on it. A PR that + conflicts with `main` gets `main` merged in, then the gate runs on that merged tree before it lands. + Stop at PRs that carry an open design question, and say so. - **Releases are the user's**: `mvn release:clean release:prepare` pushes a `msgbuf-api-` tag, and the tag push runs `.github/workflows/release.yml`, which deploys to Maven Central (HOWTO-RELEASE.md). Never run `release:*`, never push a `msgbuf-api-*` tag, never edit the From ed035be8d1f348424fa237e5e00331fd74ee6ac0 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 17:29:44 +0200 Subject: [PATCH 199/207] Require OpenWorld for extensions across files and support specializations nested in their generalization. Extending a message of another package without OpenWorld produced Java that did not compile (#25). Extending a message of an only imported file compiled in the same package, but the base's readers did not know the subtype. As decided by the maintainer, such inconsistent OpenWorld annotations are rejected. A message may extend a message of another file only if that file declares `option OpenWorld`; this includes intermediates in extension files. A closed hierarchy split into files of the same package that are generated together stays accepted, since it works. The check runs before the format and field name checks, which would otherwise report follow-up errors. It also rejects inheritance cycles, which crashed the generator. `FieldIDSynthesizer` computed the indexes of a message by visiting its generalization, and that visit descended into the nested definitions again, so a message nested in its own generalization recursed endlessly (#32). The indexes are now computed along the generalizations only and memoized. The assigned indexes are unchanged for all existing test protos. Closes #25 Closes #32 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 8 + README.md | 8 +- .../msgbuf/generator/FieldIDSynthesizer.java | 36 +- .../haumacher/msgbuf/generator/Generator.java | 78 ++ .../java/test/nested/TestNestedRecursive.java | 82 ++ .../test/java/test/nested/recursive/Expr.java | 229 ++++++ .../test/java/test/nested/recursive/Node.java | 152 ++++ .../test/nested/recursive/impl/Expr_Impl.java | 777 ++++++++++++++++++ .../test/nested/recursive/impl/Node_Impl.java | 575 +++++++++++++ .../test/nested/recursive/recursive.proto | 28 + .../test/validation/TestGeneralizations.java | 101 +++ .../reject/openworld/base/closed.proto | 6 + .../reject/openworld/base/open.proto | 7 + .../reject/openworld/base/same-package.proto | 7 + .../resources/reject/openworld/cycle.proto | 9 + .../resources/reject/openworld/ext/leaf.proto | 6 + .../reject/openworld/ext/other-package.proto | 13 + .../resources/reject/openworld/mid/mid.proto | 7 + 18 files changed, 2123 insertions(+), 6 deletions(-) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNestedRecursive.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/Expr.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/Node.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/impl/Expr_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/impl/Node_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/recursive.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/validation/TestGeneralizations.java create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/base/closed.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/base/open.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/base/same-package.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/cycle.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/ext/leaf.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/ext/other-package.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/mid/mid.proto diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f1eb809..2a1c5390 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,14 @@ - **Redeclared fields** (#21): A field that redeclares an inherited field (directly or through any generalization, also across files), a field declared twice, and fields whose names generate the same Java names (e.g. `foo_bar` and `fooBar`) are rejected with an error. Before, the generator silently produced Java code that did not compile. +- **Extensions across files require OpenWorld** (#25): A message that extends a message of another file is rejected + unless that file declares `option OpenWorld`. Extending from another package produced Java that did not compile. + **Source compatibility:** extending a message of an only imported (not generated together) file of the same package + compiled before, but the readers of the base did not know the subtype. It is now rejected as well. A closed + hierarchy split into files of the same package that are generated together is still accepted. Inheritance cycles + are rejected with an error instead of crashing the generator. +- **Nested specializations of the outer message** (#32): A message nested in its own generalization (e.g. + `abstract message Expr { message Sum extends Expr {…} }`) crashed the generator with a `StackOverflowError`. ## 1.2.1 diff --git a/README.md b/README.md index 21455245..d640f63b 100644 --- a/README.md +++ b/README.md @@ -279,7 +279,13 @@ message Config { ### `option OpenWorld` Enables cross-file protocol extension for abstract type hierarchies. With this option, subtypes can be defined in -separate `.proto` files (and separate modules) using `import` and `extends`: +separate `.proto` files (and separate modules) using `import` and `extends`. + +A message can extend a message of another file only if that file declares `option OpenWorld`, so that the readers of +the hierarchy resolve types of other files. This also holds for an intermediate: to extend a message of an extension +file, the extension file must declare `option OpenWorld` as well. The only exception is a hierarchy without +`OpenWorld` that is split into several files of the same package, which are generated together. The generator rejects +other extensions across files with an error. ```protobuf // base-module: events.proto diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldIDSynthesizer.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldIDSynthesizer.java index 32dbd079..a23cacd3 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldIDSynthesizer.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/FieldIDSynthesizer.java @@ -20,6 +20,11 @@ * assigned in the message definition. */ public class FieldIDSynthesizer implements Definition.Visitor, Void> { + + /** + * Names of all fields by index for each processed message, including inherited fields. + */ + private final Map> _indexes = new HashMap<>(); /** * Assigns IDs in the given file. @@ -65,9 +70,33 @@ private void error(String message) { @Override public Map visit(MessageDef self, Void arg) { + Map result = indexes(self); + for (Definition inner : self.getDefinitions()) { + inner.visit(this, arg); + } + return result; + } + + /** + * Assigns the field indexes of the given message (and its generalizations) and returns the + * names of all its fields, including the inherited ones, by index. + * + *

+ * Walks the generalizations only, not the nested definitions: a nested message may extend its + * outer message. + *

+ */ + private Map indexes(MessageDef self) { + Map cached = _indexes.get(self); + if (cached != null) { + return cached; + } + // Guards against an inheritance cycle, which the generator rejects before. + _indexes.put(self, new HashMap<>()); + Map partByIndex; if (self.getExtendedDef() != null) { - partByIndex = self.getExtendedDef().visit(this, arg); + partByIndex = new HashMap<>(indexes(self.getExtendedDef())); } else { partByIndex = new HashMap<>(); } @@ -94,11 +123,8 @@ public Map visit(MessageDef self, Void arg) { field.setIndex(nextIndex); } } - - for (Definition inner : self.getDefinitions()) { - inner.visit(this, arg); - } + _indexes.put(self, partByIndex); return partByIndex; } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java index 25ca5868..6dcbce44 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java @@ -185,6 +185,15 @@ public void generate(GeneratorPlugin plugin) { } List errors = new ArrayList<>(); + for (DefinitionFile file : _files) { + if (!_importedFiles.contains(file)) { + validateGeneralizations(file, errors); + } + } + if (!errors.isEmpty()) { + // Checks below depend on a consistent hierarchy. + throw new GeneratorException(errors); + } for (DefinitionFile file : _files) { if (!_importedFiles.contains(file)) { validateFieldNames(file, errors); @@ -350,6 +359,75 @@ private static boolean extendsOpenWorldFromOtherFile(DefinitionFile file, Listoption OpenWorld. + * + *

+ * The readers of a hierarchy must know all its types. A message of another file can therefore + * only be extended if that file declares option OpenWorld, which makes its readers + * resolve extension types through a registry. The only exception is a closed hierarchy that is + * split into several files of the same package and generated together: then the readers of the + * extended message are generated with all its specializations. + *

+ */ + private void validateGeneralizations(DefinitionFile file, List errors) { + for (Definition def : file.getDefinitions()) { + validateGeneralizations(file, def, errors); + } + } + + private void validateGeneralizations(DefinitionFile file, Definition def, List errors) { + if (!(def instanceof MessageDef)) { + return; + } + MessageDef message = (MessageDef) def; + MessageDef extended = message.getExtendedDef(); + if (extended != null) { + List path = new ArrayList<>(); + path.add(message); + for (MessageDef current = extended; current != null; current = current.getExtendedDef()) { + if (current == message) { + path.add(current); + errors.add(sourceDescription(file) + ": Message '" + Util.toString(message) + + "' is part of an inheritance cycle: " + + path.stream().map(Util::toString).collect(java.util.stream.Collectors.joining(" extends ")) + + ". Remove one of the extends clauses."); + break; + } + if (path.contains(current)) { + // A cycle not containing this message, reported for its members. + break; + } + path.add(current); + } + + DefinitionFile extendedFile = Util.definingFile(extended); + if (extendedFile != file && !Util.getFlag(extendedFile, "OpenWorld") + && !(samePackage(file, extendedFile) && !_importedFiles.contains(extendedFile))) { + errors.add(sourceDescription(file) + ": Message '" + Util.toString(message) + "' extends message '" + + Util.toString(extended) + "' of '" + sourceDescription(extendedFile) + + "', which does not declare option OpenWorld. Add 'option OpenWorld;' to '" + + sourceDescription(extendedFile) + "' to extend its messages in other files" + + " (a hierarchy without OpenWorld can only be split into files of the same package" + + " that are generated together)."); + } + } + + for (Definition inner : message.getDefinitions()) { + validateGeneralizations(file, inner, errors); + } + } + + private static boolean samePackage(DefinitionFile file, DefinitionFile other) { + QName pkg = file.getPackage(); + QName otherPkg = other.getPackage(); + if (pkg == null || otherPkg == null) { + return pkg == otherPkg; + } + return pkg.getNames().equals(otherPkg.getNames()); + } + /** * Rejects fields whose generated names clash with the names of other fields of the same message, * declared in the message itself or inherited from a generalization. diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNestedRecursive.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNestedRecursive.java new file mode 100644 index 00000000..4e76bd9f --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNestedRecursive.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2026 Bernhard Haumacher et al. All Rights Reserved. + */ +package test.nested; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; + +import de.haumacher.msgbuf.binary.OctetDataReader; +import de.haumacher.msgbuf.binary.OctetDataWriter; +import de.haumacher.msgbuf.io.StringR; +import de.haumacher.msgbuf.json.JsonReader; +import junit.framework.TestCase; +import test.nested.recursive.Expr; +import test.nested.recursive.Node; + +/** + * Test case for specializations nested in their own generalization (issue #32). + */ +@SuppressWarnings("javadoc") +public class TestNestedRecursive extends TestCase { + + public void testJson() throws IOException { + Expr.Sum sum = createSum(); + String json = sum.toString(); + assertEquals("[\"Sum\",{\"label\":\"s\",\"operands\":[[\"Literal\",{\"label\":\"a\",\"value\":1}]," + + "[\"Sum\",{\"label\":\"\",\"operands\":[]}]],\"first\":{\"label\":\"\",\"value\":2}}]", json); + assertEquals(json, Expr.readExpr(new JsonReader(new StringR(json))).toString()); + } + + public void testBinary() throws IOException { + Expr.Sum sum = createSum(); + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + sum.writeTo(new OctetDataWriter(buffer)); + Expr copy = Expr.readExpr(new OctetDataReader(new ByteArrayInputStream(buffer.toByteArray()))); + assertEquals(sum.toString(), copy.toString()); + } + + public void testXml() throws XMLStreamException { + Expr.Sum sum = createSum(); + StringWriter buffer = new StringWriter(); + sum.writeTo(XMLOutputFactory.newDefaultFactory().createXMLStreamWriter(buffer)); + Expr copy = Expr.readExpr(XMLInputFactory.newFactory().createXMLStreamReader(new StringReader(buffer.toString()))); + assertEquals(sum.toString(), copy.toString()); + } + + public void testFieldIndexes() { + // Inherited fields keep their index, own fields of the nested specializations follow. + assertEquals(1, Expr.Literal.LABEL__ID); + assertEquals(2, Expr.Literal.VALUE__ID); + assertEquals(2, Expr.Sum.OPERANDS__ID); + assertEquals(3, Expr.Sum.FIRST__ID); + assertEquals(3, Node.Special.WEIGHT__ID); + } + + public void testConcreteRoot() throws IOException { + // A hierarchy with a concrete root carries no type information, read through the specialization's reader. + Node.Special special = Node.Special.create().setWeight(4); + special.setName("s"); + special.addChildren(Node.create().setName("c")); + String json = special.toString(); + assertEquals("{\"name\":\"s\",\"children\":[{\"name\":\"c\",\"children\":[]}],\"weight\":4}", json); + assertEquals(json, Node.Special.readSpecial(new JsonReader(new StringR(json))).toString()); + } + + private static Expr.Sum createSum() { + Expr.Sum result = Expr.Sum.create(); + result.setLabel("s"); + result.addOperand(Expr.Literal.create().setValue(1).setLabel("a")); + result.addOperand(Expr.Sum.create()); + result.setFirst(Expr.Literal.create().setValue(2)); + return result; + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/Expr.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/Expr.java new file mode 100644 index 00000000..066b03e0 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/Expr.java @@ -0,0 +1,229 @@ +package test.nested.recursive; + +/** + * Specializations nested in their own generalization (issue #32). + */ +public interface Expr extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** Type codes for the {@link test.nested.recursive.Expr} hierarchy. */ + public enum TypeKind { + + /** Type literal for {@link test.nested.recursive.Expr.Literal}. */ + LITERAL, + + /** Type literal for {@link test.nested.recursive.Expr.Sum}. */ + SUM, + ; + + } + + /** Visitor interface for the {@link test.nested.recursive.Expr} hierarchy.*/ + public interface Visitor { + + /** Visit case for {@link test.nested.recursive.Expr.Literal}.*/ + R visit(test.nested.recursive.Expr.Literal self, A arg) throws E; + + /** Visit case for {@link test.nested.recursive.Expr.Sum}.*/ + R visit(test.nested.recursive.Expr.Sum self, A arg) throws E; + + } + public interface Literal extends test.nested.recursive.Expr { + + /** + * Creates a {@link test.nested.recursive.Expr.Literal} instance. + */ + static test.nested.recursive.Expr.Literal create() { + return new test.nested.recursive.impl.Expr_Impl.Literal_Impl(); + } + + /** Identifier for the {@link test.nested.recursive.Expr.Literal} type in JSON format. */ + String LITERAL__TYPE = "Literal"; + + /** @see #getValue() */ + String VALUE__PROP = "value"; + + /** Identifier for the {@link test.nested.recursive.Expr.Literal} type in binary format. */ + static final int LITERAL__TYPE_ID = 1; + + /** Identifier for the property {@link #getValue()} in binary format. */ + static final int VALUE__ID = 2; + + int getValue(); + + /** + * @see #getValue() + */ + test.nested.recursive.Expr.Literal setValue(int value); + + @Override + test.nested.recursive.Expr.Literal setLabel(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.recursive.Expr.Literal readLiteral(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.recursive.impl.Expr_Impl.Literal_Impl result = new test.nested.recursive.impl.Expr_Impl.Literal_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.recursive.Expr.Literal readLiteral(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.recursive.Expr.Literal result = test.nested.recursive.impl.Expr_Impl.Literal_Impl.readLiteral_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Literal} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Literal readLiteral(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.recursive.impl.Expr_Impl.Literal_Impl.readLiteral_XmlContent(in); + } + + } + public interface Sum extends test.nested.recursive.Expr { + + /** + * Creates a {@link test.nested.recursive.Expr.Sum} instance. + */ + static test.nested.recursive.Expr.Sum create() { + return new test.nested.recursive.impl.Expr_Impl.Sum_Impl(); + } + + /** Identifier for the {@link test.nested.recursive.Expr.Sum} type in JSON format. */ + String SUM__TYPE = "Sum"; + + /** @see #getOperands() */ + String OPERANDS__PROP = "operands"; + + /** @see #getFirst() */ + String FIRST__PROP = "first"; + + /** Identifier for the {@link test.nested.recursive.Expr.Sum} type in binary format. */ + static final int SUM__TYPE_ID = 2; + + /** Identifier for the property {@link #getOperands()} in binary format. */ + static final int OPERANDS__ID = 2; + + /** Identifier for the property {@link #getFirst()} in binary format. */ + static final int FIRST__ID = 3; + + java.util.List getOperands(); + + /** + * @see #getOperands() + */ + test.nested.recursive.Expr.Sum setOperands(java.util.List value); + + /** + * Adds a value to the {@link #getOperands()} list. + */ + test.nested.recursive.Expr.Sum addOperand(test.nested.recursive.Expr value); + + /** + * Removes a value from the {@link #getOperands()} list. + */ + void removeOperand(test.nested.recursive.Expr value); + + test.nested.recursive.Expr.Literal getFirst(); + + /** + * @see #getFirst() + */ + test.nested.recursive.Expr.Sum setFirst(test.nested.recursive.Expr.Literal value); + + /** + * Checks, whether {@link #getFirst()} has a value. + */ + boolean hasFirst(); + + @Override + test.nested.recursive.Expr.Sum setLabel(String value); + + /** Reads a new instance from the given reader. */ + static test.nested.recursive.Expr.Sum readSum(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.recursive.impl.Expr_Impl.Sum_Impl result = new test.nested.recursive.impl.Expr_Impl.Sum_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.recursive.Expr.Sum readSum(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.recursive.Expr.Sum result = test.nested.recursive.impl.Expr_Impl.Sum_Impl.readSum_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Sum} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Sum readSum(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.recursive.impl.Expr_Impl.Sum_Impl.readSum_XmlContent(in); + } + + } + + /** @see #getLabel() */ + String LABEL__PROP = "label"; + + /** Identifier for the property {@link #getLabel()} in binary format. */ + static final int LABEL__ID = 1; + + /** The type code of this instance. */ + TypeKind kind(); + + String getLabel(); + + /** + * @see #getLabel() + */ + test.nested.recursive.Expr setLabel(String value); + + @Override + public test.nested.recursive.Expr registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.recursive.Expr unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.recursive.Expr readExpr(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.recursive.Expr result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case test.nested.recursive.Expr.Literal.LITERAL__TYPE: result = test.nested.recursive.Expr.Literal.readLiteral(in); break; + case test.nested.recursive.Expr.Sum.SUM__TYPE: result = test.nested.recursive.Expr.Sum.readSum(in); break; + default: in.skipValue(); result = null; break; + } + in.endArray(); + return result; + } + + /** The binary identifier for this concrete type in the polymorphic {@link test.nested.recursive.Expr} hierarchy. */ + abstract int typeId(); + + /** Reads a new instance from the given reader. */ + static test.nested.recursive.Expr readExpr(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + int typeField = in.nextName(); + assert typeField == 0; + int type = in.nextInt(); + test.nested.recursive.Expr result; + switch (type) { + case test.nested.recursive.Expr.Literal.LITERAL__TYPE_ID: result = test.nested.recursive.impl.Expr_Impl.Literal_Impl.readLiteral_Content(in); break; + case test.nested.recursive.Expr.Sum.SUM__TYPE_ID: result = test.nested.recursive.impl.Expr_Impl.Sum_Impl.readSum_Content(in); break; + default: result = null; while (in.hasNext()) {in.skipValue(); } + } + in.endObject(); + return result; + } + + /** Creates a new {@link Expr} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Expr readExpr(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.recursive.impl.Expr_Impl.readExpr_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/Node.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/Node.java new file mode 100644 index 00000000..a89ae399 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/Node.java @@ -0,0 +1,152 @@ +package test.nested.recursive; + +/** + * A concrete message with a nested specialization of itself. + */ +public interface Node extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** Type codes for the {@link test.nested.recursive.Node} hierarchy. */ + public enum TypeKind { + + /** Type literal for {@link test.nested.recursive.Node}. */ + NODE, + + /** Type literal for {@link test.nested.recursive.Node.Special}. */ + SPECIAL, + ; + + } + public interface Special extends test.nested.recursive.Node { + + /** + * Creates a {@link test.nested.recursive.Node.Special} instance. + */ + static test.nested.recursive.Node.Special create() { + return new test.nested.recursive.impl.Node_Impl.Special_Impl(); + } + + /** Identifier for the {@link test.nested.recursive.Node.Special} type in JSON format. */ + String SPECIAL__TYPE = "Special"; + + /** @see #getWeight() */ + String WEIGHT__PROP = "weight"; + + /** Identifier for the property {@link #getWeight()} in binary format. */ + static final int WEIGHT__ID = 3; + + int getWeight(); + + /** + * @see #getWeight() + */ + test.nested.recursive.Node.Special setWeight(int value); + + @Override + test.nested.recursive.Node.Special setName(String value); + + @Override + test.nested.recursive.Node.Special setChildren(java.util.List value); + + @Override + test.nested.recursive.Node.Special addChildren(test.nested.recursive.Node value); + + /** Reads a new instance from the given reader. */ + static test.nested.recursive.Node.Special readSpecial(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.recursive.impl.Node_Impl.Special_Impl result = new test.nested.recursive.impl.Node_Impl.Special_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.recursive.Node.Special readSpecial(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.recursive.Node.Special result = test.nested.recursive.impl.Node_Impl.Special_Impl.readSpecial_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Special} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Special readSpecial(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.recursive.impl.Node_Impl.Special_Impl.readSpecial_XmlContent(in); + } + + } + + /** + * Creates a {@link test.nested.recursive.Node} instance. + */ + static test.nested.recursive.Node create() { + return new test.nested.recursive.impl.Node_Impl(); + } + + /** Identifier for the {@link test.nested.recursive.Node} type in JSON format. */ + String NODE__TYPE = "Node"; + + /** @see #getName() */ + String NAME__PROP = "name"; + + /** @see #getChildren() */ + String CHILDREN__PROP = "children"; + + /** Identifier for the property {@link #getName()} in binary format. */ + static final int NAME__ID = 1; + + /** Identifier for the property {@link #getChildren()} in binary format. */ + static final int CHILDREN__ID = 2; + + /** The type code of this instance. */ + TypeKind kind(); + + String getName(); + + /** + * @see #getName() + */ + test.nested.recursive.Node setName(String value); + + java.util.List getChildren(); + + /** + * @see #getChildren() + */ + test.nested.recursive.Node setChildren(java.util.List value); + + /** + * Adds a value to the {@link #getChildren()} list. + */ + test.nested.recursive.Node addChildren(test.nested.recursive.Node value); + + /** + * Removes a value from the {@link #getChildren()} list. + */ + void removeChildren(test.nested.recursive.Node value); + + @Override + public test.nested.recursive.Node registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.nested.recursive.Node unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.nested.recursive.Node readNode(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.nested.recursive.impl.Node_Impl result = new test.nested.recursive.impl.Node_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.nested.recursive.Node readNode(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.nested.recursive.Node result = test.nested.recursive.impl.Node_Impl.readNode_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Node} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Node readNode(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.nested.recursive.impl.Node_Impl.readNode_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/impl/Expr_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/impl/Expr_Impl.java new file mode 100644 index 00000000..7d70c0ac --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/impl/Expr_Impl.java @@ -0,0 +1,777 @@ +package test.nested.recursive.impl; + +/** + * Implementation of {@link test.nested.recursive.Expr}. + */ +public abstract class Expr_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.recursive.Expr { + /** + * Implementation of {@link test.nested.recursive.Expr.Literal}. + */ + public static class Literal_Impl extends test.nested.recursive.impl.Expr_Impl implements test.nested.recursive.Expr.Literal { + + private int _value = 0; + + /** + * Creates a {@link Literal_Impl} instance. + * + * @see test.nested.recursive.Expr.Literal#create() + */ + public Literal_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.LITERAL; + } + + @Override + public final int getValue() { + return _value; + } + + @Override + public test.nested.recursive.Expr.Literal setValue(int value) { + internalSetValue(value); + return this; + } + + /** Internal setter for {@link #getValue()} without chain call utility. */ + protected final void internalSetValue(int value) { + _listener.beforeSet(this, VALUE__PROP, value); + _value = value; + _listener.afterChanged(this, VALUE__PROP); + } + + @Override + public test.nested.recursive.Expr.Literal setLabel(String value) { + internalSetLabel(value); + return this; + } + + @Override + public String jsonType() { + return LITERAL__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + VALUE__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.recursive.impl.Expr_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.recursive.impl.Expr_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case VALUE__PROP: return getValue(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case VALUE__PROP: internalSetValue((int) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(VALUE__PROP); + out.value(getValue()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case VALUE__PROP: setValue(in.nextInt()); break; + default: super.readField(in, field); + } + } + + @Override + public int typeId() { + return LITERAL__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(VALUE__ID); + out.value(getValue()); + } + + /** Helper for creating an object of type {@link test.nested.recursive.Expr.Literal} from a polymorphic composition. */ + public static test.nested.recursive.Expr.Literal readLiteral_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.recursive.impl.Expr_Impl.Literal_Impl result = new Literal_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case VALUE__ID: setValue(in.nextInt()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.recursive.Expr.Literal} type. */ + public static final String LITERAL__XML_ELEMENT = "literal"; + + /** XML attribute or element name of a {@link #getValue} property. */ + private static final String VALUE__XML_ATTR = "value"; + + @Override + public String getXmlTagName() { + return LITERAL__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(VALUE__XML_ATTR, Integer.toString(getValue())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.recursive.Expr.Literal} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Literal_Impl readLiteral_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Literal_Impl result = new Literal_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case VALUE__XML_ATTR: { + setValue(Integer.parseInt(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case VALUE__XML_ATTR: { + setValue(Integer.parseInt(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.nested.recursive.Expr.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + + } + /** + * Implementation of {@link test.nested.recursive.Expr.Sum}. + */ + public static class Sum_Impl extends test.nested.recursive.impl.Expr_Impl implements test.nested.recursive.Expr.Sum { + + private final java.util.List _operands = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.nested.recursive.Expr element) { + _listener.beforeAdd(Sum_Impl.this, OPERANDS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.nested.recursive.Expr element) { + _listener.afterRemove(Sum_Impl.this, OPERANDS__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Sum_Impl.this, OPERANDS__PROP); + } + }; + + private test.nested.recursive.Expr.Literal _first = null; + + /** + * Creates a {@link Sum_Impl} instance. + * + * @see test.nested.recursive.Expr.Sum#create() + */ + public Sum_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.SUM; + } + + @Override + public final java.util.List getOperands() { + return _operands; + } + + @Override + public test.nested.recursive.Expr.Sum setOperands(java.util.List value) { + internalSetOperands(value); + return this; + } + + /** Internal setter for {@link #getOperands()} without chain call utility. */ + protected final void internalSetOperands(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'operands' cannot be null."); + _operands.clear(); + _operands.addAll(value); + } + + @Override + public test.nested.recursive.Expr.Sum addOperand(test.nested.recursive.Expr value) { + internalAddOperand(value); + return this; + } + + /** Implementation of {@link #addOperand(test.nested.recursive.Expr)} without chain call utility. */ + protected final void internalAddOperand(test.nested.recursive.Expr value) { + _operands.add(value); + } + + @Override + public final void removeOperand(test.nested.recursive.Expr value) { + _operands.remove(value); + } + + @Override + public final test.nested.recursive.Expr.Literal getFirst() { + return _first; + } + + @Override + public test.nested.recursive.Expr.Sum setFirst(test.nested.recursive.Expr.Literal value) { + internalSetFirst(value); + return this; + } + + /** Internal setter for {@link #getFirst()} without chain call utility. */ + protected final void internalSetFirst(test.nested.recursive.Expr.Literal value) { + _listener.beforeSet(this, FIRST__PROP, value); + _first = value; + _listener.afterChanged(this, FIRST__PROP); + } + + @Override + public final boolean hasFirst() { + return _first != null; + } + + @Override + public test.nested.recursive.Expr.Sum setLabel(String value) { + internalSetLabel(value); + return this; + } + + @Override + public String jsonType() { + return SUM__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + OPERANDS__PROP, + FIRST__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.recursive.impl.Expr_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.recursive.impl.Expr_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case OPERANDS__PROP: return getOperands(); + case FIRST__PROP: return getFirst(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case OPERANDS__PROP: internalSetOperands(de.haumacher.msgbuf.util.Conversions.asList(test.nested.recursive.Expr.class, value)); break; + case FIRST__PROP: internalSetFirst((test.nested.recursive.Expr.Literal) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(OPERANDS__PROP); + out.beginArray(); + for (test.nested.recursive.Expr x : getOperands()) { + x.writeTo(out); + } + out.endArray(); + if (hasFirst()) { + out.name(FIRST__PROP); + getFirst().writeContent(out); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case OPERANDS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.nested.recursive.Expr.readExpr(in)); + } + in.endArray(); + setOperands(newValue); + } + break; + case FIRST__PROP: setFirst(test.nested.recursive.Expr.Literal.readLiteral(in)); break; + default: super.readField(in, field); + } + } + + @Override + public int typeId() { + return SUM__TYPE_ID; + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(OPERANDS__ID); + { + java.util.List values = getOperands(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.nested.recursive.Expr x : values) { + x.writeTo(out); + } + out.endArray(); + } + if (hasFirst()) { + out.name(FIRST__ID); + getFirst().writeTo(out); + } + } + + /** Helper for creating an object of type {@link test.nested.recursive.Expr.Sum} from a polymorphic composition. */ + public static test.nested.recursive.Expr.Sum readSum_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.recursive.impl.Expr_Impl.Sum_Impl result = new Sum_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case OPERANDS__ID: { + in.beginArray(); + while (in.hasNext()) { + addOperand(test.nested.recursive.Expr.readExpr(in)); + } + in.endArray(); + } + break; + case FIRST__ID: setFirst(test.nested.recursive.Expr.Literal.readLiteral(in)); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.recursive.Expr.Sum} type. */ + public static final String SUM__XML_ELEMENT = "sum"; + + /** XML attribute or element name of a {@link #getOperands} property. */ + private static final String OPERANDS__XML_ATTR = "operands"; + + /** XML attribute or element name of a {@link #getFirst} property. */ + private static final String FIRST__XML_ATTR = "first"; + + @Override + public String getXmlTagName() { + return SUM__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + out.writeStartElement(OPERANDS__XML_ATTR); + for (test.nested.recursive.Expr element : getOperands()) { + element.writeTo(out); + } + out.writeEndElement(); + if (hasFirst()) { + out.writeStartElement(FIRST__XML_ATTR); + getFirst().writeContent(out); + out.writeEndElement(); + } + } + + /** Creates a new {@link test.nested.recursive.Expr.Sum} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Sum_Impl readSum_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Sum_Impl result = new Sum_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case OPERANDS__XML_ATTR: { + internalReadOperandsListXml(in); + break; + } + case FIRST__XML_ATTR: { + setFirst(test.nested.recursive.impl.Expr_Impl.Literal_Impl.readLiteral_XmlContent(in)); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + private void internalReadOperandsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addOperand(test.nested.recursive.impl.Expr_Impl.readExpr_XmlContent(in)); + } + } + + @Override + public R visit(test.nested.recursive.Expr.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + + } + + private String _label = ""; + + /** + * Creates a {@link Expr_Impl} instance. + */ + public Expr_Impl() { + super(); + } + + @Override + public final String getLabel() { + return _label; + } + + @Override + public test.nested.recursive.Expr setLabel(String value) { + internalSetLabel(value); + return this; + } + + /** Internal setter for {@link #getLabel()} without chain call utility. */ + protected final void internalSetLabel(String value) { + _listener.beforeSet(this, LABEL__PROP, value); + _label = value; + _listener.afterChanged(this, LABEL__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.recursive.Expr registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.recursive.Expr unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + LABEL__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case LABEL__PROP: return getLabel(); + default: return test.nested.recursive.Expr.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case LABEL__PROP: internalSetLabel((String) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.beginArray(); + out.value(jsonType()); + writeContent(out); + out.endArray(); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(LABEL__PROP); + out.value(getLabel()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case LABEL__PROP: setLabel(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + out.name(0); + out.value(typeId()); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(LABEL__ID); + out.value(getLabel()); + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case LABEL__ID: setLabel(in.nextString()); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.recursive.Expr} type. */ + public static final String EXPR__XML_ELEMENT = "expr"; + + /** XML attribute or element name of a {@link #getLabel} property. */ + private static final String LABEL__XML_ATTR = "label"; + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(LABEL__XML_ATTR, getLabel()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.nested.recursive.Expr} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Expr_Impl readExpr_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case test.nested.recursive.impl.Expr_Impl.Literal_Impl.LITERAL__XML_ELEMENT: { + return test.nested.recursive.impl.Expr_Impl.Literal_Impl.readLiteral_XmlContent(in); + } + + case test.nested.recursive.impl.Expr_Impl.Sum_Impl.SUM__XML_ELEMENT: { + return test.nested.recursive.impl.Expr_Impl.Sum_Impl.readSum_XmlContent(in); + } + + default: { + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case LABEL__XML_ATTR: { + setLabel(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case LABEL__XML_ATTR: { + setLabel(in.getElementText()); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/impl/Node_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/impl/Node_Impl.java new file mode 100644 index 00000000..285af65b --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/impl/Node_Impl.java @@ -0,0 +1,575 @@ +package test.nested.recursive.impl; + +/** + * Implementation of {@link test.nested.recursive.Node}. + */ +public class Node_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.nested.recursive.Node { + /** + * Implementation of {@link test.nested.recursive.Node.Special}. + */ + public static class Special_Impl extends test.nested.recursive.impl.Node_Impl implements test.nested.recursive.Node.Special { + + private int _weight = 0; + + /** + * Creates a {@link Special_Impl} instance. + * + * @see test.nested.recursive.Node.Special#create() + */ + public Special_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.SPECIAL; + } + + @Override + public final int getWeight() { + return _weight; + } + + @Override + public test.nested.recursive.Node.Special setWeight(int value) { + internalSetWeight(value); + return this; + } + + /** Internal setter for {@link #getWeight()} without chain call utility. */ + protected final void internalSetWeight(int value) { + _listener.beforeSet(this, WEIGHT__PROP, value); + _weight = value; + _listener.afterChanged(this, WEIGHT__PROP); + } + + @Override + public test.nested.recursive.Node.Special setName(String value) { + internalSetName(value); + return this; + } + + @Override + public test.nested.recursive.Node.Special setChildren(java.util.List value) { + internalSetChildren(value); + return this; + } + + @Override + public test.nested.recursive.Node.Special addChildren(test.nested.recursive.Node value) { + internalAddChildren(value); + return this; + } + + @Override + public String jsonType() { + return SPECIAL__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + WEIGHT__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.nested.recursive.impl.Node_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.nested.recursive.impl.Node_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case WEIGHT__PROP: return getWeight(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case WEIGHT__PROP: internalSetWeight((int) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(WEIGHT__PROP); + out.value(getWeight()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case WEIGHT__PROP: setWeight(in.nextInt()); break; + default: super.readField(in, field); + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(WEIGHT__ID); + out.value(getWeight()); + } + + /** Helper for creating an object of type {@link test.nested.recursive.Node.Special} from a polymorphic composition. */ + public static test.nested.recursive.Node.Special readSpecial_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.recursive.impl.Node_Impl.Special_Impl result = new Special_Impl(); + result.readContent(in); + return result; + } + + @Override + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case WEIGHT__ID: setWeight(in.nextInt()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.nested.recursive.Node.Special} type. */ + public static final String SPECIAL__XML_ELEMENT = "special"; + + /** XML attribute or element name of a {@link #getWeight} property. */ + private static final String WEIGHT__XML_ATTR = "weight"; + + @Override + public String getXmlTagName() { + return SPECIAL__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WEIGHT__XML_ATTR, Integer.toString(getWeight())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.nested.recursive.Node.Special} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Special_Impl readSpecial_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Special_Impl result = new Special_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case WEIGHT__XML_ATTR: { + setWeight(Integer.parseInt(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case WEIGHT__XML_ATTR: { + setWeight(Integer.parseInt(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + } + + private String _name = ""; + + private final java.util.List _children = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.nested.recursive.Node element) { + _listener.beforeAdd(Node_Impl.this, CHILDREN__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.nested.recursive.Node element) { + _listener.afterRemove(Node_Impl.this, CHILDREN__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Node_Impl.this, CHILDREN__PROP); + } + }; + + /** + * Creates a {@link Node_Impl} instance. + * + * @see test.nested.recursive.Node#create() + */ + public Node_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.NODE; + } + + @Override + public final String getName() { + return _name; + } + + @Override + public test.nested.recursive.Node setName(String value) { + internalSetName(value); + return this; + } + + /** Internal setter for {@link #getName()} without chain call utility. */ + protected final void internalSetName(String value) { + _listener.beforeSet(this, NAME__PROP, value); + _name = value; + _listener.afterChanged(this, NAME__PROP); + } + + @Override + public final java.util.List getChildren() { + return _children; + } + + @Override + public test.nested.recursive.Node setChildren(java.util.List value) { + internalSetChildren(value); + return this; + } + + /** Internal setter for {@link #getChildren()} without chain call utility. */ + protected final void internalSetChildren(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'children' cannot be null."); + _children.clear(); + _children.addAll(value); + } + + @Override + public test.nested.recursive.Node addChildren(test.nested.recursive.Node value) { + internalAddChildren(value); + return this; + } + + /** Implementation of {@link #addChildren(test.nested.recursive.Node)} without chain call utility. */ + protected final void internalAddChildren(test.nested.recursive.Node value) { + _children.add(value); + } + + @Override + public final void removeChildren(test.nested.recursive.Node value) { + _children.remove(value); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.nested.recursive.Node registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.nested.recursive.Node unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return NODE__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + NAME__PROP, + CHILDREN__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NAME__PROP: return getName(); + case CHILDREN__PROP: return getChildren(); + default: return test.nested.recursive.Node.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NAME__PROP: internalSetName((String) value); break; + case CHILDREN__PROP: internalSetChildren(de.haumacher.msgbuf.util.Conversions.asList(test.nested.recursive.Node.class, value)); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NAME__PROP); + out.value(getName()); + out.name(CHILDREN__PROP); + out.beginArray(); + for (test.nested.recursive.Node x : getChildren()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case CHILDREN__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.nested.recursive.Node.readNode(in)); + } + in.endArray(); + setChildren(newValue); + } + break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(NAME__ID); + out.value(getName()); + out.name(CHILDREN__ID); + { + java.util.List values = getChildren(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.OBJECT, values.size()); + for (test.nested.recursive.Node x : values) { + x.writeTo(out); + } + out.endArray(); + } + } + + /** Helper for creating an object of type {@link test.nested.recursive.Node} from a polymorphic composition. */ + public static test.nested.recursive.Node readNode_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.nested.recursive.impl.Node_Impl result = new Node_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case NAME__ID: setName(in.nextString()); break; + case CHILDREN__ID: { + in.beginArray(); + while (in.hasNext()) { + addChildren(test.nested.recursive.Node.readNode(in)); + } + in.endArray(); + } + break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.nested.recursive.Node} type. */ + public static final String NODE__XML_ELEMENT = "node"; + + /** XML attribute or element name of a {@link #getName} property. */ + private static final String NAME__XML_ATTR = "name"; + + /** XML attribute or element name of a {@link #getChildren} property. */ + private static final String CHILDREN__XML_ATTR = "children"; + + @Override + public String getXmlTagName() { + return NODE__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeStartElement(CHILDREN__XML_ATTR); + for (test.nested.recursive.Node element : getChildren()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.nested.recursive.Node} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Node_Impl readNode_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Node_Impl result = new Node_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NAME__XML_ATTR: { + setName(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NAME__XML_ATTR: { + setName(in.getElementText()); + break; + } + case CHILDREN__XML_ATTR: { + internalReadChildrenListXml(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadChildrenListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addChildren(test.nested.recursive.impl.Node_Impl.readNode_XmlContent(in)); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/recursive.proto b/de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/recursive.proto new file mode 100644 index 00000000..03709b35 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/recursive/recursive.proto @@ -0,0 +1,28 @@ +package test.nested.recursive; + +/** + * Specializations nested in their own generalization (issue #32). + */ +abstract message Expr { + string label; + + message Literal extends Expr { + int value; + } + + message Sum extends Expr { + repeated Expr operands; + Literal first; + } +} + +/** A concrete message with a nested specialization of itself. */ +message Node { + string name; + + message Special extends Node { + int weight; + } + + repeated Node children; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/validation/TestGeneralizations.java b/de.haumacher.msgbuf.generator/src/test/java/test/validation/TestGeneralizations.java new file mode 100644 index 00000000..5ccf76f8 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/validation/TestGeneralizations.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2026 Bernhard Haumacher et al. All Rights Reserved. + */ +package test.validation; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.List; + +import de.haumacher.msgbuf.generator.Generator; +import de.haumacher.msgbuf.generator.GeneratorException; +import de.haumacher.msgbuf.generator.parser.ParseException; +import de.haumacher.msgbuf.generator.plugins.XmlStreamingPlugin; +import junit.framework.TestCase; + +/** + * Test case for rejecting extensions of messages of other files that are inconsistent with + * option OpenWorld (issue #25), and inheritance cycles. + */ +@SuppressWarnings("javadoc") +public class TestGeneralizations extends TestCase { + + private static final File FIXTURES = new File("src/test/resources/reject/openworld"); + + private static final String HINT = " to extend its messages in other files (a hierarchy without OpenWorld can only" + + " be split into files of the same package that are generated together)."; + + public void testOtherPackage() throws IOException, ParseException { + assertEquals(Arrays.asList( + "reject/ow/ext/other-package.proto: Message 'reject.ow.ext.Circle' extends message 'reject.ow.base.Shape' of" + + " 'reject/ow/base/closed.proto', which does not declare option OpenWorld. Add 'option OpenWorld;' to" + + " 'reject/ow/base/closed.proto'" + HINT, + "reject/ow/ext/other-package.proto: Message 'reject.ow.ext.Holder.Nested' extends message" + + " 'reject.ow.base.Shape' of 'reject/ow/base/closed.proto', which does not declare option OpenWorld." + + " Add 'option OpenWorld;' to 'reject/ow/base/closed.proto'" + HINT), + reject("ext/other-package.proto")); + } + + /** The base file is only imported, its readers were generated without the specialization. */ + public void testSamePackageImported() throws IOException, ParseException { + assertEquals(Arrays.asList( + "reject/ow/base/same-package.proto: Message 'reject.ow.base.Square' extends message 'reject.ow.base.Shape'" + + " of 'reject/ow/base/closed.proto', which does not declare option OpenWorld. Add 'option OpenWorld;'" + + " to 'reject/ow/base/closed.proto'" + HINT), + reject("base/same-package.proto")); + } + + /** A closed hierarchy split into files of the same package that are generated together. */ + public void testSamePackageTogether() throws IOException, ParseException { + File out = newOutputDir(); + Generator generator = new Generator(); + generator.setOut(out); + generator.load(new File(FIXTURES, "base/closed.proto")); + generator.load(new File(FIXTURES, "base/same-package.proto")); + generator.generate(new XmlStreamingPlugin()); + assertTrue(new File(out, "reject/ow/base/Square.java").isFile()); + } + + /** Extending an intermediate requires OpenWorld in the intermediate's file, not only in the root's. */ + public void testIntermediateWithoutOpenWorld() throws IOException, ParseException { + assertEquals(Arrays.asList( + "reject/ow/ext/leaf.proto: Message 'reject.ow.ext.Beep' extends message 'reject.ow.mid.Signal' of" + + " 'reject/ow/mid/mid.proto', which does not declare option OpenWorld. Add 'option OpenWorld;' to" + + " 'reject/ow/mid/mid.proto'" + HINT), + reject("ext/leaf.proto")); + } + + public void testCycle() throws IOException, ParseException { + assertEquals(Arrays.asList( + "reject/ow/cycle.proto: Message 'reject.ow.A' is part of an inheritance cycle: reject.ow.A extends" + + " reject.ow.B extends reject.ow.A. Remove one of the extends clauses.", + "reject/ow/cycle.proto: Message 'reject.ow.B' is part of an inheritance cycle: reject.ow.B extends" + + " reject.ow.A extends reject.ow.B. Remove one of the extends clauses."), + reject("cycle.proto")); + } + + private List reject(String proto) throws IOException, ParseException { + File out = newOutputDir(); + Generator generator = new Generator(); + generator.setOut(out); + generator.load(new File(FIXTURES, proto)); + try { + generator.generate(new XmlStreamingPlugin()); + fail("Expected rejection of '" + proto + "'."); + return null; + } catch (GeneratorException ex) { + String[] written = out.list(); + assertTrue("No code must be generated for rejected definitions.", written == null || written.length == 0); + return ex.getErrors(); + } + } + + private File newOutputDir() throws IOException { + File target = new File("target"); + target.mkdirs(); + return Files.createTempDirectory(target.toPath(), getName()).toFile(); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/base/closed.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/base/closed.proto new file mode 100644 index 00000000..72838681 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/base/closed.proto @@ -0,0 +1,6 @@ +package reject.ow.base; + +/** A closed hierarchy (no option OpenWorld). */ +abstract message Shape { + string name; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/base/open.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/base/open.proto new file mode 100644 index 00000000..8b141184 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/base/open.proto @@ -0,0 +1,7 @@ +package reject.ow.base; + +option OpenWorld; + +abstract message Event { + string source; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/base/same-package.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/base/same-package.proto new file mode 100644 index 00000000..7fa9fc33 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/base/same-package.proto @@ -0,0 +1,7 @@ +package reject.ow.base; +import "closed.proto"; + +/** Splits the closed hierarchy into another file of the same package. */ +message Square extends Shape { + int side; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/cycle.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/cycle.proto new file mode 100644 index 00000000..607bf368 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/cycle.proto @@ -0,0 +1,9 @@ +package reject.ow; + +message A extends B { + string a; +} + +message B extends A { + string b; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/ext/leaf.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/ext/leaf.proto new file mode 100644 index 00000000..e9231233 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/ext/leaf.proto @@ -0,0 +1,6 @@ +package reject.ow.ext; +import "../mid/mid.proto"; + +message Beep extends reject.ow.mid.Signal { + int duration; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/ext/other-package.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/ext/other-package.proto new file mode 100644 index 00000000..82c1e365 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/ext/other-package.proto @@ -0,0 +1,13 @@ +package reject.ow.ext; +import "../base/closed.proto"; + +/** Extends the closed hierarchy from another package (issue #25). */ +message Circle extends reject.ow.base.Shape { + int radius; +} + +message Holder { + message Nested extends reject.ow.base.Shape { + int size; + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/mid/mid.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/mid/mid.proto new file mode 100644 index 00000000..545bcc88 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/openworld/mid/mid.proto @@ -0,0 +1,7 @@ +package reject.ow.mid; +import "../base/open.proto"; + +/** An intermediate in a file without option OpenWorld. */ +abstract message Signal extends reject.ow.base.Event { + int level; +} From 7c34048f218b229e4e1429860e1decb0af2902a8 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 17:38:08 +0200 Subject: [PATCH 200/207] Let every reader of an OpenWorld hierarchy resolve the types of other files, in JSON and XML. The JSON reader of an abstract intermediate looked up the root's registry with a factory type it could not be assigned to, which did not compile (#26). The XML readers of an OpenWorld hierarchy had a closed switch over the types of their own file and could not read extension types at all (#27). As decided by the maintainer, a reader must consider all types of a hierarchy. The registration of an extension module now also registers XML element names, when both the extension and the root generate XML. The XML readers of the root and of all intermediates fall back to that registry. Intermediates accept a registered type only if it is one of their subtypes; otherwise they skip it like an unknown type, as the root reader does in JSON. The readers load the registrations themselves (`TypeRegistryLoader.ensureLoaded()`), since reading through an interface method did not trigger the static initializer that loaded them before. All concrete messages below an OpenWorld message of another file are registered, not only direct subtypes, and visitor dispatch and `kind()` of extension intermediates follow. Closes #26 Closes #27 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 14 + README.md | 7 + .../haumacher/msgbuf/generator/Generator.java | 60 +- .../msgbuf/generator/MessageGenerator.java | 56 +- .../generator/plugins/XmlStreamingPlugin.java | 61 +- .../src/test/java/test/nested/TestNested.java | 13 +- .../test/java/test/nested/owbase/Events.java | 11 + .../test/nested/owbase/impl/Events_Impl.java | 7 + .../test/nested/owcount/OwcountTypes.java | 1 + .../java/test/nested/owext/OwextTypes.java | 1 + .../java/test/openworld/TestOpenWorld.java | 18 + .../java/test/openworld/base/SSEEvent.java | 11 + .../openworld/base/impl/SSEEvent_Impl.java | 7 + .../openworld/deep/TestOpenWorldDeep.java | 373 ++++++++ .../java/test/openworld/deep/base/Animal.java | 103 +++ .../java/test/openworld/deep/base/Bird.java | 65 ++ .../java/test/openworld/deep/base/Dog.java | 44 + .../test/openworld/deep/base/Habitat.java | 257 ++++++ .../test/openworld/deep/base/Sparrow.java | 47 + .../java/test/openworld/deep/base/Zoo.java | 192 +++++ .../java/test/openworld/deep/base/base.proto | 61 ++ .../openworld/deep/base/impl/Animal_Impl.java | 227 +++++ .../openworld/deep/base/impl/Bird_Impl.java | 175 ++++ .../openworld/deep/base/impl/Dog_Impl.java | 178 ++++ .../deep/base/impl/Habitat_Impl.java | 797 +++++++++++++++++ .../deep/base/impl/Sparrow_Impl.java | 184 ++++ .../openworld/deep/base/impl/Zoo_Impl.java | 813 ++++++++++++++++++ .../test/openworld/deep/ext1/Ext1Types.java | 24 + .../java/test/openworld/deep/ext1/Fish.java | 65 ++ .../java/test/openworld/deep/ext1/Forest.java | 87 ++ .../java/test/openworld/deep/ext1/Parrot.java | 55 ++ .../java/test/openworld/deep/ext1/Pond.java | 72 ++ .../java/test/openworld/deep/ext1/Trout.java | 47 + .../java/test/openworld/deep/ext1/ext1.proto | 35 + .../openworld/deep/ext1/impl/Fish_Impl.java | 178 ++++ .../openworld/deep/ext1/impl/Forest_Impl.java | 312 +++++++ .../openworld/deep/ext1/impl/Parrot_Impl.java | 187 ++++ .../openworld/deep/ext1/impl/Pond_Impl.java | 315 +++++++ .../openworld/deep/ext1/impl/Trout_Impl.java | 184 ++++ .../java/test/openworld/deep/ext2/Eagle.java | 47 + .../test/openworld/deep/ext2/Ext2Types.java | 22 + .../java/test/openworld/deep/ext2/Raptor.java | 54 ++ .../java/test/openworld/deep/ext2/Shark.java | 55 ++ .../java/test/openworld/deep/ext2/ext2.proto | 18 + .../openworld/deep/ext2/impl/Eagle_Impl.java | 190 ++++ .../openworld/deep/ext2/impl/Raptor_Impl.java | 177 ++++ .../openworld/deep/ext2/impl/Shark_Impl.java | 187 ++++ .../java/test/openworld/ext1/Ext1Types.java | 1 + .../java/test/openworld/ext2/Ext2Types.java | 1 + .../de.haumacher.msgbuf.data.TypeRegistration | 2 + 50 files changed, 6068 insertions(+), 30 deletions(-) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/TestOpenWorldDeep.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Animal.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Bird.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Dog.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Habitat.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Sparrow.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Zoo.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/base.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Animal_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Bird_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Dog_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Habitat_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Sparrow_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Zoo_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Ext1Types.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Fish.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Forest.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Parrot.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Pond.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Trout.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/ext1.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Fish_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Forest_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Parrot_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Pond_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Trout_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Eagle.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Ext2Types.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Raptor.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Shark.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/ext2.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/impl/Eagle_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/impl/Raptor_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/impl/Shark_Impl.java diff --git a/CHANGELOG.md b/CHANGELOG.md index f9354651..97e9fbe9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,20 @@ - **Redeclared fields** (#21): A field that redeclares an inherited field (directly or through any generalization, also across files), a field declared twice, and fields whose names generate the same Java names (e.g. `foo_bar` and `fooBar`) are rejected with an error. Before, the generator silently produced Java code that did not compile. +- **OpenWorld readers of abstract intermediates** (#26): The JSON reader of an abstract message below the root of an + `option OpenWorld` hierarchy (e.g. `Bird` in `Animal > Bird > Parrot`, top-level or nested) no longer fails to + compile. It reads the types of other files registered with the root, if they are specializations of the message; a + registered type of another subtree is skipped like an unknown type (the reader returns `null`). This also works for + abstract intermediates declared in extension files (which need `option OpenWorld` to be extended themselves), at any + depth. All concrete messages of an extension file below an OpenWorld message of another file are now registered, + also those extending a message of their own file. Visiting a type of an extension-file intermediate with a visitor + that does not know it calls `visitDefault()`, and such types return `null` from `kind()`. The JSON readers load the + type registrations themselves (before, reading an extension type returned `null` unless some implementation class + of the hierarchy had been initialized before). +- **OpenWorld XML readers** (#27): The XML readers of an `option OpenWorld` hierarchy (root and abstract intermediates) + now read the types of other files. The generated registration class (e.g. `Ext1Types`) additionally registers the + XML element name of each extension type with the root (`registerXml()`, `XML_REGISTRY`), if the files generate XML. + The wire formats are unchanged. ## 1.2.1 diff --git a/README.md b/README.md index 7f044439..f5532c8e 100644 --- a/README.md +++ b/README.md @@ -297,6 +297,13 @@ The base module's `.proto` files should be packaged as resources in its JAR (e.g The Maven plugin automatically resolves imports from compile-scope dependency JARs, so no file system paths to the base module are needed. +Readers of the hierarchy (of the root and of abstract intermediates) resolve the types of all registered +extension modules in JSON and XML format. The registration class registers the JSON type ID and, if XML is +generated, the XML element name of each extension type with the root of the hierarchy. A reader of an abstract +intermediate only accepts registered types that specialize the intermediate. An unknown type (or a registered +type of another subtree) is skipped, and the reader returns `null`. An abstract message of an extension file can +itself be extended in further files, if the extension file declares `option OpenWorld`, too. + Implications: - Implies `option NoBinary` (only JSON and XML serialization are supported) - Cannot be combined with `option NoInterfaces` diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java index 25ca5868..4e428968 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java @@ -241,7 +241,7 @@ public void generate(GeneratorPlugin plugin) { } List crossFileExtensions = findCrossFileExtensions(file); if (!crossFileExtensions.isEmpty()) { - String fqClassName = generateRegistrationClass(file, crossFileExtensions); + String fqClassName = generateRegistrationClass(file, crossFileExtensions, plugin); registrationClasses.add(fqClassName); } } @@ -778,15 +778,21 @@ private List findCrossFileExtensions(DefinitionFile file) { return result; } + /** + * Collects the concrete messages of the given file that must be registered with the registry of + * an option OpenWorld hierarchy. + * + *

+ * These are all concrete messages with a generalization defined in another file with + * option OpenWorld. The readers of this generalization (and of its generalizations) + * only find these types through the registry of the hierarchy root. This includes messages + * that extend a message of the same file that extends a message of another file, and messages + * that extend a message of an extension file. + *

+ */ private void collectCrossFileExtensions(MessageDef def, DefinitionFile file, List result) { - MessageDef extended = def.getExtendedDef(); - DefinitionFile extendedFile = extended == null ? null : Util.definingFile(extended); - if (extendedFile != null && extendedFile != file) { - if (Util.getFlag(extendedFile, "OpenWorld")) { - if (!def.isAbstract()) { - result.add(def); - } - } + if (!def.isAbstract() && hasOpenWorldGeneralizationInOtherFile(def, file)) { + result.add(def); } for (Definition inner : def.getDefinitions()) { if (inner instanceof MessageDef) { @@ -795,7 +801,27 @@ private void collectCrossFileExtensions(MessageDef def, DefinitionFile file, Lis } } - private String generateRegistrationClass(DefinitionFile file, List extensions) { + private static boolean hasOpenWorldGeneralizationInOtherFile(MessageDef def, DefinitionFile file) { + Set seen = new HashSet<>(); + for (MessageDef current = def.getExtendedDef(); current != null && seen.add(current); current = current.getExtendedDef()) { + DefinitionFile currentFile = Util.definingFile(current); + if (currentFile != file && Util.getFlag(currentFile, "OpenWorld")) { + return true; + } + } + return false; + } + + private static MessageDef hierarchyRoot(MessageDef def) { + Set seen = new HashSet<>(); + MessageDef result = def; + while (result.getExtendedDef() != null && seen.add(result)) { + result = result.getExtendedDef(); + } + return result; + } + + private String generateRegistrationClass(DefinitionFile file, List extensions, GeneratorPlugin plugin) { String packageName = CodeConvention.packageName(file.getPackage()); String[] parts = packageName.split("\\."); String baseName = parts[parts.length - 1]; @@ -804,6 +830,8 @@ private String generateRegistrationClass(DefinitionFile file, List e File dir = mkdir(file.getPackage()); File out = new File(dir, className + ".java"); + boolean xml = formats(file, plugin).contains(XmlStreamingPlugin.XML_FORMAT); + try (FileOutputStream os = new FileOutputStream(out)) { try (PrintWriter w = new PrintWriter(new OutputStreamWriter(os, "utf-8"))) { System.out.println("Generating '" + out + "'."); @@ -817,15 +845,17 @@ private String generateRegistrationClass(DefinitionFile file, List e w.println("\t@Override"); w.println("\tpublic void register() {"); for (MessageDef ext : extensions) { - // Find the OpenWorld root type - MessageDef root = ext.getExtendedDef(); - while (root.getExtendedDef() != null) { - root = root.getExtendedDef(); - } + MessageDef root = hierarchyRoot(ext); String rootQName = CodeConvention.qTypeName(root); String extQName = CodeConvention.qTypeName(ext); String typeConstant = CodeConvention.jsonTypeConstant(ext); w.println("\t\t" + rootQName + ".register(" + extQName + "." + typeConstant + ", " + extQName + "::create);"); + if (xml && formats(Util.definingFile(root), plugin).contains(XmlStreamingPlugin.XML_FORMAT)) { + // The XML readers of the hierarchy dispatch unknown element names through the registry of the root. + String extImplQName = CodeConvention.qImplName(CodeConvention.IMPL_PACKAGE_SUFFIX, ext); + w.println("\t\t" + rootQName + "." + XmlStreamingPlugin.REGISTER_XML + "(" + extImplQName + "." + + XmlStreamingPlugin.xmlElementConstant(ext) + ", " + extQName + "::create);"); + } } w.println("\t}"); w.println(); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 4804f3a0..cf9a3431 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -664,8 +664,8 @@ private void generateKindLookup() { kindLookupComment(); line("public abstract " + TYPE_KIND_NAME + " kind();"); } - } else if (isCrossFileExtension()) { - // Cross-file extensions are not in the base's TypeKind enum, return null + } else if (isOpenWorldExtension()) { + // Types of other files are not in the TypeKind enum of an OpenWorld root, return null nl(); line("@Override"); line("public " + TYPE_KIND_NAME + " kind() {"); @@ -1374,11 +1374,26 @@ private void generateJson() { if (isOpenWorld()) { line("default: {"); { - line("de.haumacher.msgbuf.data.Factory factory = " + getOpenWorldRoot() + ".REGISTRY.get(type);"); - line("if (factory != null) {"); - { - line("result = factory.create();"); - line("result.readContent(in);"); + // Types of other files are only known through the registry of the hierarchy root, + // which is filled by the registrations found on the class path. + line("de.haumacher.msgbuf.data.TypeRegistryLoader.ensureLoaded();"); + String root = getOpenWorldRoot(); + if (_def.getExtendedDef() == null) { + line("de.haumacher.msgbuf.data.Factory factory = " + root + ".REGISTRY.get(type);"); + line("if (factory != null) {"); + { + line("result = factory.create();"); + line("result.readContent(in);"); + } + } else { + // The registry of the root may contain types that are no specializations of this type. + line("de.haumacher.msgbuf.data.Factory factory = " + root + ".REGISTRY.get(type);"); + line(root + " instance = factory == null ? null : factory.create();"); + line("if (instance instanceof " + thisType() + ") {"); + { + line("result = (" + thisType() + ") instance;"); + line("result.readContent(in);"); + } } line("} else {"); { @@ -2215,7 +2230,17 @@ private void generateVisitMethods() { line("public" + (_def.isAbstract() ? " final" : "") + " R visit(" + qTypeName(gen) + ".Visitor v, A arg) " + onVisitEx("throws E ") + "{"); { if (_def.isAbstract()) { - line("return visit((" + qTypeName(_def) + ".Visitor) v, arg);"); + if (isCrossFileExtension()) { + // The visitor of the generalization does not know this type. + line("if (v instanceof " + qTypeName(_def) + ".Visitor) {"); + { + line("return visit((" + qTypeName(_def) + ".Visitor) v, arg);"); + } + line("}"); + line("return v.visitDefault(this, arg);"); + } else { + line("return visit((" + qTypeName(_def) + ".Visitor) v, arg);"); + } } else if (isCrossFileExtension()) { line("if (v instanceof " + qTypeName(_def) + ".Visitor) {"); { @@ -2364,6 +2389,21 @@ private boolean isCrossFileExtension() { return genFile != Util.definingFile(_def) && Util.getFlag(genFile, "OpenWorld"); } + /** + * Whether the generated type belongs to an OpenWorld hierarchy whose root is defined in + * another file. + * + *

+ * Such a type is not known to the root, e.g. it is not listed in the root's TypeKind enum. + * In contrast to {@link #isCrossFileExtension()}, this also holds for a type that extends a + * message of its own file which in turn extends a message of another file. + *

+ */ + private boolean isOpenWorldExtension() { + DefinitionFile rootFile = Util.definingFile(getRoot(_def)); + return rootFile != Util.definingFile(_def) && Util.getFlag(rootFile, "OpenWorld"); + } + private List localSpecializations(MessageDef def) { return localSpecializations(def, Util.definingFile(_def)); } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java index a40b0999..17d6451f 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java @@ -95,6 +95,21 @@ public FileGenerator messageInterfaceContents(Map options, Messa return new AbstractMessageGenerator(options) { @Override protected void generate() { + if (isOpenWorld(options) && def.isAbstract() && !def.hasExtends()) { + nl(); + line("/** Registry for dynamically registered subtypes by their XML element names. */"); + line("static final java.util.Map> " + XML_REGISTRY + " = new java.util.HashMap<>();"); + nl(); + line("/**"); + line(" * Registers a subtype factory for reading elements with the given name in XML format."); + line(" */"); + line("static void " + REGISTER_XML + "(String elementName, de.haumacher.msgbuf.data.Factory factory) {"); + { + line(XML_REGISTRY + ".put(elementName, factory);"); + } + line("}"); + } + nl(); line("/** Creates a new {@link " + typeName(def) + "} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */"); line("public static " + typeName(def) + " " + readerMethod(def) + "(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException {"); @@ -254,6 +269,19 @@ protected void generate() { line("default: {"); { + if (isOpenWorld(options)) { + // Types of other files are only known through the registry of the hierarchy root. + String root = qTypeName(openWorldRoot(def)); + line("de.haumacher.msgbuf.data.Factory factory = " + root + "." + XML_REGISTRY + ".get(in.getLocalName());"); + line(root + " instance = factory == null ? null : factory.create();"); + line("if (instance instanceof " + implName(def) + ") {"); + { + line(implName(def) + " result = (" + implName(def) + ") instance;"); + line("result.readContentXml(in);"); + line("return result;"); + } + line("}"); + } line("internalSkipUntilMatchingEndElement(in);"); line("return null;"); } @@ -499,6 +527,37 @@ String xmlTypeNameRef(MessageDef def) { }; } + /** + * Name of the registry of XML element names in the root interface of an + * option OpenWorld hierarchy. + */ + public static final String XML_REGISTRY = "XML_REGISTRY"; + + /** + * Name of the method in the root interface of an option OpenWorld hierarchy + * that registers a factory for an XML element name. + */ + public static final String REGISTER_XML = "registerXml"; + + /** + * Name of the constant with the XML element name of the given message in its implementation class. + */ + public static String xmlElementConstant(MessageDef def) { + return CodeUtil.allUpperCase(def.getName()) + "__XML_ELEMENT"; + } + + private static boolean isOpenWorld(Map options) { + return AbstractMessageGenerator.isTrue(options.get("OpenWorld"), false); + } + + private static MessageDef openWorldRoot(MessageDef def) { + MessageDef result = def; + while (result.getExtendedDef() != null) { + result = result.getExtendedDef(); + } + return result; + } + private boolean noXml(Map options) { return options.get("NoXml") != null; } @@ -669,7 +728,7 @@ String xmlFieldNameConstant(Field field) { } String xmlTypeNameConstant(MessageDef def) { - return CodeUtil.allUpperCase(def.getName()) + "__XML_ELEMENT"; + return xmlElementConstant(def); } String readListFieldMethod(Field field) { diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNested.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNested.java index a9752731..6d35280c 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNested.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/TestNested.java @@ -223,9 +223,8 @@ public String visit(Zoo.Parrot self, Void arg) { * *

* OpenWorld implies NoBinary, so only JSON and XML apply. The extension types are discovered - * through the generated service descriptor in src/test/resources/META-INF/services. - * XML is checked for the local type only: the generated XML reader of an OpenWorld root does not - * consult the registry of extension types (for top-level roots neither). + * through the generated service descriptor in src/test/resources/META-INF/services, + * in JSON and in XML format (issue #27). *

*/ public void testOpenWorldCrossFile() throws IOException, XMLStreamException { @@ -251,9 +250,11 @@ public void testOpenWorldCrossFile() throws IOException, XMLStreamException { assertTrue(copy.getEvents().get(1) instanceof Patches.PatchEvent); assertTrue(copy.getEvents().get(2) instanceof CountEvent); - // XML: the local type of the base file is read back. - Events local = Events.create().addEvent(Events.TextEvent.create().setText("hi").setTimestamp(1)); - assertEquals(local.toString(), Events.readEvents(xmlReader(xml(local))).toString()); + // XML: the extension types are read back through the registry of XML element names. + Events xmlCopy = Events.readEvents(xmlReader(xml(events))); + assertEquals(expected, xmlCopy.toString()); + assertTrue(xmlCopy.getEvents().get(1) instanceof Patches.PatchEvent); + assertTrue(xmlCopy.getEvents().get(2) instanceof CountEvent); Events.Event.Visitor visitor = new Patches.PatchEvent.Visitor<>() { @Override diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/Events.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/Events.java index 84f9f31d..8dad7ea3 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/Events.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/Events.java @@ -66,6 +66,7 @@ static test.nested.owbase.Events.Event readEvent(de.haumacher.msgbuf.json.JsonRe switch (type) { case test.nested.owbase.Events.TextEvent.TEXT_EVENT__TYPE: result = test.nested.owbase.Events.TextEvent.readTextEvent(in); break; default: { + de.haumacher.msgbuf.data.TypeRegistryLoader.ensureLoaded(); de.haumacher.msgbuf.data.Factory factory = test.nested.owbase.Events.Event.REGISTRY.get(type); if (factory != null) { result = factory.create(); @@ -80,6 +81,16 @@ static test.nested.owbase.Events.Event readEvent(de.haumacher.msgbuf.json.JsonRe return result; } + /** Registry for dynamically registered subtypes by their XML element names. */ + static final java.util.Map> XML_REGISTRY = new java.util.HashMap<>(); + + /** + * Registers a subtype factory for reading elements with the given name in XML format. + */ + static void registerXml(String elementName, de.haumacher.msgbuf.data.Factory factory) { + XML_REGISTRY.put(elementName, factory); + } + /** Creates a new {@link Event} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static Event readEvent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/impl/Events_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/impl/Events_Impl.java index 547e6ed4..d1d92011 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/impl/Events_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owbase/impl/Events_Impl.java @@ -155,6 +155,13 @@ public static Event_Impl readEvent_XmlContent(javax.xml.stream.XMLStreamReader i } default: { + de.haumacher.msgbuf.data.Factory factory = test.nested.owbase.Events.Event.XML_REGISTRY.get(in.getLocalName()); + test.nested.owbase.Events.Event instance = factory == null ? null : factory.create(); + if (instance instanceof Event_Impl) { + Event_Impl result = (Event_Impl) instance; + result.readContentXml(in); + return result; + } internalSkipUntilMatchingEndElement(in); return null; } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/OwcountTypes.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/OwcountTypes.java index ac890314..2176adb8 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/OwcountTypes.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owcount/OwcountTypes.java @@ -8,6 +8,7 @@ public class OwcountTypes implements de.haumacher.msgbuf.data.TypeRegistration { @Override public void register() { test.nested.owbase.Events.Event.register(test.nested.owcount.CountEvent.COUNT_EVENT__TYPE, test.nested.owcount.CountEvent::create); + test.nested.owbase.Events.Event.registerXml(test.nested.owcount.impl.CountEvent_Impl.COUNT_EVENT__XML_ELEMENT, test.nested.owcount.CountEvent::create); } /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/OwextTypes.java b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/OwextTypes.java index e792e17e..3d2f68ad 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/OwextTypes.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/nested/owext/OwextTypes.java @@ -8,6 +8,7 @@ public class OwextTypes implements de.haumacher.msgbuf.data.TypeRegistration { @Override public void register() { test.nested.owbase.Events.Event.register(test.nested.owext.Patches.PatchEvent.PATCH_EVENT__TYPE, test.nested.owext.Patches.PatchEvent::create); + test.nested.owbase.Events.Event.registerXml(test.nested.owext.impl.Patches_Impl.PatchEvent_Impl.PATCH_EVENT__XML_ELEMENT, test.nested.owext.Patches.PatchEvent::create); } /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/TestOpenWorld.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/TestOpenWorld.java index c25ac546..0d5ba73e 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/TestOpenWorld.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/TestOpenWorld.java @@ -1,6 +1,12 @@ package test.openworld; import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; import de.haumacher.msgbuf.io.StringR; import de.haumacher.msgbuf.json.JsonReader; @@ -112,6 +118,18 @@ public void testUnknownType() throws IOException { assertNull(result); } + public void testExtensionRegistrationXml() throws XMLStreamException { + GraphPatchEvent graph = GraphPatchEvent.create().setControlId("c1").setPatch("p").setTimestamp(1); + AnalyticsPatchEvent analytics = AnalyticsPatchEvent.create().setMetricName("cpu").setMetricValue(0.5).setTimestamp(2); + for (SSEEvent event : new SSEEvent[] { graph, analytics, TextEvent.create().setText("t") }) { + StringWriter buffer = new StringWriter(); + event.writeTo(XMLOutputFactory.newDefaultFactory().createXMLStreamWriter(buffer)); + SSEEvent copy = SSEEvent.readSSEEvent(XMLInputFactory.newFactory().createXMLStreamReader(new StringReader(buffer.toString()))); + assertEquals(event.getClass(), copy.getClass()); + assertEquals(event.toString(), copy.toString()); + } + } + private SSEEvent readEvent(String json) throws IOException { return SSEEvent.readSSEEvent(new JsonReader(new StringR(json))); } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/base/SSEEvent.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/base/SSEEvent.java index 1b9ef5e4..a1d2a96a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/base/SSEEvent.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/base/SSEEvent.java @@ -65,6 +65,7 @@ static test.openworld.base.SSEEvent readSSEEvent(de.haumacher.msgbuf.json.JsonRe switch (type) { case TextEvent.TEXT_EVENT__TYPE: result = test.openworld.base.TextEvent.readTextEvent(in); break; default: { + de.haumacher.msgbuf.data.TypeRegistryLoader.ensureLoaded(); de.haumacher.msgbuf.data.Factory factory = test.openworld.base.SSEEvent.REGISTRY.get(type); if (factory != null) { result = factory.create(); @@ -79,6 +80,16 @@ static test.openworld.base.SSEEvent readSSEEvent(de.haumacher.msgbuf.json.JsonRe return result; } + /** Registry for dynamically registered subtypes by their XML element names. */ + static final java.util.Map> XML_REGISTRY = new java.util.HashMap<>(); + + /** + * Registers a subtype factory for reading elements with the given name in XML format. + */ + static void registerXml(String elementName, de.haumacher.msgbuf.data.Factory factory) { + XML_REGISTRY.put(elementName, factory); + } + /** Creates a new {@link SSEEvent} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ public static SSEEvent readSSEEvent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { in.nextTag(); diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/base/impl/SSEEvent_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/base/impl/SSEEvent_Impl.java index 0a59bf61..a096ce1a 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/base/impl/SSEEvent_Impl.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/base/impl/SSEEvent_Impl.java @@ -151,6 +151,13 @@ public static SSEEvent_Impl readSSEEvent_XmlContent(javax.xml.stream.XMLStreamRe } default: { + de.haumacher.msgbuf.data.Factory factory = test.openworld.base.SSEEvent.XML_REGISTRY.get(in.getLocalName()); + test.openworld.base.SSEEvent instance = factory == null ? null : factory.create(); + if (instance instanceof SSEEvent_Impl) { + SSEEvent_Impl result = (SSEEvent_Impl) instance; + result.readContentXml(in); + return result; + } internalSkipUntilMatchingEndElement(in); return null; } diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/TestOpenWorldDeep.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/TestOpenWorldDeep.java new file mode 100644 index 00000000..aa275445 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/TestOpenWorldDeep.java @@ -0,0 +1,373 @@ +package test.openworld.deep; + +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import java.net.URL; +import java.net.URLClassLoader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import de.haumacher.msgbuf.data.TypeRegistryLoader; +import de.haumacher.msgbuf.io.StringR; +import de.haumacher.msgbuf.json.JsonReader; +import de.haumacher.msgbuf.xml.XmlSerializable; +import junit.framework.TestCase; +import test.openworld.deep.base.Animal; +import test.openworld.deep.base.Bird; +import test.openworld.deep.base.Dog; +import test.openworld.deep.base.Habitat; +import test.openworld.deep.base.Sparrow; +import test.openworld.deep.base.Zoo; +import test.openworld.deep.ext1.Fish; +import test.openworld.deep.ext1.Forest; +import test.openworld.deep.ext1.Parrot; +import test.openworld.deep.ext1.Pond; +import test.openworld.deep.ext1.Trout; +import test.openworld.deep.ext2.Eagle; +import test.openworld.deep.ext2.Raptor; +import test.openworld.deep.ext2.Shark; + +/** + * Readers of OpenWorld hierarchies with abstract intermediates resolve the types of all files of + * the hierarchy in JSON and XML format (issues #26 and #27). + * + *

+ * The hierarchy {@link Animal} has the abstract intermediate {@link Bird} in the base file, the + * abstract intermediate {@link Fish} in the extension file ext1 and the abstract + * intermediate {@link Raptor} in the extension file ext2. The extension types are + * registered through the generated service descriptor in + * src/test/resources/META-INF/services. + *

+ */ +@SuppressWarnings("javadoc") +public class TestOpenWorldDeep extends TestCase { + + private static Parrot parrot() { + return Parrot.create().setWord("hello").setWingspan(0.5).setName("Polly"); + } + + private static Eagle eagle() { + return Eagle.create().setBald(true).setSpeed(80.5).setWingspan(2.0).setName("Sam"); + } + + private static Trout trout() { + return Trout.create().setRainbow(true).setFins(7).setName("Tim"); + } + + private static Shark shark() { + return Shark.create().setTeeth(300).setFins(8).setName("Bruce"); + } + + public void testExpectedJson() { + assertEquals("[\"Parrot\",{\"name\":\"Polly\",\"wingspan\":0.5,\"word\":\"hello\"}]", parrot().toString()); + assertEquals("{\"king\":[\"Shark\",{\"name\":\"Bruce\",\"fins\":8,\"teeth\":300}],\"school\":[]}", + Pond.create().setKing(shark()).toString()); + } + + public void testJsonThroughRootReader() throws IOException { + for (Animal animal : new Animal[] { parrot(), eagle(), trout(), shark(), Sparrow.create().setFlock(3), + Dog.create().setGood(true) }) { + Animal copy = Animal.readAnimal(json(animal.toString())); + assertEquals(animal.getClass(), copy.getClass()); + assertEquals(animal.toString(), copy.toString()); + } + } + + public void testJsonThroughIntermediateReader() throws IOException { + // Intermediate of the base file, types of the base file, the first and the second extension. + for (Bird bird : new Bird[] { parrot(), eagle(), Sparrow.create().setFlock(3) }) { + Bird copy = Bird.readBird(json(bird.toString())); + assertEquals(bird.getClass(), copy.getClass()); + assertEquals(bird.toString(), copy.toString()); + } + + // Intermediate of the first extension file, types of the same and of the second extension. + for (Fish fish : new Fish[] { trout(), shark() }) { + Fish copy = Fish.readFish(json(fish.toString())); + assertEquals(fish.getClass(), copy.getClass()); + assertEquals(fish.toString(), copy.toString()); + } + + // Intermediate at depth three of the second extension file. + Raptor copy = Raptor.readRaptor(json(eagle().toString())); + assertEquals(eagle().toString(), copy.toString()); + } + + public void testXmlThroughRootReader() throws XMLStreamException { + for (Animal animal : new Animal[] { parrot(), eagle(), trout(), shark(), Sparrow.create().setFlock(3), + Dog.create().setGood(true) }) { + Animal copy = Animal.readAnimal(xmlReader(xml(animal))); + assertEquals(animal.getClass(), copy.getClass()); + assertEquals(animal.toString(), copy.toString()); + } + } + + public void testXmlThroughIntermediateReader() throws XMLStreamException { + for (Bird bird : new Bird[] { parrot(), eagle(), Sparrow.create().setFlock(3) }) { + Bird copy = Bird.readBird(xmlReader(xml(bird))); + assertEquals(bird.getClass(), copy.getClass()); + assertEquals(bird.toString(), copy.toString()); + } + + for (Fish fish : new Fish[] { trout(), shark() }) { + Fish copy = Fish.readFish(xmlReader(xml(fish))); + assertEquals(fish.getClass(), copy.getClass()); + assertEquals(fish.toString(), copy.toString()); + } + + Raptor copy = Raptor.readRaptor(xmlReader(xml(eagle()))); + assertEquals(eagle().toString(), copy.toString()); + } + + /** + * Single, repeated and nested fields of the root and of an intermediate type. + */ + private static Zoo zoo() { + return Zoo.create() + .setStar(shark()) + .addAnimal(trout()) + .addAnimal(parrot()) + .addAnimal(Dog.create().setName("Rex")) + .addAnimal(eagle()) + .setFavorite(eagle()) + .addBird(parrot()) + .addBird(Sparrow.create().setName("Jack")) + .addBird(eagle()) + .setAviary(Zoo.Aviary.create() + .setBoss(parrot()) + .addResident(eagle()) + .addResident(parrot())); + } + + public void testFieldsJson() throws IOException { + Zoo zoo = zoo(); + String json = zoo.toString(); + Zoo copy = Zoo.readZoo(json(json)); + assertEquals(json, copy.toString()); + assertTrue(copy.getStar() instanceof Shark); + assertTrue(copy.getFavorite() instanceof Eagle); + assertTrue(copy.getBirds().get(0) instanceof Parrot); + assertTrue(copy.getAviary().getBoss() instanceof Parrot); + assertTrue(copy.getAviary().getResidents().get(0) instanceof Eagle); + + Pond pond = Pond.create().setKing(shark()).addSchool(trout()).addSchool(shark()); + assertEquals(pond.toString(), Pond.readPond(json(pond.toString())).toString()); + } + + public void testFieldsXml() throws XMLStreamException { + Zoo zoo = zoo(); + Zoo copy = Zoo.readZoo(xmlReader(xml(zoo))); + assertEquals(zoo.toString(), copy.toString()); + assertTrue(copy.getStar() instanceof Shark); + assertTrue(copy.getFavorite() instanceof Eagle); + assertTrue(copy.getAviary().getResidents().get(1) instanceof Parrot); + + Pond pond = Pond.create().setKing(shark()).addSchool(trout()).addSchool(shark()); + assertEquals(pond.toString(), Pond.readPond(xmlReader(xml(pond))).toString()); + } + + /** + * A nested OpenWorld hierarchy with a nested intermediate, extended by a nested type of another + * file. + */ + public void testNestedHierarchy() throws IOException, XMLStreamException { + Habitat habitat = Habitat.create() + .setTallest(Forest.Oak.create().setAge(200).setHeight(30).setSpecies("quercus")) + .addPlant(Habitat.Birch.create().setHeight(10)) + .addPlant(Forest.Oak.create().setAge(5)); + String json = habitat.toString(); + assertEquals(json, Habitat.readHabitat(json(json)).toString()); + assertEquals(json, Habitat.readHabitat(xmlReader(xml(habitat))).toString()); + + Forest.Oak oak = Forest.Oak.create().setAge(1); + assertEquals(oak.toString(), Habitat.Tree.readTree(json(oak.toString())).toString()); + assertEquals(oak.toString(), Habitat.Tree.readTree(xmlReader(xml(oak))).toString()); + } + + /** + * A reader of an intermediate treats a registered type of a sibling subtree like an unknown type: + * the value is skipped and the reader returns null, as the root reader does for an + * unknown type. + */ + public void testMismatchedAndUnknownTypeJson() throws IOException { + assertNull(Bird.readBird(json(trout().toString()))); + assertNull(Bird.readBird(json(shark().toString()))); + assertNull(Bird.readBird(json(Dog.create().toString()))); + assertNull(Fish.readFish(json(parrot().toString()))); + assertNull(Raptor.readRaptor(json(parrot().toString()))); + assertNull(Bird.readBird(json("[\"Unknown\",{\"name\":\"x\"}]"))); + assertNull(Animal.readAnimal(json("[\"Unknown\",{\"name\":\"x\"}]"))); + + // The skipped value is consumed completely: the reader continues with the next property. + Zoo zoo = Zoo.readZoo(json("{\"favorite\":" + trout() + ",\"star\":" + parrot() + "}")); + assertNull(zoo.getFavorite()); + assertEquals(parrot().toString(), zoo.getStar().toString()); + } + + public void testMismatchedAndUnknownTypeXml() throws XMLStreamException { + assertNull(Bird.readBird(xmlReader(xml(trout())))); + assertNull(Bird.readBird(xmlReader(xml(shark())))); + assertNull(Fish.readFish(xmlReader(xml(parrot())))); + assertNull(Raptor.readRaptor(xmlReader(xml(parrot())))); + assertNull(Bird.readBird(xmlReader(""))); + assertNull(Animal.readAnimal(xmlReader(""))); + + // The skipped element is consumed completely: the reader continues with the next element. + String xml = xml(Zoo.create().setFavorite(eagle()).setStar(parrot())) + .replace("", ""); + assertTrue(xml, xml.contains(" animals = new Animal.Visitor<>() { + @Override + public String visit(Sparrow self, Void arg) { + return "sparrow"; + } + + @Override + public String visit(Dog self, Void arg) { + return "dog"; + } + + @Override + public String visitDefault(Bird self, Void arg) { + return "bird:" + self.getName(); + } + + @Override + public String visitDefault(Animal self, Void arg) { + return "animal:" + self.getName(); + } + }; + assertEquals("sparrow", Sparrow.create().visit(animals, null)); + assertEquals("dog", Dog.create().visit(animals, null)); + assertEquals("bird:Polly", parrot().visit(animals, null)); + assertEquals("bird:Sam", eagle().visit(animals, null)); + assertEquals("animal:Tim", trout().visit(animals, null)); + assertEquals("animal:Bruce", shark().visit(animals, null)); + + // A visitor of the intermediate of an extension file handles its types. + class FishVisitor implements Animal.Visitor, Fish.Visitor { + @Override + public String visit(Sparrow self, Void arg) { + return "sparrow"; + } + + @Override + public String visit(Dog self, Void arg) { + return "dog"; + } + + @Override + public String visitDefault(Bird self, Void arg) { + return "bird"; + } + + @Override + public String visitDefault(Animal self, Void arg) { + return "animal"; + } + + @Override + public String visit(Trout self, Void arg) { + return "trout"; + } + + @Override + public String visitDefault(Fish self, Void arg) { + return "fish:" + self.getName(); + } + } + // Dispatched through the visitor of the root, which does not know the types of the extensions. + Animal.Visitor fishes = new FishVisitor(); + assertEquals("trout", trout().visit(fishes, null)); + assertEquals("fish:Bruce", shark().visit(fishes, null)); + assertEquals("bird", parrot().visit(fishes, null)); + assertEquals("dog", Dog.create().visit(fishes, null)); + + Animal.Visitor sharks = new FishVisitor() { + @Override + public String visitDefault(Fish self, Void arg) { + return self instanceof Shark ? "shark" : "other"; + } + }; + assertEquals("shark", shark().visit(sharks, null)); + + Bird.Visitor parrots = new Parrot.Visitor<>() { + @Override + public String visit(Sparrow self, Void arg) { + return "sparrow"; + } + + @Override + public String visit(Parrot self, Void arg) { + return "parrot:" + self.getWord(); + } + + @Override + public String visitDefault(Bird self, Void arg) { + return "bird"; + } + }; + assertEquals("parrot:hello", parrot().visit(parrots, null)); + assertEquals("bird", eagle().visit(parrots, null)); + assertEquals("sparrow", Sparrow.create().visit(parrots, null)); + } + + /** + * The JSON readers, static methods of interfaces, load the registrations of the extension types + * even if no implementation class of the hierarchy has been initialized before. + */ + public void testFreshReaderLoadsRegistrations() throws Exception { + assertEquals(Parrot.class.getName(), readInFreshClassLoader(Animal.class, "readAnimal", parrot().toString())); + assertEquals(Shark.class.getName(), readInFreshClassLoader(Fish.class, "readFish", shark().toString())); + } + + /** + * Reads the given JSON with the given reader method in a class loader that has not yet loaded + * any class of the tested hierarchy, and returns the name of the data interface of the result. + */ + private static String readInFreshClassLoader(Class type, String readMethod, String json) throws Exception { + URL testClasses = TestOpenWorldDeep.class.getProtectionDomain().getCodeSource().getLocation(); + URL apiClasses = TypeRegistryLoader.class.getProtectionDomain().getCodeSource().getLocation(); + Thread thread = Thread.currentThread(); + ClassLoader before = thread.getContextClassLoader(); + try (URLClassLoader loader = new URLClassLoader(new URL[] { testClasses, apiClasses }, + ClassLoader.getPlatformClassLoader())) { + // The service loader of the registrations uses the context class loader. + thread.setContextClassLoader(loader); + Class reader = loader.loadClass(JsonReader.class.getName()); + Object in = reader.getConstructor(loader.loadClass("de.haumacher.msgbuf.io.Reader")) + .newInstance(loader.loadClass(StringR.class.getName()).getConstructor(String.class).newInstance(json)); + Object result = loader.loadClass(type.getName()).getMethod(readMethod, reader).invoke(null, in); + assertNotNull(result); + assertNotSame(type, result.getClass().getInterfaces()[0]); + return result.getClass().getInterfaces()[0].getName(); + } finally { + thread.setContextClassLoader(before); + } + } + + private static JsonReader json(String data) { + return new JsonReader(new StringR(data)); + } + + private static String xml(XmlSerializable value) throws XMLStreamException { + StringWriter buffer = new StringWriter(); + value.writeTo(XMLOutputFactory.newDefaultFactory().createXMLStreamWriter(buffer)); + return buffer.toString(); + } + + private static XMLStreamReader xmlReader(String xml) throws XMLStreamException { + return XMLInputFactory.newFactory().createXMLStreamReader(new StringReader(xml)); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Animal.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Animal.java new file mode 100644 index 00000000..35e2aaac --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Animal.java @@ -0,0 +1,103 @@ +package test.openworld.deep.base; + +/** + * Root of an OpenWorld hierarchy with abstract intermediates (issues #26, #27). + */ +public interface Animal extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** Type codes for the {@link test.openworld.deep.base.Animal} hierarchy. */ + public enum TypeKind { + + /** Type literal for {@link test.openworld.deep.base.Sparrow}. */ + SPARROW, + + /** Type literal for {@link test.openworld.deep.base.Dog}. */ + DOG, + ; + + } + + /** Registry for dynamically registered subtypes. */ + static final java.util.Map> REGISTRY = new java.util.HashMap<>(); + + /** + * Registers a subtype factory for polymorphic deserialization. + */ + static void register(String typeId, de.haumacher.msgbuf.data.Factory factory) { + REGISTRY.put(typeId, factory); + } + + /** Visitor interface for the {@link test.openworld.deep.base.Animal} hierarchy.*/ + public interface Visitor extends test.openworld.deep.base.Bird.Visitor { + + /** Visit case for {@link test.openworld.deep.base.Dog}.*/ + R visit(test.openworld.deep.base.Dog self, A arg) throws E; + + /** Fallback for visiting subtypes not known at compile time. */ + R visitDefault(test.openworld.deep.base.Animal self, A arg) throws E; + + } + + /** @see #getName() */ + String NAME__PROP = "name"; + + /** The type code of this instance. */ + TypeKind kind(); + + String getName(); + + /** + * @see #getName() + */ + test.openworld.deep.base.Animal setName(String value); + + @Override + public test.openworld.deep.base.Animal registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.openworld.deep.base.Animal unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.base.Animal readAnimal(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.base.Animal result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case Sparrow.SPARROW__TYPE: result = test.openworld.deep.base.Sparrow.readSparrow(in); break; + case Dog.DOG__TYPE: result = test.openworld.deep.base.Dog.readDog(in); break; + default: { + de.haumacher.msgbuf.data.TypeRegistryLoader.ensureLoaded(); + de.haumacher.msgbuf.data.Factory factory = test.openworld.deep.base.Animal.REGISTRY.get(type); + if (factory != null) { + result = factory.create(); + result.readContent(in); + } else { + in.skipValue(); + result = null; + } + } break; + } + in.endArray(); + return result; + } + + /** Registry for dynamically registered subtypes by their XML element names. */ + static final java.util.Map> XML_REGISTRY = new java.util.HashMap<>(); + + /** + * Registers a subtype factory for reading elements with the given name in XML format. + */ + static void registerXml(String elementName, de.haumacher.msgbuf.data.Factory factory) { + XML_REGISTRY.put(elementName, factory); + } + + /** Creates a new {@link Animal} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Animal readAnimal(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.base.impl.Animal_Impl.readAnimal_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Bird.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Bird.java new file mode 100644 index 00000000..3e914bd1 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Bird.java @@ -0,0 +1,65 @@ +package test.openworld.deep.base; + +/** + * Abstract intermediate of the base file, extended in other files. + */ +public interface Bird extends test.openworld.deep.base.Animal { + + /** Visitor interface for the {@link test.openworld.deep.base.Bird} hierarchy.*/ + public interface Visitor { + + /** Visit case for {@link test.openworld.deep.base.Sparrow}.*/ + R visit(test.openworld.deep.base.Sparrow self, A arg) throws E; + + /** Fallback for visiting subtypes not known at compile time. */ + R visitDefault(test.openworld.deep.base.Bird self, A arg) throws E; + + } + + /** @see #getWingspan() */ + String WINGSPAN__PROP = "wingspan"; + + double getWingspan(); + + /** + * @see #getWingspan() + */ + test.openworld.deep.base.Bird setWingspan(double value); + + @Override + test.openworld.deep.base.Bird setName(String value); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.base.Bird readBird(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.base.Bird result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case Sparrow.SPARROW__TYPE: result = test.openworld.deep.base.Sparrow.readSparrow(in); break; + default: { + de.haumacher.msgbuf.data.TypeRegistryLoader.ensureLoaded(); + de.haumacher.msgbuf.data.Factory factory = test.openworld.deep.base.Animal.REGISTRY.get(type); + test.openworld.deep.base.Animal instance = factory == null ? null : factory.create(); + if (instance instanceof test.openworld.deep.base.Bird) { + result = (test.openworld.deep.base.Bird) instance; + result.readContent(in); + } else { + in.skipValue(); + result = null; + } + } break; + } + in.endArray(); + return result; + } + + /** Creates a new {@link Bird} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Bird readBird(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.base.impl.Bird_Impl.readBird_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Dog.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Dog.java new file mode 100644 index 00000000..dd7c194c --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Dog.java @@ -0,0 +1,44 @@ +package test.openworld.deep.base; + +/** + * Local leaf of a sibling subtree. + */ +public interface Dog extends test.openworld.deep.base.Animal { + + /** + * Creates a {@link test.openworld.deep.base.Dog} instance. + */ + static test.openworld.deep.base.Dog create() { + return new test.openworld.deep.base.impl.Dog_Impl(); + } + + /** Identifier for the {@link test.openworld.deep.base.Dog} type in JSON format. */ + String DOG__TYPE = "Dog"; + + /** @see #isGood() */ + String GOOD__PROP = "good"; + + boolean isGood(); + + /** + * @see #isGood() + */ + test.openworld.deep.base.Dog setGood(boolean value); + + @Override + test.openworld.deep.base.Dog setName(String value); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.base.Dog readDog(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.base.impl.Dog_Impl result = new test.openworld.deep.base.impl.Dog_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Dog} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Dog readDog(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.base.impl.Dog_Impl.readDog_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Habitat.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Habitat.java new file mode 100644 index 00000000..0466c48d --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Habitat.java @@ -0,0 +1,257 @@ +package test.openworld.deep.base; + +/** + * A nested OpenWorld hierarchy with an abstract intermediate. + */ +public interface Habitat extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + public interface Plant extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** Type codes for the {@link test.openworld.deep.base.Habitat.Plant} hierarchy. */ + public enum TypeKind { + + /** Type literal for {@link test.openworld.deep.base.Habitat.Birch}. */ + BIRCH, + ; + + } + + /** Registry for dynamically registered subtypes. */ + static final java.util.Map> REGISTRY = new java.util.HashMap<>(); + + /** + * Registers a subtype factory for polymorphic deserialization. + */ + static void register(String typeId, de.haumacher.msgbuf.data.Factory factory) { + REGISTRY.put(typeId, factory); + } + + /** Visitor interface for the {@link test.openworld.deep.base.Habitat.Plant} hierarchy.*/ + public interface Visitor extends test.openworld.deep.base.Habitat.Tree.Visitor { + + // Pure sum interface. + + /** Fallback for visiting subtypes not known at compile time. */ + R visitDefault(test.openworld.deep.base.Habitat.Plant self, A arg) throws E; + + } + + /** @see #getSpecies() */ + String SPECIES__PROP = "species"; + + /** The type code of this instance. */ + TypeKind kind(); + + String getSpecies(); + + /** + * @see #getSpecies() + */ + test.openworld.deep.base.Habitat.Plant setSpecies(String value); + + @Override + public test.openworld.deep.base.Habitat.Plant registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.openworld.deep.base.Habitat.Plant unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.base.Habitat.Plant readPlant(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.base.Habitat.Plant result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case test.openworld.deep.base.Habitat.Birch.BIRCH__TYPE: result = test.openworld.deep.base.Habitat.Birch.readBirch(in); break; + default: { + de.haumacher.msgbuf.data.TypeRegistryLoader.ensureLoaded(); + de.haumacher.msgbuf.data.Factory factory = test.openworld.deep.base.Habitat.Plant.REGISTRY.get(type); + if (factory != null) { + result = factory.create(); + result.readContent(in); + } else { + in.skipValue(); + result = null; + } + } break; + } + in.endArray(); + return result; + } + + /** Registry for dynamically registered subtypes by their XML element names. */ + static final java.util.Map> XML_REGISTRY = new java.util.HashMap<>(); + + /** + * Registers a subtype factory for reading elements with the given name in XML format. + */ + static void registerXml(String elementName, de.haumacher.msgbuf.data.Factory factory) { + XML_REGISTRY.put(elementName, factory); + } + + /** Creates a new {@link Plant} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Plant readPlant(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.base.impl.Habitat_Impl.Plant_Impl.readPlant_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + + } + public interface Tree extends test.openworld.deep.base.Habitat.Plant { + + /** Visitor interface for the {@link test.openworld.deep.base.Habitat.Tree} hierarchy.*/ + public interface Visitor { + + /** Visit case for {@link test.openworld.deep.base.Habitat.Birch}.*/ + R visit(test.openworld.deep.base.Habitat.Birch self, A arg) throws E; + + /** Fallback for visiting subtypes not known at compile time. */ + R visitDefault(test.openworld.deep.base.Habitat.Tree self, A arg) throws E; + + } + + /** @see #getHeight() */ + String HEIGHT__PROP = "height"; + + int getHeight(); + + /** + * @see #getHeight() + */ + test.openworld.deep.base.Habitat.Tree setHeight(int value); + + @Override + test.openworld.deep.base.Habitat.Tree setSpecies(String value); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.base.Habitat.Tree readTree(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.base.Habitat.Tree result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case test.openworld.deep.base.Habitat.Birch.BIRCH__TYPE: result = test.openworld.deep.base.Habitat.Birch.readBirch(in); break; + default: { + de.haumacher.msgbuf.data.TypeRegistryLoader.ensureLoaded(); + de.haumacher.msgbuf.data.Factory factory = test.openworld.deep.base.Habitat.Plant.REGISTRY.get(type); + test.openworld.deep.base.Habitat.Plant instance = factory == null ? null : factory.create(); + if (instance instanceof test.openworld.deep.base.Habitat.Tree) { + result = (test.openworld.deep.base.Habitat.Tree) instance; + result.readContent(in); + } else { + in.skipValue(); + result = null; + } + } break; + } + in.endArray(); + return result; + } + + /** Creates a new {@link Tree} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Tree readTree(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.base.impl.Habitat_Impl.Tree_Impl.readTree_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + + } + public interface Birch extends test.openworld.deep.base.Habitat.Tree { + + /** + * Creates a {@link test.openworld.deep.base.Habitat.Birch} instance. + */ + static test.openworld.deep.base.Habitat.Birch create() { + return new test.openworld.deep.base.impl.Habitat_Impl.Birch_Impl(); + } + + /** Identifier for the {@link test.openworld.deep.base.Habitat.Birch} type in JSON format. */ + String BIRCH__TYPE = "Birch"; + + @Override + test.openworld.deep.base.Habitat.Birch setHeight(int value); + + @Override + test.openworld.deep.base.Habitat.Birch setSpecies(String value); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.base.Habitat.Birch readBirch(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.base.impl.Habitat_Impl.Birch_Impl result = new test.openworld.deep.base.impl.Habitat_Impl.Birch_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Birch} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Birch readBirch(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.base.impl.Habitat_Impl.Birch_Impl.readBirch_XmlContent(in); + } + + } + + /** + * Creates a {@link test.openworld.deep.base.Habitat} instance. + */ + static test.openworld.deep.base.Habitat create() { + return new test.openworld.deep.base.impl.Habitat_Impl(); + } + + /** Identifier for the {@link test.openworld.deep.base.Habitat} type in JSON format. */ + String HABITAT__TYPE = "Habitat"; + + /** @see #getTallest() */ + String TALLEST__PROP = "tallest"; + + /** @see #getPlants() */ + String PLANTS__PROP = "plants"; + + test.openworld.deep.base.Habitat.Tree getTallest(); + + /** + * @see #getTallest() + */ + test.openworld.deep.base.Habitat setTallest(test.openworld.deep.base.Habitat.Tree value); + + /** + * Checks, whether {@link #getTallest()} has a value. + */ + boolean hasTallest(); + + java.util.List getPlants(); + + /** + * @see #getPlants() + */ + test.openworld.deep.base.Habitat setPlants(java.util.List value); + + /** + * Adds a value to the {@link #getPlants()} list. + */ + test.openworld.deep.base.Habitat addPlant(test.openworld.deep.base.Habitat.Plant value); + + /** + * Removes a value from the {@link #getPlants()} list. + */ + void removePlant(test.openworld.deep.base.Habitat.Plant value); + + @Override + public test.openworld.deep.base.Habitat registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.openworld.deep.base.Habitat unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.base.Habitat readHabitat(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.base.impl.Habitat_Impl result = new test.openworld.deep.base.impl.Habitat_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Habitat} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Habitat readHabitat(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.base.impl.Habitat_Impl.readHabitat_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Sparrow.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Sparrow.java new file mode 100644 index 00000000..07c7228c --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Sparrow.java @@ -0,0 +1,47 @@ +package test.openworld.deep.base; + +/** + * Local leaf below the intermediate. + */ +public interface Sparrow extends test.openworld.deep.base.Bird { + + /** + * Creates a {@link test.openworld.deep.base.Sparrow} instance. + */ + static test.openworld.deep.base.Sparrow create() { + return new test.openworld.deep.base.impl.Sparrow_Impl(); + } + + /** Identifier for the {@link test.openworld.deep.base.Sparrow} type in JSON format. */ + String SPARROW__TYPE = "Sparrow"; + + /** @see #getFlock() */ + String FLOCK__PROP = "flock"; + + int getFlock(); + + /** + * @see #getFlock() + */ + test.openworld.deep.base.Sparrow setFlock(int value); + + @Override + test.openworld.deep.base.Sparrow setWingspan(double value); + + @Override + test.openworld.deep.base.Sparrow setName(String value); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.base.Sparrow readSparrow(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.base.impl.Sparrow_Impl result = new test.openworld.deep.base.impl.Sparrow_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Sparrow} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Sparrow readSparrow(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.base.impl.Sparrow_Impl.readSparrow_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Zoo.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Zoo.java new file mode 100644 index 00000000..7e083adc --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/Zoo.java @@ -0,0 +1,192 @@ +package test.openworld.deep.base; + +/** + * Holder of values of the hierarchy in single, repeated and nested fields. + */ +public interface Zoo extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + /** + * A nested message with fields of the hierarchy. + */ + public interface Aviary extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.openworld.deep.base.Zoo.Aviary} instance. + */ + static test.openworld.deep.base.Zoo.Aviary create() { + return new test.openworld.deep.base.impl.Zoo_Impl.Aviary_Impl(); + } + + /** Identifier for the {@link test.openworld.deep.base.Zoo.Aviary} type in JSON format. */ + String AVIARY__TYPE = "Aviary"; + + /** @see #getBoss() */ + String BOSS__PROP = "boss"; + + /** @see #getResidents() */ + String RESIDENTS__PROP = "residents"; + + test.openworld.deep.base.Bird getBoss(); + + /** + * @see #getBoss() + */ + test.openworld.deep.base.Zoo.Aviary setBoss(test.openworld.deep.base.Bird value); + + /** + * Checks, whether {@link #getBoss()} has a value. + */ + boolean hasBoss(); + + java.util.List getResidents(); + + /** + * @see #getResidents() + */ + test.openworld.deep.base.Zoo.Aviary setResidents(java.util.List value); + + /** + * Adds a value to the {@link #getResidents()} list. + */ + test.openworld.deep.base.Zoo.Aviary addResident(test.openworld.deep.base.Bird value); + + /** + * Removes a value from the {@link #getResidents()} list. + */ + void removeResident(test.openworld.deep.base.Bird value); + + @Override + public test.openworld.deep.base.Zoo.Aviary registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.openworld.deep.base.Zoo.Aviary unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.base.Zoo.Aviary readAviary(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.base.impl.Zoo_Impl.Aviary_Impl result = new test.openworld.deep.base.impl.Zoo_Impl.Aviary_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Aviary} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Aviary readAviary(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.base.impl.Zoo_Impl.Aviary_Impl.readAviary_XmlContent(in); + } + + } + + /** + * Creates a {@link test.openworld.deep.base.Zoo} instance. + */ + static test.openworld.deep.base.Zoo create() { + return new test.openworld.deep.base.impl.Zoo_Impl(); + } + + /** Identifier for the {@link test.openworld.deep.base.Zoo} type in JSON format. */ + String ZOO__TYPE = "Zoo"; + + /** @see #getStar() */ + String STAR__PROP = "star"; + + /** @see #getAnimals() */ + String ANIMALS__PROP = "animals"; + + /** @see #getFavorite() */ + String FAVORITE__PROP = "favorite"; + + /** @see #getBirds() */ + String BIRDS__PROP = "birds"; + + /** @see #getAviary() */ + String AVIARY__PROP = "aviary"; + + test.openworld.deep.base.Animal getStar(); + + /** + * @see #getStar() + */ + test.openworld.deep.base.Zoo setStar(test.openworld.deep.base.Animal value); + + /** + * Checks, whether {@link #getStar()} has a value. + */ + boolean hasStar(); + + java.util.List getAnimals(); + + /** + * @see #getAnimals() + */ + test.openworld.deep.base.Zoo setAnimals(java.util.List value); + + /** + * Adds a value to the {@link #getAnimals()} list. + */ + test.openworld.deep.base.Zoo addAnimal(test.openworld.deep.base.Animal value); + + /** + * Removes a value from the {@link #getAnimals()} list. + */ + void removeAnimal(test.openworld.deep.base.Animal value); + + test.openworld.deep.base.Bird getFavorite(); + + /** + * @see #getFavorite() + */ + test.openworld.deep.base.Zoo setFavorite(test.openworld.deep.base.Bird value); + + /** + * Checks, whether {@link #getFavorite()} has a value. + */ + boolean hasFavorite(); + + java.util.List getBirds(); + + /** + * @see #getBirds() + */ + test.openworld.deep.base.Zoo setBirds(java.util.List value); + + /** + * Adds a value to the {@link #getBirds()} list. + */ + test.openworld.deep.base.Zoo addBird(test.openworld.deep.base.Bird value); + + /** + * Removes a value from the {@link #getBirds()} list. + */ + void removeBird(test.openworld.deep.base.Bird value); + + test.openworld.deep.base.Zoo.Aviary getAviary(); + + /** + * @see #getAviary() + */ + test.openworld.deep.base.Zoo setAviary(test.openworld.deep.base.Zoo.Aviary value); + + /** + * Checks, whether {@link #getAviary()} has a value. + */ + boolean hasAviary(); + + @Override + public test.openworld.deep.base.Zoo registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.openworld.deep.base.Zoo unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.base.Zoo readZoo(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.base.impl.Zoo_Impl result = new test.openworld.deep.base.impl.Zoo_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Zoo} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Zoo readZoo(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.base.impl.Zoo_Impl.readZoo_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/base.proto b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/base.proto new file mode 100644 index 00000000..08f4b8d5 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/base.proto @@ -0,0 +1,61 @@ +package test.openworld.deep.base; + +option OpenWorld; + +/** Root of an OpenWorld hierarchy with abstract intermediates (issues #26, #27). */ +abstract message Animal { + string name; +} + +/** Abstract intermediate of the base file, extended in other files. */ +abstract message Bird extends Animal { + double wingspan; +} + +/** Local leaf below the intermediate. */ +message Sparrow extends Bird { + int32 flock; +} + +/** Local leaf of a sibling subtree. */ +message Dog extends Animal { + bool good; +} + +/** Holder of values of the hierarchy in single, repeated and nested fields. */ +message Zoo { + Animal star; + + repeated Animal animals; + + Bird favorite; + + repeated Bird birds; + + /** A nested message with fields of the hierarchy. */ + message Aviary { + Bird boss; + + repeated Bird residents; + } + + Aviary aviary; +} + +/** A nested OpenWorld hierarchy with an abstract intermediate. */ +message Habitat { + abstract message Plant { + string species; + } + + abstract message Tree extends Plant { + int32 height; + } + + message Birch extends Tree { + } + + Tree tallest; + + repeated Plant plants; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Animal_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Animal_Impl.java new file mode 100644 index 00000000..ef183063 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Animal_Impl.java @@ -0,0 +1,227 @@ +package test.openworld.deep.base.impl; + +/** + * Implementation of {@link test.openworld.deep.base.Animal}. + */ +public abstract class Animal_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.openworld.deep.base.Animal { + + static { + de.haumacher.msgbuf.data.TypeRegistryLoader.ensureLoaded(); + } + + private String _name = ""; + + /** + * Creates a {@link Animal_Impl} instance. + */ + public Animal_Impl() { + super(); + } + + @Override + public final String getName() { + return _name; + } + + @Override + public test.openworld.deep.base.Animal setName(String value) { + internalSetName(value); + return this; + } + + /** Internal setter for {@link #getName()} without chain call utility. */ + protected final void internalSetName(String value) { + _listener.beforeSet(this, NAME__PROP, value); + _name = value; + _listener.afterChanged(this, NAME__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.openworld.deep.base.Animal registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.openworld.deep.base.Animal unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + NAME__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NAME__PROP: return getName(); + default: return test.openworld.deep.base.Animal.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NAME__PROP: internalSetName((String) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.beginArray(); + out.value(jsonType()); + writeContent(out); + out.endArray(); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NAME__PROP); + out.value(getName()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.base.Animal} type. */ + public static final String ANIMAL__XML_ELEMENT = "animal"; + + /** XML attribute or element name of a {@link #getName} property. */ + private static final String NAME__XML_ATTR = "name"; + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.openworld.deep.base.Animal} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Animal_Impl readAnimal_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case Sparrow_Impl.SPARROW__XML_ELEMENT: { + return test.openworld.deep.base.impl.Sparrow_Impl.readSparrow_XmlContent(in); + } + + case Dog_Impl.DOG__XML_ELEMENT: { + return test.openworld.deep.base.impl.Dog_Impl.readDog_XmlContent(in); + } + + default: { + de.haumacher.msgbuf.data.Factory factory = test.openworld.deep.base.Animal.XML_REGISTRY.get(in.getLocalName()); + test.openworld.deep.base.Animal instance = factory == null ? null : factory.create(); + if (instance instanceof Animal_Impl) { + Animal_Impl result = (Animal_Impl) instance; + result.readContentXml(in); + return result; + } + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NAME__XML_ATTR: { + setName(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NAME__XML_ATTR: { + setName(in.getElementText()); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Bird_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Bird_Impl.java new file mode 100644 index 00000000..8d503afb --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Bird_Impl.java @@ -0,0 +1,175 @@ +package test.openworld.deep.base.impl; + +/** + * Implementation of {@link test.openworld.deep.base.Bird}. + */ +public abstract class Bird_Impl extends test.openworld.deep.base.impl.Animal_Impl implements test.openworld.deep.base.Bird { + + private double _wingspan = 0.0d; + + /** + * Creates a {@link Bird_Impl} instance. + */ + public Bird_Impl() { + super(); + } + + @Override + public final double getWingspan() { + return _wingspan; + } + + @Override + public test.openworld.deep.base.Bird setWingspan(double value) { + internalSetWingspan(value); + return this; + } + + /** Internal setter for {@link #getWingspan()} without chain call utility. */ + protected final void internalSetWingspan(double value) { + _listener.beforeSet(this, WINGSPAN__PROP, value); + _wingspan = value; + _listener.afterChanged(this, WINGSPAN__PROP); + } + + @Override + public test.openworld.deep.base.Bird setName(String value) { + internalSetName(value); + return this; + } + + @SuppressWarnings("hiding") + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + WINGSPAN__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.openworld.deep.base.impl.Animal_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.openworld.deep.base.impl.Animal_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case WINGSPAN__PROP: return getWingspan(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case WINGSPAN__PROP: internalSetWingspan((double) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(WINGSPAN__PROP); + out.value(getWingspan()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case WINGSPAN__PROP: setWingspan(in.nextDouble()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.base.Bird} type. */ + public static final String BIRD__XML_ELEMENT = "bird"; + + /** XML attribute or element name of a {@link #getWingspan} property. */ + private static final String WINGSPAN__XML_ATTR = "wingspan"; + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WINGSPAN__XML_ATTR, Double.toString(getWingspan())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.openworld.deep.base.Bird} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Bird_Impl readBird_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case Sparrow_Impl.SPARROW__XML_ELEMENT: { + return test.openworld.deep.base.impl.Sparrow_Impl.readSparrow_XmlContent(in); + } + + default: { + de.haumacher.msgbuf.data.Factory factory = test.openworld.deep.base.Animal.XML_REGISTRY.get(in.getLocalName()); + test.openworld.deep.base.Animal instance = factory == null ? null : factory.create(); + if (instance instanceof Bird_Impl) { + Bird_Impl result = (Bird_Impl) instance; + result.readContentXml(in); + return result; + } + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case WINGSPAN__XML_ATTR: { + setWingspan(Double.parseDouble(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case WINGSPAN__XML_ATTR: { + setWingspan(Double.parseDouble(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public final R visit(test.openworld.deep.base.Animal.Visitor v, A arg) throws E { + return visit((test.openworld.deep.base.Bird.Visitor) v, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Dog_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Dog_Impl.java new file mode 100644 index 00000000..6de0269c --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Dog_Impl.java @@ -0,0 +1,178 @@ +package test.openworld.deep.base.impl; + +/** + * Implementation of {@link test.openworld.deep.base.Dog}. + */ +public class Dog_Impl extends test.openworld.deep.base.impl.Animal_Impl implements test.openworld.deep.base.Dog { + + private boolean _good = false; + + /** + * Creates a {@link Dog_Impl} instance. + * + * @see test.openworld.deep.base.Dog#create() + */ + public Dog_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.DOG; + } + + @Override + public final boolean isGood() { + return _good; + } + + @Override + public test.openworld.deep.base.Dog setGood(boolean value) { + internalSetGood(value); + return this; + } + + /** Internal setter for {@link #isGood()} without chain call utility. */ + protected final void internalSetGood(boolean value) { + _listener.beforeSet(this, GOOD__PROP, value); + _good = value; + _listener.afterChanged(this, GOOD__PROP); + } + + @Override + public test.openworld.deep.base.Dog setName(String value) { + internalSetName(value); + return this; + } + + @Override + public String jsonType() { + return DOG__TYPE; + } + + @SuppressWarnings("hiding") + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + GOOD__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.openworld.deep.base.impl.Animal_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.openworld.deep.base.impl.Animal_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case GOOD__PROP: return isGood(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case GOOD__PROP: internalSetGood((boolean) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(GOOD__PROP); + out.value(isGood()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case GOOD__PROP: setGood(in.nextBoolean()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.base.Dog} type. */ + public static final String DOG__XML_ELEMENT = "dog"; + + /** XML attribute or element name of a {@link #isGood} property. */ + private static final String GOOD__XML_ATTR = "good"; + + @Override + public String getXmlTagName() { + return DOG__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(GOOD__XML_ATTR, Boolean.toString(isGood())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.openworld.deep.base.Dog} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Dog_Impl readDog_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Dog_Impl result = new Dog_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case GOOD__XML_ATTR: { + setGood(Boolean.parseBoolean(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case GOOD__XML_ATTR: { + setGood(Boolean.parseBoolean(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.openworld.deep.base.Animal.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Habitat_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Habitat_Impl.java new file mode 100644 index 00000000..83a520e3 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Habitat_Impl.java @@ -0,0 +1,797 @@ +package test.openworld.deep.base.impl; + +/** + * Implementation of {@link test.openworld.deep.base.Habitat}. + */ +public class Habitat_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.openworld.deep.base.Habitat { + /** + * Implementation of {@link test.openworld.deep.base.Habitat.Plant}. + */ + public static abstract class Plant_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.openworld.deep.base.Habitat.Plant { + + static { + de.haumacher.msgbuf.data.TypeRegistryLoader.ensureLoaded(); + } + + private String _species = ""; + + /** + * Creates a {@link Plant_Impl} instance. + */ + public Plant_Impl() { + super(); + } + + @Override + public final String getSpecies() { + return _species; + } + + @Override + public test.openworld.deep.base.Habitat.Plant setSpecies(String value) { + internalSetSpecies(value); + return this; + } + + /** Internal setter for {@link #getSpecies()} without chain call utility. */ + protected final void internalSetSpecies(String value) { + _listener.beforeSet(this, SPECIES__PROP, value); + _species = value; + _listener.afterChanged(this, SPECIES__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.openworld.deep.base.Habitat.Plant registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.openworld.deep.base.Habitat.Plant unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + SPECIES__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case SPECIES__PROP: return getSpecies(); + default: return test.openworld.deep.base.Habitat.Plant.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case SPECIES__PROP: internalSetSpecies((String) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.beginArray(); + out.value(jsonType()); + writeContent(out); + out.endArray(); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(SPECIES__PROP); + out.value(getSpecies()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case SPECIES__PROP: setSpecies(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.base.Habitat.Plant} type. */ + public static final String PLANT__XML_ELEMENT = "plant"; + + /** XML attribute or element name of a {@link #getSpecies} property. */ + private static final String SPECIES__XML_ATTR = "species"; + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(SPECIES__XML_ATTR, getSpecies()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.openworld.deep.base.Habitat.Plant} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Plant_Impl readPlant_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case test.openworld.deep.base.impl.Habitat_Impl.Birch_Impl.BIRCH__XML_ELEMENT: { + return test.openworld.deep.base.impl.Habitat_Impl.Birch_Impl.readBirch_XmlContent(in); + } + + default: { + de.haumacher.msgbuf.data.Factory factory = test.openworld.deep.base.Habitat.Plant.XML_REGISTRY.get(in.getLocalName()); + test.openworld.deep.base.Habitat.Plant instance = factory == null ? null : factory.create(); + if (instance instanceof Plant_Impl) { + Plant_Impl result = (Plant_Impl) instance; + result.readContentXml(in); + return result; + } + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case SPECIES__XML_ATTR: { + setSpecies(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case SPECIES__XML_ATTR: { + setSpecies(in.getElementText()); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + } + /** + * Implementation of {@link test.openworld.deep.base.Habitat.Tree}. + */ + public static abstract class Tree_Impl extends test.openworld.deep.base.impl.Habitat_Impl.Plant_Impl implements test.openworld.deep.base.Habitat.Tree { + + private int _height = 0; + + /** + * Creates a {@link Tree_Impl} instance. + */ + public Tree_Impl() { + super(); + } + + @Override + public final int getHeight() { + return _height; + } + + @Override + public test.openworld.deep.base.Habitat.Tree setHeight(int value) { + internalSetHeight(value); + return this; + } + + /** Internal setter for {@link #getHeight()} without chain call utility. */ + protected final void internalSetHeight(int value) { + _listener.beforeSet(this, HEIGHT__PROP, value); + _height = value; + _listener.afterChanged(this, HEIGHT__PROP); + } + + @Override + public test.openworld.deep.base.Habitat.Tree setSpecies(String value) { + internalSetSpecies(value); + return this; + } + + @SuppressWarnings("hiding") + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + HEIGHT__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.openworld.deep.base.impl.Habitat_Impl.Plant_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.openworld.deep.base.impl.Habitat_Impl.Plant_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case HEIGHT__PROP: return getHeight(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case HEIGHT__PROP: internalSetHeight((int) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(HEIGHT__PROP); + out.value(getHeight()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case HEIGHT__PROP: setHeight(in.nextInt()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.base.Habitat.Tree} type. */ + public static final String TREE__XML_ELEMENT = "tree"; + + /** XML attribute or element name of a {@link #getHeight} property. */ + private static final String HEIGHT__XML_ATTR = "height"; + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(HEIGHT__XML_ATTR, Integer.toString(getHeight())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.openworld.deep.base.Habitat.Tree} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Tree_Impl readTree_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case test.openworld.deep.base.impl.Habitat_Impl.Birch_Impl.BIRCH__XML_ELEMENT: { + return test.openworld.deep.base.impl.Habitat_Impl.Birch_Impl.readBirch_XmlContent(in); + } + + default: { + de.haumacher.msgbuf.data.Factory factory = test.openworld.deep.base.Habitat.Plant.XML_REGISTRY.get(in.getLocalName()); + test.openworld.deep.base.Habitat.Plant instance = factory == null ? null : factory.create(); + if (instance instanceof Tree_Impl) { + Tree_Impl result = (Tree_Impl) instance; + result.readContentXml(in); + return result; + } + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case HEIGHT__XML_ATTR: { + setHeight(Integer.parseInt(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case HEIGHT__XML_ATTR: { + setHeight(Integer.parseInt(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public final R visit(test.openworld.deep.base.Habitat.Plant.Visitor v, A arg) throws E { + return visit((test.openworld.deep.base.Habitat.Tree.Visitor) v, arg); + } + + } + /** + * Implementation of {@link test.openworld.deep.base.Habitat.Birch}. + */ + public static class Birch_Impl extends test.openworld.deep.base.impl.Habitat_Impl.Tree_Impl implements test.openworld.deep.base.Habitat.Birch { + + /** + * Creates a {@link Birch_Impl} instance. + * + * @see test.openworld.deep.base.Habitat.Birch#create() + */ + public Birch_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.BIRCH; + } + + @Override + public test.openworld.deep.base.Habitat.Birch setHeight(int value) { + internalSetHeight(value); + return this; + } + + @Override + public test.openworld.deep.base.Habitat.Birch setSpecies(String value) { + internalSetSpecies(value); + return this; + } + + @Override + public String jsonType() { + return BIRCH__TYPE; + } + + /** XML element name representing a {@link test.openworld.deep.base.Habitat.Birch} type. */ + public static final String BIRCH__XML_ELEMENT = "birch"; + + @Override + public String getXmlTagName() { + return BIRCH__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.openworld.deep.base.Habitat.Birch} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Birch_Impl readBirch_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Birch_Impl result = new Birch_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.openworld.deep.base.Habitat.Tree.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + + } + + private test.openworld.deep.base.Habitat.Tree _tallest = null; + + private final java.util.List _plants = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.openworld.deep.base.Habitat.Plant element) { + _listener.beforeAdd(Habitat_Impl.this, PLANTS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.openworld.deep.base.Habitat.Plant element) { + _listener.afterRemove(Habitat_Impl.this, PLANTS__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Habitat_Impl.this, PLANTS__PROP); + } + }; + + /** + * Creates a {@link Habitat_Impl} instance. + * + * @see test.openworld.deep.base.Habitat#create() + */ + public Habitat_Impl() { + super(); + } + + @Override + public final test.openworld.deep.base.Habitat.Tree getTallest() { + return _tallest; + } + + @Override + public test.openworld.deep.base.Habitat setTallest(test.openworld.deep.base.Habitat.Tree value) { + internalSetTallest(value); + return this; + } + + /** Internal setter for {@link #getTallest()} without chain call utility. */ + protected final void internalSetTallest(test.openworld.deep.base.Habitat.Tree value) { + _listener.beforeSet(this, TALLEST__PROP, value); + _tallest = value; + _listener.afterChanged(this, TALLEST__PROP); + } + + @Override + public final boolean hasTallest() { + return _tallest != null; + } + + @Override + public final java.util.List getPlants() { + return _plants; + } + + @Override + public test.openworld.deep.base.Habitat setPlants(java.util.List value) { + internalSetPlants(value); + return this; + } + + /** Internal setter for {@link #getPlants()} without chain call utility. */ + protected final void internalSetPlants(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'plants' cannot be null."); + _plants.clear(); + _plants.addAll(value); + } + + @Override + public test.openworld.deep.base.Habitat addPlant(test.openworld.deep.base.Habitat.Plant value) { + internalAddPlant(value); + return this; + } + + /** Implementation of {@link #addPlant(test.openworld.deep.base.Habitat.Plant)} without chain call utility. */ + protected final void internalAddPlant(test.openworld.deep.base.Habitat.Plant value) { + _plants.add(value); + } + + @Override + public final void removePlant(test.openworld.deep.base.Habitat.Plant value) { + _plants.remove(value); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.openworld.deep.base.Habitat registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.openworld.deep.base.Habitat unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return HABITAT__TYPE; + } + + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + TALLEST__PROP, + PLANTS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case TALLEST__PROP: return getTallest(); + case PLANTS__PROP: return getPlants(); + default: return test.openworld.deep.base.Habitat.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case TALLEST__PROP: internalSetTallest((test.openworld.deep.base.Habitat.Tree) value); break; + case PLANTS__PROP: internalSetPlants(de.haumacher.msgbuf.util.Conversions.asList(test.openworld.deep.base.Habitat.Plant.class, value)); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + if (hasTallest()) { + out.name(TALLEST__PROP); + getTallest().writeTo(out); + } + out.name(PLANTS__PROP); + out.beginArray(); + for (test.openworld.deep.base.Habitat.Plant x : getPlants()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case TALLEST__PROP: setTallest(test.openworld.deep.base.Habitat.Tree.readTree(in)); break; + case PLANTS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.openworld.deep.base.Habitat.Plant.readPlant(in)); + } + in.endArray(); + setPlants(newValue); + } + break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.base.Habitat} type. */ + public static final String HABITAT__XML_ELEMENT = "habitat"; + + /** XML attribute or element name of a {@link #getTallest} property. */ + private static final String TALLEST__XML_ATTR = "tallest"; + + /** XML attribute or element name of a {@link #getPlants} property. */ + private static final String PLANTS__XML_ATTR = "plants"; + + @Override + public String getXmlTagName() { + return HABITAT__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasTallest()) { + out.writeStartElement(TALLEST__XML_ATTR); + getTallest().writeTo(out); + out.writeEndElement(); + } + out.writeStartElement(PLANTS__XML_ATTR); + for (test.openworld.deep.base.Habitat.Plant element : getPlants()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.openworld.deep.base.Habitat} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Habitat_Impl readHabitat_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Habitat_Impl result = new Habitat_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case TALLEST__XML_ATTR: { + in.nextTag(); + setTallest(test.openworld.deep.base.impl.Habitat_Impl.Tree_Impl.readTree_XmlContent(in)); + internalSkipUntilMatchingEndElement(in); + break; + } + case PLANTS__XML_ATTR: { + internalReadPlantsListXml(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadPlantsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addPlant(test.openworld.deep.base.impl.Habitat_Impl.Plant_Impl.readPlant_XmlContent(in)); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Sparrow_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Sparrow_Impl.java new file mode 100644 index 00000000..9a70c959 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Sparrow_Impl.java @@ -0,0 +1,184 @@ +package test.openworld.deep.base.impl; + +/** + * Implementation of {@link test.openworld.deep.base.Sparrow}. + */ +public class Sparrow_Impl extends test.openworld.deep.base.impl.Bird_Impl implements test.openworld.deep.base.Sparrow { + + private int _flock = 0; + + /** + * Creates a {@link Sparrow_Impl} instance. + * + * @see test.openworld.deep.base.Sparrow#create() + */ + public Sparrow_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.SPARROW; + } + + @Override + public final int getFlock() { + return _flock; + } + + @Override + public test.openworld.deep.base.Sparrow setFlock(int value) { + internalSetFlock(value); + return this; + } + + /** Internal setter for {@link #getFlock()} without chain call utility. */ + protected final void internalSetFlock(int value) { + _listener.beforeSet(this, FLOCK__PROP, value); + _flock = value; + _listener.afterChanged(this, FLOCK__PROP); + } + + @Override + public test.openworld.deep.base.Sparrow setWingspan(double value) { + internalSetWingspan(value); + return this; + } + + @Override + public test.openworld.deep.base.Sparrow setName(String value) { + internalSetName(value); + return this; + } + + @Override + public String jsonType() { + return SPARROW__TYPE; + } + + @SuppressWarnings("hiding") + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + FLOCK__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.openworld.deep.base.impl.Bird_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.openworld.deep.base.impl.Bird_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case FLOCK__PROP: return getFlock(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case FLOCK__PROP: internalSetFlock((int) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(FLOCK__PROP); + out.value(getFlock()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case FLOCK__PROP: setFlock(in.nextInt()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.base.Sparrow} type. */ + public static final String SPARROW__XML_ELEMENT = "sparrow"; + + /** XML attribute or element name of a {@link #getFlock} property. */ + private static final String FLOCK__XML_ATTR = "flock"; + + @Override + public String getXmlTagName() { + return SPARROW__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(FLOCK__XML_ATTR, Integer.toString(getFlock())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.openworld.deep.base.Sparrow} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Sparrow_Impl readSparrow_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Sparrow_Impl result = new Sparrow_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case FLOCK__XML_ATTR: { + setFlock(Integer.parseInt(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case FLOCK__XML_ATTR: { + setFlock(Integer.parseInt(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.openworld.deep.base.Bird.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Zoo_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Zoo_Impl.java new file mode 100644 index 00000000..b794e689 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/base/impl/Zoo_Impl.java @@ -0,0 +1,813 @@ +package test.openworld.deep.base.impl; + +/** + * Implementation of {@link test.openworld.deep.base.Zoo}. + */ +public class Zoo_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.openworld.deep.base.Zoo { + /** + * Implementation of {@link test.openworld.deep.base.Zoo.Aviary}. + */ + public static class Aviary_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.openworld.deep.base.Zoo.Aviary { + + private test.openworld.deep.base.Bird _boss = null; + + private final java.util.List _residents = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.openworld.deep.base.Bird element) { + _listener.beforeAdd(Aviary_Impl.this, RESIDENTS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.openworld.deep.base.Bird element) { + _listener.afterRemove(Aviary_Impl.this, RESIDENTS__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Aviary_Impl.this, RESIDENTS__PROP); + } + }; + + /** + * Creates a {@link Aviary_Impl} instance. + * + * @see test.openworld.deep.base.Zoo.Aviary#create() + */ + public Aviary_Impl() { + super(); + } + + @Override + public final test.openworld.deep.base.Bird getBoss() { + return _boss; + } + + @Override + public test.openworld.deep.base.Zoo.Aviary setBoss(test.openworld.deep.base.Bird value) { + internalSetBoss(value); + return this; + } + + /** Internal setter for {@link #getBoss()} without chain call utility. */ + protected final void internalSetBoss(test.openworld.deep.base.Bird value) { + _listener.beforeSet(this, BOSS__PROP, value); + _boss = value; + _listener.afterChanged(this, BOSS__PROP); + } + + @Override + public final boolean hasBoss() { + return _boss != null; + } + + @Override + public final java.util.List getResidents() { + return _residents; + } + + @Override + public test.openworld.deep.base.Zoo.Aviary setResidents(java.util.List value) { + internalSetResidents(value); + return this; + } + + /** Internal setter for {@link #getResidents()} without chain call utility. */ + protected final void internalSetResidents(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'residents' cannot be null."); + _residents.clear(); + _residents.addAll(value); + } + + @Override + public test.openworld.deep.base.Zoo.Aviary addResident(test.openworld.deep.base.Bird value) { + internalAddResident(value); + return this; + } + + /** Implementation of {@link #addResident(test.openworld.deep.base.Bird)} without chain call utility. */ + protected final void internalAddResident(test.openworld.deep.base.Bird value) { + _residents.add(value); + } + + @Override + public final void removeResident(test.openworld.deep.base.Bird value) { + _residents.remove(value); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.openworld.deep.base.Zoo.Aviary registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.openworld.deep.base.Zoo.Aviary unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return AVIARY__TYPE; + } + + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + BOSS__PROP, + RESIDENTS__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case BOSS__PROP: return getBoss(); + case RESIDENTS__PROP: return getResidents(); + default: return test.openworld.deep.base.Zoo.Aviary.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case BOSS__PROP: internalSetBoss((test.openworld.deep.base.Bird) value); break; + case RESIDENTS__PROP: internalSetResidents(de.haumacher.msgbuf.util.Conversions.asList(test.openworld.deep.base.Bird.class, value)); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + if (hasBoss()) { + out.name(BOSS__PROP); + getBoss().writeTo(out); + } + out.name(RESIDENTS__PROP); + out.beginArray(); + for (test.openworld.deep.base.Bird x : getResidents()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case BOSS__PROP: setBoss(test.openworld.deep.base.Bird.readBird(in)); break; + case RESIDENTS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.openworld.deep.base.Bird.readBird(in)); + } + in.endArray(); + setResidents(newValue); + } + break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.base.Zoo.Aviary} type. */ + public static final String AVIARY__XML_ELEMENT = "aviary"; + + /** XML attribute or element name of a {@link #getBoss} property. */ + private static final String BOSS__XML_ATTR = "boss"; + + /** XML attribute or element name of a {@link #getResidents} property. */ + private static final String RESIDENTS__XML_ATTR = "residents"; + + @Override + public String getXmlTagName() { + return AVIARY__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasBoss()) { + out.writeStartElement(BOSS__XML_ATTR); + getBoss().writeTo(out); + out.writeEndElement(); + } + out.writeStartElement(RESIDENTS__XML_ATTR); + for (test.openworld.deep.base.Bird element : getResidents()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.openworld.deep.base.Zoo.Aviary} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Aviary_Impl readAviary_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Aviary_Impl result = new Aviary_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case BOSS__XML_ATTR: { + in.nextTag(); + setBoss(test.openworld.deep.base.impl.Bird_Impl.readBird_XmlContent(in)); + internalSkipUntilMatchingEndElement(in); + break; + } + case RESIDENTS__XML_ATTR: { + internalReadResidentsListXml(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadResidentsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addResident(test.openworld.deep.base.impl.Bird_Impl.readBird_XmlContent(in)); + } + } + + } + + private test.openworld.deep.base.Animal _star = null; + + private final java.util.List _animals = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.openworld.deep.base.Animal element) { + _listener.beforeAdd(Zoo_Impl.this, ANIMALS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.openworld.deep.base.Animal element) { + _listener.afterRemove(Zoo_Impl.this, ANIMALS__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Zoo_Impl.this, ANIMALS__PROP); + } + }; + + private test.openworld.deep.base.Bird _favorite = null; + + private final java.util.List _birds = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.openworld.deep.base.Bird element) { + _listener.beforeAdd(Zoo_Impl.this, BIRDS__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.openworld.deep.base.Bird element) { + _listener.afterRemove(Zoo_Impl.this, BIRDS__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Zoo_Impl.this, BIRDS__PROP); + } + }; + + private test.openworld.deep.base.Zoo.Aviary _aviary = null; + + /** + * Creates a {@link Zoo_Impl} instance. + * + * @see test.openworld.deep.base.Zoo#create() + */ + public Zoo_Impl() { + super(); + } + + @Override + public final test.openworld.deep.base.Animal getStar() { + return _star; + } + + @Override + public test.openworld.deep.base.Zoo setStar(test.openworld.deep.base.Animal value) { + internalSetStar(value); + return this; + } + + /** Internal setter for {@link #getStar()} without chain call utility. */ + protected final void internalSetStar(test.openworld.deep.base.Animal value) { + _listener.beforeSet(this, STAR__PROP, value); + _star = value; + _listener.afterChanged(this, STAR__PROP); + } + + @Override + public final boolean hasStar() { + return _star != null; + } + + @Override + public final java.util.List getAnimals() { + return _animals; + } + + @Override + public test.openworld.deep.base.Zoo setAnimals(java.util.List value) { + internalSetAnimals(value); + return this; + } + + /** Internal setter for {@link #getAnimals()} without chain call utility. */ + protected final void internalSetAnimals(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'animals' cannot be null."); + _animals.clear(); + _animals.addAll(value); + } + + @Override + public test.openworld.deep.base.Zoo addAnimal(test.openworld.deep.base.Animal value) { + internalAddAnimal(value); + return this; + } + + /** Implementation of {@link #addAnimal(test.openworld.deep.base.Animal)} without chain call utility. */ + protected final void internalAddAnimal(test.openworld.deep.base.Animal value) { + _animals.add(value); + } + + @Override + public final void removeAnimal(test.openworld.deep.base.Animal value) { + _animals.remove(value); + } + + @Override + public final test.openworld.deep.base.Bird getFavorite() { + return _favorite; + } + + @Override + public test.openworld.deep.base.Zoo setFavorite(test.openworld.deep.base.Bird value) { + internalSetFavorite(value); + return this; + } + + /** Internal setter for {@link #getFavorite()} without chain call utility. */ + protected final void internalSetFavorite(test.openworld.deep.base.Bird value) { + _listener.beforeSet(this, FAVORITE__PROP, value); + _favorite = value; + _listener.afterChanged(this, FAVORITE__PROP); + } + + @Override + public final boolean hasFavorite() { + return _favorite != null; + } + + @Override + public final java.util.List getBirds() { + return _birds; + } + + @Override + public test.openworld.deep.base.Zoo setBirds(java.util.List value) { + internalSetBirds(value); + return this; + } + + /** Internal setter for {@link #getBirds()} without chain call utility. */ + protected final void internalSetBirds(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'birds' cannot be null."); + _birds.clear(); + _birds.addAll(value); + } + + @Override + public test.openworld.deep.base.Zoo addBird(test.openworld.deep.base.Bird value) { + internalAddBird(value); + return this; + } + + /** Implementation of {@link #addBird(test.openworld.deep.base.Bird)} without chain call utility. */ + protected final void internalAddBird(test.openworld.deep.base.Bird value) { + _birds.add(value); + } + + @Override + public final void removeBird(test.openworld.deep.base.Bird value) { + _birds.remove(value); + } + + @Override + public final test.openworld.deep.base.Zoo.Aviary getAviary() { + return _aviary; + } + + @Override + public test.openworld.deep.base.Zoo setAviary(test.openworld.deep.base.Zoo.Aviary value) { + internalSetAviary(value); + return this; + } + + /** Internal setter for {@link #getAviary()} without chain call utility. */ + protected final void internalSetAviary(test.openworld.deep.base.Zoo.Aviary value) { + _listener.beforeSet(this, AVIARY__PROP, value); + _aviary = value; + _listener.afterChanged(this, AVIARY__PROP); + } + + @Override + public final boolean hasAviary() { + return _aviary != null; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.openworld.deep.base.Zoo registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.openworld.deep.base.Zoo unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return ZOO__TYPE; + } + + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + STAR__PROP, + ANIMALS__PROP, + FAVORITE__PROP, + BIRDS__PROP, + AVIARY__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case STAR__PROP: return getStar(); + case ANIMALS__PROP: return getAnimals(); + case FAVORITE__PROP: return getFavorite(); + case BIRDS__PROP: return getBirds(); + case AVIARY__PROP: return getAviary(); + default: return test.openworld.deep.base.Zoo.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case STAR__PROP: internalSetStar((test.openworld.deep.base.Animal) value); break; + case ANIMALS__PROP: internalSetAnimals(de.haumacher.msgbuf.util.Conversions.asList(test.openworld.deep.base.Animal.class, value)); break; + case FAVORITE__PROP: internalSetFavorite((test.openworld.deep.base.Bird) value); break; + case BIRDS__PROP: internalSetBirds(de.haumacher.msgbuf.util.Conversions.asList(test.openworld.deep.base.Bird.class, value)); break; + case AVIARY__PROP: internalSetAviary((test.openworld.deep.base.Zoo.Aviary) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + if (hasStar()) { + out.name(STAR__PROP); + getStar().writeTo(out); + } + out.name(ANIMALS__PROP); + out.beginArray(); + for (test.openworld.deep.base.Animal x : getAnimals()) { + x.writeTo(out); + } + out.endArray(); + if (hasFavorite()) { + out.name(FAVORITE__PROP); + getFavorite().writeTo(out); + } + out.name(BIRDS__PROP); + out.beginArray(); + for (test.openworld.deep.base.Bird x : getBirds()) { + x.writeTo(out); + } + out.endArray(); + if (hasAviary()) { + out.name(AVIARY__PROP); + getAviary().writeTo(out); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case STAR__PROP: setStar(test.openworld.deep.base.Animal.readAnimal(in)); break; + case ANIMALS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.openworld.deep.base.Animal.readAnimal(in)); + } + in.endArray(); + setAnimals(newValue); + } + break; + case FAVORITE__PROP: setFavorite(test.openworld.deep.base.Bird.readBird(in)); break; + case BIRDS__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.openworld.deep.base.Bird.readBird(in)); + } + in.endArray(); + setBirds(newValue); + } + break; + case AVIARY__PROP: setAviary(test.openworld.deep.base.Zoo.Aviary.readAviary(in)); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.base.Zoo} type. */ + public static final String ZOO__XML_ELEMENT = "zoo"; + + /** XML attribute or element name of a {@link #getStar} property. */ + private static final String STAR__XML_ATTR = "star"; + + /** XML attribute or element name of a {@link #getAnimals} property. */ + private static final String ANIMALS__XML_ATTR = "animals"; + + /** XML attribute or element name of a {@link #getFavorite} property. */ + private static final String FAVORITE__XML_ATTR = "favorite"; + + /** XML attribute or element name of a {@link #getBirds} property. */ + private static final String BIRDS__XML_ATTR = "birds"; + + /** XML attribute or element name of a {@link #getAviary} property. */ + private static final String AVIARY__XML_ATTR = "aviary"; + + @Override + public String getXmlTagName() { + return ZOO__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasStar()) { + out.writeStartElement(STAR__XML_ATTR); + getStar().writeTo(out); + out.writeEndElement(); + } + out.writeStartElement(ANIMALS__XML_ATTR); + for (test.openworld.deep.base.Animal element : getAnimals()) { + element.writeTo(out); + } + out.writeEndElement(); + if (hasFavorite()) { + out.writeStartElement(FAVORITE__XML_ATTR); + getFavorite().writeTo(out); + out.writeEndElement(); + } + out.writeStartElement(BIRDS__XML_ATTR); + for (test.openworld.deep.base.Bird element : getBirds()) { + element.writeTo(out); + } + out.writeEndElement(); + if (hasAviary()) { + out.writeStartElement(AVIARY__XML_ATTR); + getAviary().writeContent(out); + out.writeEndElement(); + } + } + + /** Creates a new {@link test.openworld.deep.base.Zoo} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Zoo_Impl readZoo_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Zoo_Impl result = new Zoo_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case STAR__XML_ATTR: { + in.nextTag(); + setStar(test.openworld.deep.base.impl.Animal_Impl.readAnimal_XmlContent(in)); + internalSkipUntilMatchingEndElement(in); + break; + } + case ANIMALS__XML_ATTR: { + internalReadAnimalsListXml(in); + break; + } + case FAVORITE__XML_ATTR: { + in.nextTag(); + setFavorite(test.openworld.deep.base.impl.Bird_Impl.readBird_XmlContent(in)); + internalSkipUntilMatchingEndElement(in); + break; + } + case BIRDS__XML_ATTR: { + internalReadBirdsListXml(in); + break; + } + case AVIARY__XML_ATTR: { + setAviary(test.openworld.deep.base.impl.Zoo_Impl.Aviary_Impl.readAviary_XmlContent(in)); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadAnimalsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addAnimal(test.openworld.deep.base.impl.Animal_Impl.readAnimal_XmlContent(in)); + } + } + + private void internalReadBirdsListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addBird(test.openworld.deep.base.impl.Bird_Impl.readBird_XmlContent(in)); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Ext1Types.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Ext1Types.java new file mode 100644 index 00000000..2d9532fe --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Ext1Types.java @@ -0,0 +1,24 @@ +package test.openworld.deep.ext1; + +/** + * Registration of extension types for the OpenWorld protocol. + */ +public class Ext1Types implements de.haumacher.msgbuf.data.TypeRegistration { + + @Override + public void register() { + test.openworld.deep.base.Animal.register(test.openworld.deep.ext1.Parrot.PARROT__TYPE, test.openworld.deep.ext1.Parrot::create); + test.openworld.deep.base.Animal.registerXml(test.openworld.deep.ext1.impl.Parrot_Impl.PARROT__XML_ELEMENT, test.openworld.deep.ext1.Parrot::create); + test.openworld.deep.base.Animal.register(test.openworld.deep.ext1.Trout.TROUT__TYPE, test.openworld.deep.ext1.Trout::create); + test.openworld.deep.base.Animal.registerXml(test.openworld.deep.ext1.impl.Trout_Impl.TROUT__XML_ELEMENT, test.openworld.deep.ext1.Trout::create); + test.openworld.deep.base.Habitat.Plant.register(test.openworld.deep.ext1.Forest.Oak.OAK__TYPE, test.openworld.deep.ext1.Forest.Oak::create); + test.openworld.deep.base.Habitat.Plant.registerXml(test.openworld.deep.ext1.impl.Forest_Impl.Oak_Impl.OAK__XML_ELEMENT, test.openworld.deep.ext1.Forest.Oak::create); + } + + /** + * Explicit initialization for GWT or manual use. + */ + public static void init() { + new Ext1Types().register(); + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Fish.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Fish.java new file mode 100644 index 00000000..07a58f32 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Fish.java @@ -0,0 +1,65 @@ +package test.openworld.deep.ext1; + +/** + * Abstract intermediate declared in an extension file: a sibling subtree of Bird. + */ +public interface Fish extends test.openworld.deep.base.Animal { + + /** Visitor interface for the {@link test.openworld.deep.ext1.Fish} hierarchy.*/ + public interface Visitor { + + /** Visit case for {@link test.openworld.deep.ext1.Trout}.*/ + R visit(test.openworld.deep.ext1.Trout self, A arg) throws E; + + /** Fallback for visiting subtypes not known at compile time. */ + R visitDefault(test.openworld.deep.ext1.Fish self, A arg) throws E; + + } + + /** @see #getFins() */ + String FINS__PROP = "fins"; + + int getFins(); + + /** + * @see #getFins() + */ + test.openworld.deep.ext1.Fish setFins(int value); + + @Override + test.openworld.deep.ext1.Fish setName(String value); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.ext1.Fish readFish(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.ext1.Fish result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case Trout.TROUT__TYPE: result = test.openworld.deep.ext1.Trout.readTrout(in); break; + default: { + de.haumacher.msgbuf.data.TypeRegistryLoader.ensureLoaded(); + de.haumacher.msgbuf.data.Factory factory = test.openworld.deep.base.Animal.REGISTRY.get(type); + test.openworld.deep.base.Animal instance = factory == null ? null : factory.create(); + if (instance instanceof test.openworld.deep.ext1.Fish) { + result = (test.openworld.deep.ext1.Fish) instance; + result.readContent(in); + } else { + in.skipValue(); + result = null; + } + } break; + } + in.endArray(); + return result; + } + + /** Creates a new {@link Fish} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Fish readFish(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.ext1.impl.Fish_Impl.readFish_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Forest.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Forest.java new file mode 100644 index 00000000..78dcbcb4 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Forest.java @@ -0,0 +1,87 @@ +package test.openworld.deep.ext1; + +/** + * Nested leaf of a nested hierarchy of another file. + */ +public interface Forest extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + public interface Oak extends test.openworld.deep.base.Habitat.Tree { + + /** Extended visitor that can handle {@link Oak}. */ + public interface Visitor extends test.openworld.deep.base.Habitat.Tree.Visitor { + + /** Visit case for {@link Oak}. */ + R visit(test.openworld.deep.ext1.Forest.Oak self, A arg) throws E; + + } + + /** + * Creates a {@link test.openworld.deep.ext1.Forest.Oak} instance. + */ + static test.openworld.deep.ext1.Forest.Oak create() { + return new test.openworld.deep.ext1.impl.Forest_Impl.Oak_Impl(); + } + + /** Identifier for the {@link test.openworld.deep.ext1.Forest.Oak} type in JSON format. */ + String OAK__TYPE = "Oak"; + + /** @see #getAge() */ + String AGE__PROP = "age"; + + int getAge(); + + /** + * @see #getAge() + */ + test.openworld.deep.ext1.Forest.Oak setAge(int value); + + @Override + test.openworld.deep.ext1.Forest.Oak setHeight(int value); + + @Override + test.openworld.deep.ext1.Forest.Oak setSpecies(String value); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.ext1.Forest.Oak readOak(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.ext1.impl.Forest_Impl.Oak_Impl result = new test.openworld.deep.ext1.impl.Forest_Impl.Oak_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Oak} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Oak readOak(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.ext1.impl.Forest_Impl.Oak_Impl.readOak_XmlContent(in); + } + + } + + /** + * Creates a {@link test.openworld.deep.ext1.Forest} instance. + */ + static test.openworld.deep.ext1.Forest create() { + return new test.openworld.deep.ext1.impl.Forest_Impl(); + } + + /** Identifier for the {@link test.openworld.deep.ext1.Forest} type in JSON format. */ + String FOREST__TYPE = "Forest"; + + @Override + public test.openworld.deep.ext1.Forest registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.openworld.deep.ext1.Forest unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.ext1.Forest readForest(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.ext1.impl.Forest_Impl result = new test.openworld.deep.ext1.impl.Forest_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Forest} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Forest readForest(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.ext1.impl.Forest_Impl.readForest_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Parrot.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Parrot.java new file mode 100644 index 00000000..f45e9d51 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Parrot.java @@ -0,0 +1,55 @@ +package test.openworld.deep.ext1; + +/** + * Leaf of another file below an abstract intermediate of the base file. + */ +public interface Parrot extends test.openworld.deep.base.Bird { + + /** Extended visitor that can handle {@link Parrot}. */ + public interface Visitor extends test.openworld.deep.base.Bird.Visitor { + + /** Visit case for {@link Parrot}. */ + R visit(test.openworld.deep.ext1.Parrot self, A arg) throws E; + + } + + /** + * Creates a {@link test.openworld.deep.ext1.Parrot} instance. + */ + static test.openworld.deep.ext1.Parrot create() { + return new test.openworld.deep.ext1.impl.Parrot_Impl(); + } + + /** Identifier for the {@link test.openworld.deep.ext1.Parrot} type in JSON format. */ + String PARROT__TYPE = "Parrot"; + + /** @see #getWord() */ + String WORD__PROP = "word"; + + String getWord(); + + /** + * @see #getWord() + */ + test.openworld.deep.ext1.Parrot setWord(String value); + + @Override + test.openworld.deep.ext1.Parrot setWingspan(double value); + + @Override + test.openworld.deep.ext1.Parrot setName(String value); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.ext1.Parrot readParrot(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.ext1.impl.Parrot_Impl result = new test.openworld.deep.ext1.impl.Parrot_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Parrot} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Parrot readParrot(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.ext1.impl.Parrot_Impl.readParrot_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Pond.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Pond.java new file mode 100644 index 00000000..70a86f9e --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Pond.java @@ -0,0 +1,72 @@ +package test.openworld.deep.ext1; + +/** + * Holder of values of the intermediate of this file. + */ +public interface Pond extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.openworld.deep.ext1.Pond} instance. + */ + static test.openworld.deep.ext1.Pond create() { + return new test.openworld.deep.ext1.impl.Pond_Impl(); + } + + /** Identifier for the {@link test.openworld.deep.ext1.Pond} type in JSON format. */ + String POND__TYPE = "Pond"; + + /** @see #getKing() */ + String KING__PROP = "king"; + + /** @see #getSchool() */ + String SCHOOL__PROP = "school"; + + test.openworld.deep.ext1.Fish getKing(); + + /** + * @see #getKing() + */ + test.openworld.deep.ext1.Pond setKing(test.openworld.deep.ext1.Fish value); + + /** + * Checks, whether {@link #getKing()} has a value. + */ + boolean hasKing(); + + java.util.List getSchool(); + + /** + * @see #getSchool() + */ + test.openworld.deep.ext1.Pond setSchool(java.util.List value); + + /** + * Adds a value to the {@link #getSchool()} list. + */ + test.openworld.deep.ext1.Pond addSchool(test.openworld.deep.ext1.Fish value); + + /** + * Removes a value from the {@link #getSchool()} list. + */ + void removeSchool(test.openworld.deep.ext1.Fish value); + + @Override + public test.openworld.deep.ext1.Pond registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.openworld.deep.ext1.Pond unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.ext1.Pond readPond(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.ext1.impl.Pond_Impl result = new test.openworld.deep.ext1.impl.Pond_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Pond} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Pond readPond(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.ext1.impl.Pond_Impl.readPond_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Trout.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Trout.java new file mode 100644 index 00000000..ac26b47b --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/Trout.java @@ -0,0 +1,47 @@ +package test.openworld.deep.ext1; + +/** + * Leaf of the extension file below its own intermediate. + */ +public interface Trout extends test.openworld.deep.ext1.Fish { + + /** + * Creates a {@link test.openworld.deep.ext1.Trout} instance. + */ + static test.openworld.deep.ext1.Trout create() { + return new test.openworld.deep.ext1.impl.Trout_Impl(); + } + + /** Identifier for the {@link test.openworld.deep.ext1.Trout} type in JSON format. */ + String TROUT__TYPE = "Trout"; + + /** @see #isRainbow() */ + String RAINBOW__PROP = "rainbow"; + + boolean isRainbow(); + + /** + * @see #isRainbow() + */ + test.openworld.deep.ext1.Trout setRainbow(boolean value); + + @Override + test.openworld.deep.ext1.Trout setFins(int value); + + @Override + test.openworld.deep.ext1.Trout setName(String value); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.ext1.Trout readTrout(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.ext1.impl.Trout_Impl result = new test.openworld.deep.ext1.impl.Trout_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Trout} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Trout readTrout(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.ext1.impl.Trout_Impl.readTrout_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/ext1.proto b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/ext1.proto new file mode 100644 index 00000000..8e15bcd9 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/ext1.proto @@ -0,0 +1,35 @@ +package test.openworld.deep.ext1; + +import "../base/base.proto"; + +/* Declares an abstract intermediate that is extended in another file. */ +option OpenWorld; + +/** Leaf of another file below an abstract intermediate of the base file. */ +message Parrot extends test.openworld.deep.base.Bird { + string word; +} + +/** Abstract intermediate declared in an extension file: a sibling subtree of Bird. */ +abstract message Fish extends test.openworld.deep.base.Animal { + int32 fins; +} + +/** Leaf of the extension file below its own intermediate. */ +message Trout extends Fish { + bool rainbow; +} + +/** Holder of values of the intermediate of this file. */ +message Pond { + Fish king; + + repeated Fish school; +} + +/** Nested leaf of a nested hierarchy of another file. */ +message Forest { + message Oak extends test.openworld.deep.base.Habitat.Tree { + int32 age; + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Fish_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Fish_Impl.java new file mode 100644 index 00000000..07f1d1d7 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Fish_Impl.java @@ -0,0 +1,178 @@ +package test.openworld.deep.ext1.impl; + +/** + * Implementation of {@link test.openworld.deep.ext1.Fish}. + */ +public abstract class Fish_Impl extends test.openworld.deep.base.impl.Animal_Impl implements test.openworld.deep.ext1.Fish { + + private int _fins = 0; + + /** + * Creates a {@link Fish_Impl} instance. + */ + public Fish_Impl() { + super(); + } + + @Override + public final int getFins() { + return _fins; + } + + @Override + public test.openworld.deep.ext1.Fish setFins(int value) { + internalSetFins(value); + return this; + } + + /** Internal setter for {@link #getFins()} without chain call utility. */ + protected final void internalSetFins(int value) { + _listener.beforeSet(this, FINS__PROP, value); + _fins = value; + _listener.afterChanged(this, FINS__PROP); + } + + @Override + public test.openworld.deep.ext1.Fish setName(String value) { + internalSetName(value); + return this; + } + + @SuppressWarnings("hiding") + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + FINS__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.openworld.deep.base.impl.Animal_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.openworld.deep.base.impl.Animal_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case FINS__PROP: return getFins(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case FINS__PROP: internalSetFins((int) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(FINS__PROP); + out.value(getFins()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case FINS__PROP: setFins(in.nextInt()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.ext1.Fish} type. */ + public static final String FISH__XML_ELEMENT = "fish"; + + /** XML attribute or element name of a {@link #getFins} property. */ + private static final String FINS__XML_ATTR = "fins"; + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(FINS__XML_ATTR, Integer.toString(getFins())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.openworld.deep.ext1.Fish} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Fish_Impl readFish_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case Trout_Impl.TROUT__XML_ELEMENT: { + return test.openworld.deep.ext1.impl.Trout_Impl.readTrout_XmlContent(in); + } + + default: { + de.haumacher.msgbuf.data.Factory factory = test.openworld.deep.base.Animal.XML_REGISTRY.get(in.getLocalName()); + test.openworld.deep.base.Animal instance = factory == null ? null : factory.create(); + if (instance instanceof Fish_Impl) { + Fish_Impl result = (Fish_Impl) instance; + result.readContentXml(in); + return result; + } + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case FINS__XML_ATTR: { + setFins(Integer.parseInt(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case FINS__XML_ATTR: { + setFins(Integer.parseInt(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public final R visit(test.openworld.deep.base.Animal.Visitor v, A arg) throws E { + if (v instanceof test.openworld.deep.ext1.Fish.Visitor) { + return visit((test.openworld.deep.ext1.Fish.Visitor) v, arg); + } + return v.visitDefault(this, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Forest_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Forest_Impl.java new file mode 100644 index 00000000..22b72524 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Forest_Impl.java @@ -0,0 +1,312 @@ +package test.openworld.deep.ext1.impl; + +/** + * Implementation of {@link test.openworld.deep.ext1.Forest}. + */ +public class Forest_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.openworld.deep.ext1.Forest { + /** + * Implementation of {@link test.openworld.deep.ext1.Forest.Oak}. + */ + public static class Oak_Impl extends test.openworld.deep.base.impl.Habitat_Impl.Tree_Impl implements test.openworld.deep.ext1.Forest.Oak { + + private int _age = 0; + + /** + * Creates a {@link Oak_Impl} instance. + * + * @see test.openworld.deep.ext1.Forest.Oak#create() + */ + public Oak_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return null; + } + + @Override + public final int getAge() { + return _age; + } + + @Override + public test.openworld.deep.ext1.Forest.Oak setAge(int value) { + internalSetAge(value); + return this; + } + + /** Internal setter for {@link #getAge()} without chain call utility. */ + protected final void internalSetAge(int value) { + _listener.beforeSet(this, AGE__PROP, value); + _age = value; + _listener.afterChanged(this, AGE__PROP); + } + + @Override + public test.openworld.deep.ext1.Forest.Oak setHeight(int value) { + internalSetHeight(value); + return this; + } + + @Override + public test.openworld.deep.ext1.Forest.Oak setSpecies(String value) { + internalSetSpecies(value); + return this; + } + + @Override + public String jsonType() { + return OAK__TYPE; + } + + @SuppressWarnings("hiding") + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + AGE__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.openworld.deep.base.impl.Habitat_Impl.Tree_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.openworld.deep.base.impl.Habitat_Impl.Tree_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case AGE__PROP: return getAge(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case AGE__PROP: internalSetAge((int) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(AGE__PROP); + out.value(getAge()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case AGE__PROP: setAge(in.nextInt()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.ext1.Forest.Oak} type. */ + public static final String OAK__XML_ELEMENT = "oak"; + + /** XML attribute or element name of a {@link #getAge} property. */ + private static final String AGE__XML_ATTR = "age"; + + @Override + public String getXmlTagName() { + return OAK__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(AGE__XML_ATTR, Integer.toString(getAge())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.openworld.deep.ext1.Forest.Oak} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Oak_Impl readOak_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Oak_Impl result = new Oak_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case AGE__XML_ATTR: { + setAge(Integer.parseInt(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case AGE__XML_ATTR: { + setAge(Integer.parseInt(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.openworld.deep.base.Habitat.Tree.Visitor v, A arg) throws E { + if (v instanceof test.openworld.deep.ext1.Forest.Oak.Visitor) { + return ((test.openworld.deep.ext1.Forest.Oak.Visitor) v).visit(this, arg); + } + return v.visitDefault(this, arg); + } + + } + + /** + * Creates a {@link Forest_Impl} instance. + * + * @see test.openworld.deep.ext1.Forest#create() + */ + public Forest_Impl() { + super(); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.openworld.deep.ext1.Forest registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.openworld.deep.ext1.Forest unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return FOREST__TYPE; + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + /** XML element name representing a {@link test.openworld.deep.ext1.Forest} type. */ + public static final String FOREST__XML_ELEMENT = "forest"; + + @Override + public String getXmlTagName() { + return FOREST__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.openworld.deep.ext1.Forest} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Forest_Impl readForest_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Forest_Impl result = new Forest_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Parrot_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Parrot_Impl.java new file mode 100644 index 00000000..dea0636b --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Parrot_Impl.java @@ -0,0 +1,187 @@ +package test.openworld.deep.ext1.impl; + +/** + * Implementation of {@link test.openworld.deep.ext1.Parrot}. + */ +public class Parrot_Impl extends test.openworld.deep.base.impl.Bird_Impl implements test.openworld.deep.ext1.Parrot { + + private String _word = ""; + + /** + * Creates a {@link Parrot_Impl} instance. + * + * @see test.openworld.deep.ext1.Parrot#create() + */ + public Parrot_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return null; + } + + @Override + public final String getWord() { + return _word; + } + + @Override + public test.openworld.deep.ext1.Parrot setWord(String value) { + internalSetWord(value); + return this; + } + + /** Internal setter for {@link #getWord()} without chain call utility. */ + protected final void internalSetWord(String value) { + _listener.beforeSet(this, WORD__PROP, value); + _word = value; + _listener.afterChanged(this, WORD__PROP); + } + + @Override + public test.openworld.deep.ext1.Parrot setWingspan(double value) { + internalSetWingspan(value); + return this; + } + + @Override + public test.openworld.deep.ext1.Parrot setName(String value) { + internalSetName(value); + return this; + } + + @Override + public String jsonType() { + return PARROT__TYPE; + } + + @SuppressWarnings("hiding") + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + WORD__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.openworld.deep.base.impl.Bird_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.openworld.deep.base.impl.Bird_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case WORD__PROP: return getWord(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case WORD__PROP: internalSetWord((String) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(WORD__PROP); + out.value(getWord()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case WORD__PROP: setWord(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.ext1.Parrot} type. */ + public static final String PARROT__XML_ELEMENT = "parrot"; + + /** XML attribute or element name of a {@link #getWord} property. */ + private static final String WORD__XML_ATTR = "word"; + + @Override + public String getXmlTagName() { + return PARROT__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(WORD__XML_ATTR, getWord()); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.openworld.deep.ext1.Parrot} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Parrot_Impl readParrot_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Parrot_Impl result = new Parrot_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case WORD__XML_ATTR: { + setWord(value); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case WORD__XML_ATTR: { + setWord(in.getElementText()); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.openworld.deep.base.Bird.Visitor v, A arg) throws E { + if (v instanceof test.openworld.deep.ext1.Parrot.Visitor) { + return ((test.openworld.deep.ext1.Parrot.Visitor) v).visit(this, arg); + } + return v.visitDefault(this, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Pond_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Pond_Impl.java new file mode 100644 index 00000000..4c35571d --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Pond_Impl.java @@ -0,0 +1,315 @@ +package test.openworld.deep.ext1.impl; + +/** + * Implementation of {@link test.openworld.deep.ext1.Pond}. + */ +public class Pond_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.openworld.deep.ext1.Pond { + + private test.openworld.deep.ext1.Fish _king = null; + + private final java.util.List _school = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.openworld.deep.ext1.Fish element) { + _listener.beforeAdd(Pond_Impl.this, SCHOOL__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.openworld.deep.ext1.Fish element) { + _listener.afterRemove(Pond_Impl.this, SCHOOL__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Pond_Impl.this, SCHOOL__PROP); + } + }; + + /** + * Creates a {@link Pond_Impl} instance. + * + * @see test.openworld.deep.ext1.Pond#create() + */ + public Pond_Impl() { + super(); + } + + @Override + public final test.openworld.deep.ext1.Fish getKing() { + return _king; + } + + @Override + public test.openworld.deep.ext1.Pond setKing(test.openworld.deep.ext1.Fish value) { + internalSetKing(value); + return this; + } + + /** Internal setter for {@link #getKing()} without chain call utility. */ + protected final void internalSetKing(test.openworld.deep.ext1.Fish value) { + _listener.beforeSet(this, KING__PROP, value); + _king = value; + _listener.afterChanged(this, KING__PROP); + } + + @Override + public final boolean hasKing() { + return _king != null; + } + + @Override + public final java.util.List getSchool() { + return _school; + } + + @Override + public test.openworld.deep.ext1.Pond setSchool(java.util.List value) { + internalSetSchool(value); + return this; + } + + /** Internal setter for {@link #getSchool()} without chain call utility. */ + protected final void internalSetSchool(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'school' cannot be null."); + _school.clear(); + _school.addAll(value); + } + + @Override + public test.openworld.deep.ext1.Pond addSchool(test.openworld.deep.ext1.Fish value) { + internalAddSchool(value); + return this; + } + + /** Implementation of {@link #addSchool(test.openworld.deep.ext1.Fish)} without chain call utility. */ + protected final void internalAddSchool(test.openworld.deep.ext1.Fish value) { + _school.add(value); + } + + @Override + public final void removeSchool(test.openworld.deep.ext1.Fish value) { + _school.remove(value); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.openworld.deep.ext1.Pond registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.openworld.deep.ext1.Pond unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return POND__TYPE; + } + + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + KING__PROP, + SCHOOL__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case KING__PROP: return getKing(); + case SCHOOL__PROP: return getSchool(); + default: return test.openworld.deep.ext1.Pond.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case KING__PROP: internalSetKing((test.openworld.deep.ext1.Fish) value); break; + case SCHOOL__PROP: internalSetSchool(de.haumacher.msgbuf.util.Conversions.asList(test.openworld.deep.ext1.Fish.class, value)); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + if (hasKing()) { + out.name(KING__PROP); + getKing().writeTo(out); + } + out.name(SCHOOL__PROP); + out.beginArray(); + for (test.openworld.deep.ext1.Fish x : getSchool()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case KING__PROP: setKing(test.openworld.deep.ext1.Fish.readFish(in)); break; + case SCHOOL__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.openworld.deep.ext1.Fish.readFish(in)); + } + in.endArray(); + setSchool(newValue); + } + break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.ext1.Pond} type. */ + public static final String POND__XML_ELEMENT = "pond"; + + /** XML attribute or element name of a {@link #getKing} property. */ + private static final String KING__XML_ATTR = "king"; + + /** XML attribute or element name of a {@link #getSchool} property. */ + private static final String SCHOOL__XML_ATTR = "school"; + + @Override + public String getXmlTagName() { + return POND__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasKing()) { + out.writeStartElement(KING__XML_ATTR); + getKing().writeTo(out); + out.writeEndElement(); + } + out.writeStartElement(SCHOOL__XML_ATTR); + for (test.openworld.deep.ext1.Fish element : getSchool()) { + element.writeTo(out); + } + out.writeEndElement(); + } + + /** Creates a new {@link test.openworld.deep.ext1.Pond} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Pond_Impl readPond_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Pond_Impl result = new Pond_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case KING__XML_ATTR: { + in.nextTag(); + setKing(test.openworld.deep.ext1.impl.Fish_Impl.readFish_XmlContent(in)); + internalSkipUntilMatchingEndElement(in); + break; + } + case SCHOOL__XML_ATTR: { + internalReadSchoolListXml(in); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + + private void internalReadSchoolListXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + + addSchool(test.openworld.deep.ext1.impl.Fish_Impl.readFish_XmlContent(in)); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Trout_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Trout_Impl.java new file mode 100644 index 00000000..493eaf7e --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext1/impl/Trout_Impl.java @@ -0,0 +1,184 @@ +package test.openworld.deep.ext1.impl; + +/** + * Implementation of {@link test.openworld.deep.ext1.Trout}. + */ +public class Trout_Impl extends test.openworld.deep.ext1.impl.Fish_Impl implements test.openworld.deep.ext1.Trout { + + private boolean _rainbow = false; + + /** + * Creates a {@link Trout_Impl} instance. + * + * @see test.openworld.deep.ext1.Trout#create() + */ + public Trout_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return null; + } + + @Override + public final boolean isRainbow() { + return _rainbow; + } + + @Override + public test.openworld.deep.ext1.Trout setRainbow(boolean value) { + internalSetRainbow(value); + return this; + } + + /** Internal setter for {@link #isRainbow()} without chain call utility. */ + protected final void internalSetRainbow(boolean value) { + _listener.beforeSet(this, RAINBOW__PROP, value); + _rainbow = value; + _listener.afterChanged(this, RAINBOW__PROP); + } + + @Override + public test.openworld.deep.ext1.Trout setFins(int value) { + internalSetFins(value); + return this; + } + + @Override + public test.openworld.deep.ext1.Trout setName(String value) { + internalSetName(value); + return this; + } + + @Override + public String jsonType() { + return TROUT__TYPE; + } + + @SuppressWarnings("hiding") + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + RAINBOW__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.openworld.deep.ext1.impl.Fish_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.openworld.deep.ext1.impl.Fish_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case RAINBOW__PROP: return isRainbow(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case RAINBOW__PROP: internalSetRainbow((boolean) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(RAINBOW__PROP); + out.value(isRainbow()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case RAINBOW__PROP: setRainbow(in.nextBoolean()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.ext1.Trout} type. */ + public static final String TROUT__XML_ELEMENT = "trout"; + + /** XML attribute or element name of a {@link #isRainbow} property. */ + private static final String RAINBOW__XML_ATTR = "rainbow"; + + @Override + public String getXmlTagName() { + return TROUT__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(RAINBOW__XML_ATTR, Boolean.toString(isRainbow())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.openworld.deep.ext1.Trout} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Trout_Impl readTrout_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Trout_Impl result = new Trout_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case RAINBOW__XML_ATTR: { + setRainbow(Boolean.parseBoolean(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case RAINBOW__XML_ATTR: { + setRainbow(Boolean.parseBoolean(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.openworld.deep.ext1.Fish.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Eagle.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Eagle.java new file mode 100644 index 00000000..b465b27c --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Eagle.java @@ -0,0 +1,47 @@ +package test.openworld.deep.ext2; + +public interface Eagle extends test.openworld.deep.ext2.Raptor { + + /** + * Creates a {@link test.openworld.deep.ext2.Eagle} instance. + */ + static test.openworld.deep.ext2.Eagle create() { + return new test.openworld.deep.ext2.impl.Eagle_Impl(); + } + + /** Identifier for the {@link test.openworld.deep.ext2.Eagle} type in JSON format. */ + String EAGLE__TYPE = "Eagle"; + + /** @see #isBald() */ + String BALD__PROP = "bald"; + + boolean isBald(); + + /** + * @see #isBald() + */ + test.openworld.deep.ext2.Eagle setBald(boolean value); + + @Override + test.openworld.deep.ext2.Eagle setSpeed(double value); + + @Override + test.openworld.deep.ext2.Eagle setWingspan(double value); + + @Override + test.openworld.deep.ext2.Eagle setName(String value); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.ext2.Eagle readEagle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.ext2.impl.Eagle_Impl result = new test.openworld.deep.ext2.impl.Eagle_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Eagle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Eagle readEagle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.ext2.impl.Eagle_Impl.readEagle_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Ext2Types.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Ext2Types.java new file mode 100644 index 00000000..0a9ec540 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Ext2Types.java @@ -0,0 +1,22 @@ +package test.openworld.deep.ext2; + +/** + * Registration of extension types for the OpenWorld protocol. + */ +public class Ext2Types implements de.haumacher.msgbuf.data.TypeRegistration { + + @Override + public void register() { + test.openworld.deep.base.Animal.register(test.openworld.deep.ext2.Shark.SHARK__TYPE, test.openworld.deep.ext2.Shark::create); + test.openworld.deep.base.Animal.registerXml(test.openworld.deep.ext2.impl.Shark_Impl.SHARK__XML_ELEMENT, test.openworld.deep.ext2.Shark::create); + test.openworld.deep.base.Animal.register(test.openworld.deep.ext2.Eagle.EAGLE__TYPE, test.openworld.deep.ext2.Eagle::create); + test.openworld.deep.base.Animal.registerXml(test.openworld.deep.ext2.impl.Eagle_Impl.EAGLE__XML_ELEMENT, test.openworld.deep.ext2.Eagle::create); + } + + /** + * Explicit initialization for GWT or manual use. + */ + public static void init() { + new Ext2Types().register(); + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Raptor.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Raptor.java new file mode 100644 index 00000000..8bcd80cf --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Raptor.java @@ -0,0 +1,54 @@ +package test.openworld.deep.ext2; + +/** + * Abstract intermediate at depth three, below the intermediate of the base file. + */ +public interface Raptor extends test.openworld.deep.base.Bird { + + /** Visitor interface for the {@link test.openworld.deep.ext2.Raptor} hierarchy.*/ + public interface Visitor { + + /** Visit case for {@link test.openworld.deep.ext2.Eagle}.*/ + R visit(test.openworld.deep.ext2.Eagle self, A arg) throws E; + + } + + /** @see #getSpeed() */ + String SPEED__PROP = "speed"; + + double getSpeed(); + + /** + * @see #getSpeed() + */ + test.openworld.deep.ext2.Raptor setSpeed(double value); + + @Override + test.openworld.deep.ext2.Raptor setWingspan(double value); + + @Override + test.openworld.deep.ext2.Raptor setName(String value); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.ext2.Raptor readRaptor(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.ext2.Raptor result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case Eagle.EAGLE__TYPE: result = test.openworld.deep.ext2.Eagle.readEagle(in); break; + default: in.skipValue(); result = null; break; + } + in.endArray(); + return result; + } + + /** Creates a new {@link Raptor} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Raptor readRaptor(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.ext2.impl.Raptor_Impl.readRaptor_XmlContent(in); + } + + /** Accepts the given visitor. */ + public abstract R visit(Visitor v, A arg) throws E; + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Shark.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Shark.java new file mode 100644 index 00000000..b3e35136 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/Shark.java @@ -0,0 +1,55 @@ +package test.openworld.deep.ext2; + +/** + * Leaf of a second extension file below the intermediate of the first extension file. + */ +public interface Shark extends test.openworld.deep.ext1.Fish { + + /** Extended visitor that can handle {@link Shark}. */ + public interface Visitor extends test.openworld.deep.ext1.Fish.Visitor { + + /** Visit case for {@link Shark}. */ + R visit(test.openworld.deep.ext2.Shark self, A arg) throws E; + + } + + /** + * Creates a {@link test.openworld.deep.ext2.Shark} instance. + */ + static test.openworld.deep.ext2.Shark create() { + return new test.openworld.deep.ext2.impl.Shark_Impl(); + } + + /** Identifier for the {@link test.openworld.deep.ext2.Shark} type in JSON format. */ + String SHARK__TYPE = "Shark"; + + /** @see #getTeeth() */ + String TEETH__PROP = "teeth"; + + int getTeeth(); + + /** + * @see #getTeeth() + */ + test.openworld.deep.ext2.Shark setTeeth(int value); + + @Override + test.openworld.deep.ext2.Shark setFins(int value); + + @Override + test.openworld.deep.ext2.Shark setName(String value); + + /** Reads a new instance from the given reader. */ + static test.openworld.deep.ext2.Shark readShark(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.deep.ext2.impl.Shark_Impl result = new test.openworld.deep.ext2.impl.Shark_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Shark} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Shark readShark(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.deep.ext2.impl.Shark_Impl.readShark_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/ext2.proto b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/ext2.proto new file mode 100644 index 00000000..a0f7709f --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/ext2.proto @@ -0,0 +1,18 @@ +package test.openworld.deep.ext2; + +import "../base/base.proto"; +import "../ext1/ext1.proto"; + +/** Leaf of a second extension file below the intermediate of the first extension file. */ +message Shark extends test.openworld.deep.ext1.Fish { + int32 teeth; +} + +/** Abstract intermediate at depth three, below the intermediate of the base file. */ +abstract message Raptor extends test.openworld.deep.base.Bird { + double speed; +} + +message Eagle extends Raptor { + bool bald; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/impl/Eagle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/impl/Eagle_Impl.java new file mode 100644 index 00000000..35191233 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/impl/Eagle_Impl.java @@ -0,0 +1,190 @@ +package test.openworld.deep.ext2.impl; + +/** + * Implementation of {@link test.openworld.deep.ext2.Eagle}. + */ +public class Eagle_Impl extends test.openworld.deep.ext2.impl.Raptor_Impl implements test.openworld.deep.ext2.Eagle { + + private boolean _bald = false; + + /** + * Creates a {@link Eagle_Impl} instance. + * + * @see test.openworld.deep.ext2.Eagle#create() + */ + public Eagle_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return null; + } + + @Override + public final boolean isBald() { + return _bald; + } + + @Override + public test.openworld.deep.ext2.Eagle setBald(boolean value) { + internalSetBald(value); + return this; + } + + /** Internal setter for {@link #isBald()} without chain call utility. */ + protected final void internalSetBald(boolean value) { + _listener.beforeSet(this, BALD__PROP, value); + _bald = value; + _listener.afterChanged(this, BALD__PROP); + } + + @Override + public test.openworld.deep.ext2.Eagle setSpeed(double value) { + internalSetSpeed(value); + return this; + } + + @Override + public test.openworld.deep.ext2.Eagle setWingspan(double value) { + internalSetWingspan(value); + return this; + } + + @Override + public test.openworld.deep.ext2.Eagle setName(String value) { + internalSetName(value); + return this; + } + + @Override + public String jsonType() { + return EAGLE__TYPE; + } + + @SuppressWarnings("hiding") + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + BALD__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.openworld.deep.ext2.impl.Raptor_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.openworld.deep.ext2.impl.Raptor_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case BALD__PROP: return isBald(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case BALD__PROP: internalSetBald((boolean) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(BALD__PROP); + out.value(isBald()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case BALD__PROP: setBald(in.nextBoolean()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.ext2.Eagle} type. */ + public static final String EAGLE__XML_ELEMENT = "eagle"; + + /** XML attribute or element name of a {@link #isBald} property. */ + private static final String BALD__XML_ATTR = "bald"; + + @Override + public String getXmlTagName() { + return EAGLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(BALD__XML_ATTR, Boolean.toString(isBald())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.openworld.deep.ext2.Eagle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Eagle_Impl readEagle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Eagle_Impl result = new Eagle_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case BALD__XML_ATTR: { + setBald(Boolean.parseBoolean(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case BALD__XML_ATTR: { + setBald(Boolean.parseBoolean(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.openworld.deep.ext2.Raptor.Visitor v, A arg) throws E { + return v.visit(this, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/impl/Raptor_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/impl/Raptor_Impl.java new file mode 100644 index 00000000..7f1bb9df --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/impl/Raptor_Impl.java @@ -0,0 +1,177 @@ +package test.openworld.deep.ext2.impl; + +/** + * Implementation of {@link test.openworld.deep.ext2.Raptor}. + */ +public abstract class Raptor_Impl extends test.openworld.deep.base.impl.Bird_Impl implements test.openworld.deep.ext2.Raptor { + + private double _speed = 0.0d; + + /** + * Creates a {@link Raptor_Impl} instance. + */ + public Raptor_Impl() { + super(); + } + + @Override + public final double getSpeed() { + return _speed; + } + + @Override + public test.openworld.deep.ext2.Raptor setSpeed(double value) { + internalSetSpeed(value); + return this; + } + + /** Internal setter for {@link #getSpeed()} without chain call utility. */ + protected final void internalSetSpeed(double value) { + _listener.beforeSet(this, SPEED__PROP, value); + _speed = value; + _listener.afterChanged(this, SPEED__PROP); + } + + @Override + public test.openworld.deep.ext2.Raptor setWingspan(double value) { + internalSetWingspan(value); + return this; + } + + @Override + public test.openworld.deep.ext2.Raptor setName(String value) { + internalSetName(value); + return this; + } + + @SuppressWarnings("hiding") + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + SPEED__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.openworld.deep.base.impl.Bird_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.openworld.deep.base.impl.Bird_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case SPEED__PROP: return getSpeed(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case SPEED__PROP: internalSetSpeed((double) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(SPEED__PROP); + out.value(getSpeed()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case SPEED__PROP: setSpeed(in.nextDouble()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.ext2.Raptor} type. */ + public static final String RAPTOR__XML_ELEMENT = "raptor"; + + /** XML attribute or element name of a {@link #getSpeed} property. */ + private static final String SPEED__XML_ATTR = "speed"; + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(SPEED__XML_ATTR, Double.toString(getSpeed())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.openworld.deep.ext2.Raptor} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Raptor_Impl readRaptor_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case Eagle_Impl.EAGLE__XML_ELEMENT: { + return test.openworld.deep.ext2.impl.Eagle_Impl.readEagle_XmlContent(in); + } + + default: { + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case SPEED__XML_ATTR: { + setSpeed(Double.parseDouble(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case SPEED__XML_ATTR: { + setSpeed(Double.parseDouble(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public final R visit(test.openworld.deep.base.Bird.Visitor v, A arg) throws E { + if (v instanceof test.openworld.deep.ext2.Raptor.Visitor) { + return visit((test.openworld.deep.ext2.Raptor.Visitor) v, arg); + } + return v.visitDefault(this, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/impl/Shark_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/impl/Shark_Impl.java new file mode 100644 index 00000000..e9b51408 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/deep/ext2/impl/Shark_Impl.java @@ -0,0 +1,187 @@ +package test.openworld.deep.ext2.impl; + +/** + * Implementation of {@link test.openworld.deep.ext2.Shark}. + */ +public class Shark_Impl extends test.openworld.deep.ext1.impl.Fish_Impl implements test.openworld.deep.ext2.Shark { + + private int _teeth = 0; + + /** + * Creates a {@link Shark_Impl} instance. + * + * @see test.openworld.deep.ext2.Shark#create() + */ + public Shark_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return null; + } + + @Override + public final int getTeeth() { + return _teeth; + } + + @Override + public test.openworld.deep.ext2.Shark setTeeth(int value) { + internalSetTeeth(value); + return this; + } + + /** Internal setter for {@link #getTeeth()} without chain call utility. */ + protected final void internalSetTeeth(int value) { + _listener.beforeSet(this, TEETH__PROP, value); + _teeth = value; + _listener.afterChanged(this, TEETH__PROP); + } + + @Override + public test.openworld.deep.ext2.Shark setFins(int value) { + internalSetFins(value); + return this; + } + + @Override + public test.openworld.deep.ext2.Shark setName(String value) { + internalSetName(value); + return this; + } + + @Override + public String jsonType() { + return SHARK__TYPE; + } + + @SuppressWarnings("hiding") + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + TEETH__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.openworld.deep.ext1.impl.Fish_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.openworld.deep.ext1.impl.Fish_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case TEETH__PROP: return getTeeth(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case TEETH__PROP: internalSetTeeth((int) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(TEETH__PROP); + out.value(getTeeth()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case TEETH__PROP: setTeeth(in.nextInt()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.deep.ext2.Shark} type. */ + public static final String SHARK__XML_ELEMENT = "shark"; + + /** XML attribute or element name of a {@link #getTeeth} property. */ + private static final String TEETH__XML_ATTR = "teeth"; + + @Override + public String getXmlTagName() { + return SHARK__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(TEETH__XML_ATTR, Integer.toString(getTeeth())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.openworld.deep.ext2.Shark} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Shark_Impl readShark_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Shark_Impl result = new Shark_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case TEETH__XML_ATTR: { + setTeeth(Integer.parseInt(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case TEETH__XML_ATTR: { + setTeeth(Integer.parseInt(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + + @Override + public R visit(test.openworld.deep.ext1.Fish.Visitor v, A arg) throws E { + if (v instanceof test.openworld.deep.ext2.Shark.Visitor) { + return ((test.openworld.deep.ext2.Shark.Visitor) v).visit(this, arg); + } + return v.visitDefault(this, arg); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/ext1/Ext1Types.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/ext1/Ext1Types.java index ef69c776..1fe4cac1 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/ext1/Ext1Types.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/ext1/Ext1Types.java @@ -8,6 +8,7 @@ public class Ext1Types implements de.haumacher.msgbuf.data.TypeRegistration { @Override public void register() { test.openworld.base.SSEEvent.register(test.openworld.ext1.GraphPatchEvent.GRAPH_PATCH_EVENT__TYPE, test.openworld.ext1.GraphPatchEvent::create); + test.openworld.base.SSEEvent.registerXml(test.openworld.ext1.impl.GraphPatchEvent_Impl.GRAPH_PATCH_EVENT__XML_ELEMENT, test.openworld.ext1.GraphPatchEvent::create); } /** diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/ext2/Ext2Types.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/ext2/Ext2Types.java index 981d3565..91522e8d 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/ext2/Ext2Types.java +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/ext2/Ext2Types.java @@ -8,6 +8,7 @@ public class Ext2Types implements de.haumacher.msgbuf.data.TypeRegistration { @Override public void register() { test.openworld.base.SSEEvent.register(test.openworld.ext2.AnalyticsPatchEvent.ANALYTICS_PATCH_EVENT__TYPE, test.openworld.ext2.AnalyticsPatchEvent::create); + test.openworld.base.SSEEvent.registerXml(test.openworld.ext2.impl.AnalyticsPatchEvent_Impl.ANALYTICS_PATCH_EVENT__XML_ELEMENT, test.openworld.ext2.AnalyticsPatchEvent::create); } /** diff --git a/de.haumacher.msgbuf.generator/src/test/resources/META-INF/services/de.haumacher.msgbuf.data.TypeRegistration b/de.haumacher.msgbuf.generator/src/test/resources/META-INF/services/de.haumacher.msgbuf.data.TypeRegistration index a3eef857..e3a8b0c9 100644 --- a/de.haumacher.msgbuf.generator/src/test/resources/META-INF/services/de.haumacher.msgbuf.data.TypeRegistration +++ b/de.haumacher.msgbuf.generator/src/test/resources/META-INF/services/de.haumacher.msgbuf.data.TypeRegistration @@ -1,4 +1,6 @@ +test.openworld.deep.ext2.Ext2Types test.openworld.ext1.Ext1Types test.nested.owcount.OwcountTypes test.openworld.ext2.Ext2Types test.nested.owext.OwextTypes +test.openworld.deep.ext1.Ext1Types From c27f297b9cda4f6223983a8f35b359111e51f93b Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 17:46:39 +0200 Subject: [PATCH 201/207] Reject extensions across files whose options generate incompatible code. A specialization implements the abstract methods and overrides the generated methods of its generalization. When the files of the two disagreed on an option that shapes these methods, the generator produced code that did not compile (#37, #39, #40). A measured matrix over all file options, for a closed hierarchy split into files and for an OpenWorld hierarchy, gave the rule the validation now enforces. Both files must agree on the formats, NoVisitor, NoVisitorExceptions (with visitors), NoTypeKind and NoInterfaces. A specialization may drop listener or reflection support, but not add it. The only compiling case that is now rejected is NoJson on an OpenWorld extension alone: it wrote the extension without its own fields and could not read it back. Also following the #25 decision to reject inconsistent OpenWorld annotations, OpenWorld on a file whose hierarchy root is in a file without it (#38) and OpenWorld combined with SharedGraph or NoInterfaces (#41, before only printed) are rejected. NoVisitor now also suppresses the visitor of extension types (#39). Closes #37 Closes #38 Closes #39 Closes #40 Closes #41 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 8 + README.md | 9 +- .../haumacher/msgbuf/generator/Generator.java | 109 ++++++++- .../msgbuf/generator/MessageGenerator.java | 20 +- .../openworld/TestOpenWorldNoVisitor.java | 36 +++ .../test/openworld/novisitor/base/Circle.java | 41 ++++ .../test/openworld/novisitor/base/Shape.java | 85 +++++++ .../test/openworld/novisitor/base/base.proto | 13 + .../novisitor/base/impl/Circle_Impl.java | 173 ++++++++++++++ .../novisitor/base/impl/Shape_Impl.java | 223 ++++++++++++++++++ .../openworld/novisitor/ext/ExtTypes.java | 20 ++ .../test/openworld/novisitor/ext/Square.java | 41 ++++ .../test/openworld/novisitor/ext/ext.proto | 8 + .../novisitor/ext/impl/Square_Impl.java | 173 ++++++++++++++ .../test/validation/TestExtensionOptions.java | 75 ++++++ .../de.haumacher.msgbuf.data.TypeRegistration | 1 + .../reject/options/base/events.proto | 7 + .../resources/reject/options/base/quiet.proto | 9 + .../reject/options/ext/mismatch.proto | 15 ++ .../test/resources/reject/options/graph.proto | 9 + .../resources/reject/options/split/mid.proto | 8 + .../resources/reject/options/split/root.proto | 5 + 22 files changed, 1073 insertions(+), 15 deletions(-) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/TestOpenWorldNoVisitor.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/Circle.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/Shape.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/base.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/impl/Circle_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/impl/Shape_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/ExtTypes.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/Square.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/ext.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/impl/Square_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/validation/TestExtensionOptions.java create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/options/base/events.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/options/base/quiet.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/options/ext/mismatch.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/options/graph.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/options/split/mid.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/options/split/root.proto diff --git a/CHANGELOG.md b/CHANGELOG.md index 48ca58ad..d2863086 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,14 @@ are rejected with an error instead of crashing the generator. - **Nested specializations of the outer message** (#32): A message nested in its own generalization (e.g. `abstract message Expr { message Sum extends Expr {…} }`) crashed the generator with a `StackOverflowError`. +- **Consistent options across `extends`** (#37, #38, #39, #40, #41): A message that extends a message of another + file is rejected if the files disagree on the serialization formats, `NoVisitor`, `NoVisitorExceptions`, + `NoTypeKind` or `NoInterfaces`, or if it adds listener or reflection support its generalization lacks. These + combinations generated uncompilable code. The exception is `NoJson` (or `NoXml`) only on an OpenWorld extension + file: it compiled, but the extension type was written without its own fields and could not be read. It is rejected + now as well. `option OpenWorld` on a file whose hierarchy root is in a file without it, and `OpenWorld` combined + with `SharedGraph` or `NoInterfaces` (before only a message on the console), are rejected. `option NoVisitor` now + also suppresses the visitor of OpenWorld extension types. - **OpenWorld readers of abstract intermediates** (#26): The JSON reader of an abstract message below the root of an `option OpenWorld` hierarchy (e.g. `Bird` in `Animal > Bird > Parrot`, top-level or nested) no longer fails to compile. It reads the types of other files registered with the root, if they are specializations of the message; a diff --git a/README.md b/README.md index 3995477f..3c102b51 100644 --- a/README.md +++ b/README.md @@ -234,6 +234,12 @@ another file only if both files use `option SharedGraph`, or neither does. Enums `option SharedGraph`. `transient` fields and derived references (`@Container`, `@Reverse`) are not serialized, so they don't need these formats. +A message that extends a message of another file implements and overrides its generated methods. So both files must +agree on the serialization formats, `option NoVisitor`, `option NoVisitorExceptions`, `option NoTypeKind` and +`option NoInterfaces`. A specialization may be generated without the listener (`option NoListener`) or reflection +(`option NoReflection`) support of its generalization, but not with support its generalization lacks. The generator +rejects other combinations with an error naming both files. + ### `option NoXmlNames` Disables generation of constants for the XML format. @@ -327,7 +333,8 @@ itself be extended in further files, if the extension file declares `option Open Implications: - Implies `option NoBinary` (only JSON and XML serialization are supported) -- Cannot be combined with `option NoInterfaces` +- Cannot be combined with `option NoInterfaces` or `option SharedGraph` +- The root's file must declare `option OpenWorld` if any file of the hierarchy does - The generated `Visitor` interface includes a `visitDefault()` fallback method for unknown extension types - Extension types generate their own `Visitor` sub-interface with an `instanceof`-based dispatch diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java index 0872c8a9..21834e87 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java @@ -175,8 +175,9 @@ public void generate(GeneratorPlugin plugin) { buildSpecializations(file); } + List errors = new ArrayList<>(); for (DefinitionFile file : _files) { - validateOpenWorld(file); + validateOpenWorld(file, errors); } // Propagate NoBinary and NoTypeKind to extension files that extend OpenWorld bases @@ -184,10 +185,9 @@ public void generate(GeneratorPlugin plugin) { propagateOpenWorldOptions(file); } - List errors = new ArrayList<>(); for (DefinitionFile file : _files) { if (!_importedFiles.contains(file)) { - validateGeneralizations(file, errors); + validateGeneralizations(file, plugin, errors); } } if (!errors.isEmpty()) { @@ -315,7 +315,7 @@ private static String moduleSpecifier(File from, File to) { return relative.startsWith("../") ? relative : "./" + relative; } - private void validateOpenWorld(DefinitionFile file) { + private void validateOpenWorld(DefinitionFile file, List errors) { boolean openWorld = Util.getFlag(file, "OpenWorld"); if (!openWorld) { return; @@ -323,9 +323,14 @@ private void validateOpenWorld(DefinitionFile file) { // OpenWorld implies NoBinary file.getOptions().put("NoBinary", Flag.create().setValue(true)); - boolean noInterfaces = Util.getFlag(file, "NoInterfaces"); - if (noInterfaces) { - error("option OpenWorld cannot be combined with option NoInterfaces."); + if (_importedFiles.contains(file)) { + return; + } + for (String option : new String[] { "NoInterfaces", "SharedGraph" }) { + if (Util.getFlag(file, option)) { + errors.add(sourceDescription(file) + ": option OpenWorld cannot be combined with option " + option + + ". Remove one of the options."); + } } } @@ -371,19 +376,20 @@ private static boolean extendsOpenWorldFromOtherFile(DefinitionFile file, List */ - private void validateGeneralizations(DefinitionFile file, List errors) { + private void validateGeneralizations(DefinitionFile file, GeneratorPlugin plugin, List errors) { for (Definition def : file.getDefinitions()) { - validateGeneralizations(file, def, errors); + validateGeneralizations(file, def, plugin, errors); } } - private void validateGeneralizations(DefinitionFile file, Definition def, List errors) { + private void validateGeneralizations(DefinitionFile file, Definition def, GeneratorPlugin plugin, List errors) { if (!(def instanceof MessageDef)) { return; } MessageDef message = (MessageDef) def; MessageDef extended = message.getExtendedDef(); if (extended != null) { + int errorCount = errors.size(); List path = new ArrayList<>(); path.add(message); for (MessageDef current = extended; current != null; current = current.getExtendedDef()) { @@ -412,10 +418,91 @@ private void validateGeneralizations(DefinitionFile file, Definition def, List seen = new HashSet<>(); + while (root.getExtendedDef() != null && seen.add(root)) { + root = root.getExtendedDef(); + } + DefinitionFile rootFile = Util.definingFile(root); + if (!Util.getFlag(rootFile, "OpenWorld")) { + errors.add(sourceDescription(file) + ": File declares option OpenWorld, but message '" + + Util.toString(message) + "' belongs to the hierarchy of '" + Util.toString(root) + "' of '" + + sourceDescription(rootFile) + "', which does not declare option OpenWorld. Add 'option OpenWorld;' to '" + + sourceDescription(rootFile) + "', or remove it from '" + sourceDescription(file) + "'."); + } + } + + if (extendedFile != file && errors.size() == errorCount) { + validateExtensionOptions(file, message, extended, extendedFile, plugin, errors); + } } for (Definition inner : message.getDefinitions()) { - validateGeneralizations(file, inner, errors); + validateGeneralizations(file, inner, plugin, errors); + } + } + + /** + * Rejects an extension of a message of another file, if the two files generate incompatible + * code. + * + *

+ * A specialization implements the abstract methods and overrides the methods of its + * generalization. So both files must generate the same serialization formats, visitors and type + * kinds, and use the same interface mode. A specialization may omit listener and reflection + * support of its generalization, but cannot add it. + *

+ */ + private void validateExtensionOptions(DefinitionFile file, MessageDef message, MessageDef extended, + DefinitionFile extendedFile, GeneratorPlugin plugin, List errors) { + String prefix = sourceDescription(file) + ": Message '" + Util.toString(message) + "' extends message '" + + Util.toString(extended) + "' of '" + sourceDescription(extendedFile) + "'"; + + Set formats = formats(file, plugin); + Set extendedFormats = formats(extendedFile, plugin); + for (String format : extendedFormats) { + if (!formats.contains(format) && !format.equals(GRAPH_JSON_FORMAT)) { + errors.add(prefix + ", which is generated with " + format + " serialization, but '" + + sourceDescription(file) + "' is generated without (" + disabledBy(file, format) + + "). Use the same format options in both files."); + } + } + + Map options = file.getOptions(); + Map extendedOptions = extendedFile.getOptions(); + boolean visitor = !MessageGenerator.isTrue(options.get("NoVisitor"), false); + boolean extendedVisitor = !MessageGenerator.isTrue(extendedOptions.get("NoVisitor"), false); + checkSameOption(prefix, file, extendedFile, "NoVisitor", errors); + if (visitor && extendedVisitor) { + checkSameOption(prefix, file, extendedFile, "NoVisitorExceptions", errors); + } + checkSameOption(prefix, file, extendedFile, "NoTypeKind", errors); + checkSameOption(prefix, file, extendedFile, "NoInterfaces", errors); + + boolean listener = MessageGenerator.isListener(options); + boolean reflection = MessageGenerator.isReflection(options); + if (listener && !MessageGenerator.isListener(extendedOptions)) { + errors.add(prefix + ", which is generated without listener support (option NoListener), but '" + + sourceDescription(file) + "' is generated with it. Add 'option NoListener;' to '" + + sourceDescription(file) + "', or remove it from '" + sourceDescription(extendedFile) + "'."); + } else if (reflection && !MessageGenerator.isReflection(extendedOptions)) { + errors.add(prefix + ", which is generated without reflection (option NoReflection), but '" + + sourceDescription(file) + "' is generated with it. Add 'option NoReflection;' and 'option NoListener;' to '" + + sourceDescription(file) + "', or remove them from '" + sourceDescription(extendedFile) + "'."); + } + } + + private void checkSameOption(String prefix, DefinitionFile file, DefinitionFile extendedFile, String option, + List errors) { + boolean set = MessageGenerator.isTrue(file.getOptions().get(option), false); + boolean extendedSet = MessageGenerator.isTrue(extendedFile.getOptions().get(option), false); + if (set != extendedSet) { + DefinitionFile with = set ? file : extendedFile; + DefinitionFile without = set ? extendedFile : file; + errors.add(prefix + ", but only '" + sourceDescription(with) + "' declares option " + option + + ", '" + sourceDescription(without) + "' does not. Use the same setting in both files."); } } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index cf9a3431..4465f381 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -68,8 +68,8 @@ public MessageGenerator(NameTable table, Map options, boolean is _graph = isTrue(options.get("SharedGraph"), false); _json = isJson(options); _binary = isBinary(options); - _listener = _graph || !isTrue(options.get("NoListener"), false); - _reflection = _listener || !isTrue(options.get("NoReflection"), false); + _listener = isListener(options); + _reflection = isReflection(options); _visitor = !isTrue(options.get("NoVisitor"), false); _visitEx= !isTrue(options.get("NoVisitorExceptions"), false); _typeKind = !isTrue(options.get("NoTypeKind"), false); @@ -269,7 +269,7 @@ private void generateClassContents() { if (_visitor) { generateVisitorInterface(); } - if (isCrossFileExtension() && !_def.isAbstract() && (_interface || _noInterfaces)) { + if (_visitor && isCrossFileExtension() && !_def.isAbstract() && (_interface || _noInterfaces)) { generateExtensionVisitorInterface(); } } @@ -434,6 +434,20 @@ private void generateInnerDefinitions() { } } + /** + * Whether listener support is generated for the given file options. + */ + public static boolean isListener(Map options) { + return isTrue(options.get("SharedGraph"), false) || !isTrue(options.get("NoListener"), false); + } + + /** + * Whether reflective property access is generated for the given file options. + */ + public static boolean isReflection(Map options) { + return isListener(options) || !isTrue(options.get("NoReflection"), false); + } + /** * Whether JSON serialization code is generated for the given file options. */ diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/TestOpenWorldNoVisitor.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/TestOpenWorldNoVisitor.java new file mode 100644 index 00000000..6b45f13d --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/TestOpenWorldNoVisitor.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2026 Bernhard Haumacher et al. All Rights Reserved. + */ +package test.openworld; + +import java.io.IOException; + +import de.haumacher.msgbuf.io.StringR; +import de.haumacher.msgbuf.json.JsonReader; +import junit.framework.TestCase; +import test.openworld.novisitor.base.Shape; +import test.openworld.novisitor.ext.Square; + +/** + * Test case for an OpenWorld hierarchy without visitors (issue #39). + */ +@SuppressWarnings("javadoc") +public class TestOpenWorldNoVisitor extends TestCase { + + public void testExtensionRoundTrip() throws IOException { + Square square = Square.create().setSide(3); + square.setName("s"); + String json = square.toString(); + assertEquals("[\"Square\",{\"name\":\"s\",\"side\":3}]", json); + Shape copy = Shape.readShape(new JsonReader(new StringR(json))); + assertTrue(copy instanceof Square); + assertEquals(json, copy.toString()); + } + + public void testNoVisitor() { + for (Class type : Square.class.getClasses()) { + assertFalse("Unexpected " + type.getName(), type.getSimpleName().equals("Visitor")); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/Circle.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/Circle.java new file mode 100644 index 00000000..6bd287a6 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/Circle.java @@ -0,0 +1,41 @@ +package test.openworld.novisitor.base; + +public interface Circle extends test.openworld.novisitor.base.Shape { + + /** + * Creates a {@link test.openworld.novisitor.base.Circle} instance. + */ + static test.openworld.novisitor.base.Circle create() { + return new test.openworld.novisitor.base.impl.Circle_Impl(); + } + + /** Identifier for the {@link test.openworld.novisitor.base.Circle} type in JSON format. */ + String CIRCLE__TYPE = "Circle"; + + /** @see #getRadius() */ + String RADIUS__PROP = "radius"; + + int getRadius(); + + /** + * @see #getRadius() + */ + test.openworld.novisitor.base.Circle setRadius(int value); + + @Override + test.openworld.novisitor.base.Circle setName(String value); + + /** Reads a new instance from the given reader. */ + static test.openworld.novisitor.base.Circle readCircle(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.novisitor.base.impl.Circle_Impl result = new test.openworld.novisitor.base.impl.Circle_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Circle readCircle(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.novisitor.base.impl.Circle_Impl.readCircle_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/Shape.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/Shape.java new file mode 100644 index 00000000..07575e81 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/Shape.java @@ -0,0 +1,85 @@ +package test.openworld.novisitor.base; + +/** + * An OpenWorld hierarchy without visitors (issue #39). + */ +public interface Shape extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** Type codes for the {@link test.openworld.novisitor.base.Shape} hierarchy. */ + public enum TypeKind { + + /** Type literal for {@link test.openworld.novisitor.base.Circle}. */ + CIRCLE, + ; + + } + + /** Registry for dynamically registered subtypes. */ + static final java.util.Map> REGISTRY = new java.util.HashMap<>(); + + /** + * Registers a subtype factory for polymorphic deserialization. + */ + static void register(String typeId, de.haumacher.msgbuf.data.Factory factory) { + REGISTRY.put(typeId, factory); + } + + /** @see #getName() */ + String NAME__PROP = "name"; + + /** The type code of this instance. */ + TypeKind kind(); + + String getName(); + + /** + * @see #getName() + */ + test.openworld.novisitor.base.Shape setName(String value); + + @Override + public test.openworld.novisitor.base.Shape registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.openworld.novisitor.base.Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.openworld.novisitor.base.Shape readShape(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.novisitor.base.Shape result; + in.beginArray(); + String type = in.nextString(); + switch (type) { + case Circle.CIRCLE__TYPE: result = test.openworld.novisitor.base.Circle.readCircle(in); break; + default: { + de.haumacher.msgbuf.data.TypeRegistryLoader.ensureLoaded(); + de.haumacher.msgbuf.data.Factory factory = test.openworld.novisitor.base.Shape.REGISTRY.get(type); + if (factory != null) { + result = factory.create(); + result.readContent(in); + } else { + in.skipValue(); + result = null; + } + } break; + } + in.endArray(); + return result; + } + + /** Registry for dynamically registered subtypes by their XML element names. */ + static final java.util.Map> XML_REGISTRY = new java.util.HashMap<>(); + + /** + * Registers a subtype factory for reading elements with the given name in XML format. + */ + static void registerXml(String elementName, de.haumacher.msgbuf.data.Factory factory) { + XML_REGISTRY.put(elementName, factory); + } + + /** Creates a new {@link Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Shape readShape(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.novisitor.base.impl.Shape_Impl.readShape_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/base.proto b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/base.proto new file mode 100644 index 00000000..42ec546c --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/base.proto @@ -0,0 +1,13 @@ +package test.openworld.novisitor.base; + +option OpenWorld; +option NoVisitor; + +/** An OpenWorld hierarchy without visitors (issue #39). */ +abstract message Shape { + string name; +} + +message Circle extends Shape { + int radius; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/impl/Circle_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/impl/Circle_Impl.java new file mode 100644 index 00000000..d3ecaa7f --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/impl/Circle_Impl.java @@ -0,0 +1,173 @@ +package test.openworld.novisitor.base.impl; + +/** + * Implementation of {@link test.openworld.novisitor.base.Circle}. + */ +public class Circle_Impl extends test.openworld.novisitor.base.impl.Shape_Impl implements test.openworld.novisitor.base.Circle { + + private int _radius = 0; + + /** + * Creates a {@link Circle_Impl} instance. + * + * @see test.openworld.novisitor.base.Circle#create() + */ + public Circle_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return TypeKind.CIRCLE; + } + + @Override + public final int getRadius() { + return _radius; + } + + @Override + public test.openworld.novisitor.base.Circle setRadius(int value) { + internalSetRadius(value); + return this; + } + + /** Internal setter for {@link #getRadius()} without chain call utility. */ + protected final void internalSetRadius(int value) { + _listener.beforeSet(this, RADIUS__PROP, value); + _radius = value; + _listener.afterChanged(this, RADIUS__PROP); + } + + @Override + public test.openworld.novisitor.base.Circle setName(String value) { + internalSetName(value); + return this; + } + + @Override + public String jsonType() { + return CIRCLE__TYPE; + } + + @SuppressWarnings("hiding") + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + RADIUS__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.openworld.novisitor.base.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.openworld.novisitor.base.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case RADIUS__PROP: return getRadius(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case RADIUS__PROP: internalSetRadius((int) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(RADIUS__PROP); + out.value(getRadius()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case RADIUS__PROP: setRadius(in.nextInt()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.novisitor.base.Circle} type. */ + public static final String CIRCLE__XML_ELEMENT = "circle"; + + /** XML attribute or element name of a {@link #getRadius} property. */ + private static final String RADIUS__XML_ATTR = "radius"; + + @Override + public String getXmlTagName() { + return CIRCLE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(RADIUS__XML_ATTR, Integer.toString(getRadius())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.openworld.novisitor.base.Circle} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Circle_Impl readCircle_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Circle_Impl result = new Circle_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case RADIUS__XML_ATTR: { + setRadius(Integer.parseInt(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case RADIUS__XML_ATTR: { + setRadius(Integer.parseInt(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/impl/Shape_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/impl/Shape_Impl.java new file mode 100644 index 00000000..daa603af --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/base/impl/Shape_Impl.java @@ -0,0 +1,223 @@ +package test.openworld.novisitor.base.impl; + +/** + * Implementation of {@link test.openworld.novisitor.base.Shape}. + */ +public abstract class Shape_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.openworld.novisitor.base.Shape { + + static { + de.haumacher.msgbuf.data.TypeRegistryLoader.ensureLoaded(); + } + + private String _name = ""; + + /** + * Creates a {@link Shape_Impl} instance. + */ + public Shape_Impl() { + super(); + } + + @Override + public final String getName() { + return _name; + } + + @Override + public test.openworld.novisitor.base.Shape setName(String value) { + internalSetName(value); + return this; + } + + /** Internal setter for {@link #getName()} without chain call utility. */ + protected final void internalSetName(String value) { + _listener.beforeSet(this, NAME__PROP, value); + _name = value; + _listener.afterChanged(this, NAME__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.openworld.novisitor.base.Shape registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.openworld.novisitor.base.Shape unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + NAME__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case NAME__PROP: return getName(); + default: return test.openworld.novisitor.base.Shape.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case NAME__PROP: internalSetName((String) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.beginArray(); + out.value(jsonType()); + writeContent(out); + out.endArray(); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(NAME__PROP); + out.value(getName()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case NAME__PROP: setName(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.novisitor.base.Shape} type. */ + public static final String SHAPE__XML_ELEMENT = "shape"; + + /** XML attribute or element name of a {@link #getName} property. */ + private static final String NAME__XML_ATTR = "name"; + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(NAME__XML_ATTR, getName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.openworld.novisitor.base.Shape} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Shape_Impl readShape_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + switch (in.getLocalName()) { + case Circle_Impl.CIRCLE__XML_ELEMENT: { + return test.openworld.novisitor.base.impl.Circle_Impl.readCircle_XmlContent(in); + } + + default: { + de.haumacher.msgbuf.data.Factory factory = test.openworld.novisitor.base.Shape.XML_REGISTRY.get(in.getLocalName()); + test.openworld.novisitor.base.Shape instance = factory == null ? null : factory.create(); + if (instance instanceof Shape_Impl) { + Shape_Impl result = (Shape_Impl) instance; + result.readContentXml(in); + return result; + } + internalSkipUntilMatchingEndElement(in); + return null; + } + } + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case NAME__XML_ATTR: { + setName(value); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case NAME__XML_ATTR: { + setName(in.getElementText()); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/ExtTypes.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/ExtTypes.java new file mode 100644 index 00000000..8a146ed3 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/ExtTypes.java @@ -0,0 +1,20 @@ +package test.openworld.novisitor.ext; + +/** + * Registration of extension types for the OpenWorld protocol. + */ +public class ExtTypes implements de.haumacher.msgbuf.data.TypeRegistration { + + @Override + public void register() { + test.openworld.novisitor.base.Shape.register(test.openworld.novisitor.ext.Square.SQUARE__TYPE, test.openworld.novisitor.ext.Square::create); + test.openworld.novisitor.base.Shape.registerXml(test.openworld.novisitor.ext.impl.Square_Impl.SQUARE__XML_ELEMENT, test.openworld.novisitor.ext.Square::create); + } + + /** + * Explicit initialization for GWT or manual use. + */ + public static void init() { + new ExtTypes().register(); + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/Square.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/Square.java new file mode 100644 index 00000000..ba97b9a3 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/Square.java @@ -0,0 +1,41 @@ +package test.openworld.novisitor.ext; + +public interface Square extends test.openworld.novisitor.base.Shape { + + /** + * Creates a {@link test.openworld.novisitor.ext.Square} instance. + */ + static test.openworld.novisitor.ext.Square create() { + return new test.openworld.novisitor.ext.impl.Square_Impl(); + } + + /** Identifier for the {@link test.openworld.novisitor.ext.Square} type in JSON format. */ + String SQUARE__TYPE = "Square"; + + /** @see #getSide() */ + String SIDE__PROP = "side"; + + int getSide(); + + /** + * @see #getSide() + */ + test.openworld.novisitor.ext.Square setSide(int value); + + @Override + test.openworld.novisitor.ext.Square setName(String value); + + /** Reads a new instance from the given reader. */ + static test.openworld.novisitor.ext.Square readSquare(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.openworld.novisitor.ext.impl.Square_Impl result = new test.openworld.novisitor.ext.impl.Square_Impl(); + result.readContent(in); + return result; + } + + /** Creates a new {@link Square} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Square readSquare(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.openworld.novisitor.ext.impl.Square_Impl.readSquare_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/ext.proto b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/ext.proto new file mode 100644 index 00000000..6e1bc567 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/ext.proto @@ -0,0 +1,8 @@ +package test.openworld.novisitor.ext; +import "../base/base.proto"; + +option NoVisitor; + +message Square extends test.openworld.novisitor.base.Shape { + int side; +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/impl/Square_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/impl/Square_Impl.java new file mode 100644 index 00000000..b3f18894 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/openworld/novisitor/ext/impl/Square_Impl.java @@ -0,0 +1,173 @@ +package test.openworld.novisitor.ext.impl; + +/** + * Implementation of {@link test.openworld.novisitor.ext.Square}. + */ +public class Square_Impl extends test.openworld.novisitor.base.impl.Shape_Impl implements test.openworld.novisitor.ext.Square { + + private int _side = 0; + + /** + * Creates a {@link Square_Impl} instance. + * + * @see test.openworld.novisitor.ext.Square#create() + */ + public Square_Impl() { + super(); + } + + @Override + public TypeKind kind() { + return null; + } + + @Override + public final int getSide() { + return _side; + } + + @Override + public test.openworld.novisitor.ext.Square setSide(int value) { + internalSetSide(value); + return this; + } + + /** Internal setter for {@link #getSide()} without chain call utility. */ + protected final void internalSetSide(int value) { + _listener.beforeSet(this, SIDE__PROP, value); + _side = value; + _listener.afterChanged(this, SIDE__PROP); + } + + @Override + public test.openworld.novisitor.ext.Square setName(String value) { + internalSetName(value); + return this; + } + + @Override + public String jsonType() { + return SQUARE__TYPE; + } + + @SuppressWarnings("hiding") + protected static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + SIDE__PROP); + java.util.List tmp = new java.util.ArrayList<>(); + tmp.addAll(test.openworld.novisitor.base.impl.Shape_Impl.PROPERTIES); + tmp.addAll(local); + PROPERTIES = java.util.Collections.unmodifiableList(tmp); + } + + @SuppressWarnings("hiding") + protected static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(test.openworld.novisitor.base.impl.Shape_Impl.TRANSIENT_PROPERTIES); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case SIDE__PROP: return getSide(); + default: return super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case SIDE__PROP: internalSetSide((int) value); break; + default: super.set(field, value); break; + } + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(SIDE__PROP); + out.value(getSide()); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case SIDE__PROP: setSide(in.nextInt()); break; + default: super.readField(in, field); + } + } + + /** XML element name representing a {@link test.openworld.novisitor.ext.Square} type. */ + public static final String SQUARE__XML_ELEMENT = "square"; + + /** XML attribute or element name of a {@link #getSide} property. */ + private static final String SIDE__XML_ATTR = "side"; + + @Override + public String getXmlTagName() { + return SQUARE__XML_ELEMENT; + } + + /** Serializes all fields that are written as XML attributes. */ + @Override + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeAttributes(out); + out.writeAttribute(SIDE__XML_ATTR, Integer.toString(getSide())); + } + + /** Serializes all fields that are written as XML elements. */ + @Override + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + super.writeElements(out); + // No element fields. + } + + /** Creates a new {@link test.openworld.novisitor.ext.Square} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Square_Impl readSquare_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Square_Impl result = new Square_Impl(); + result.readContentXml(in); + return result; + } + + @Override + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case SIDE__XML_ATTR: { + setSide(Integer.parseInt(value)); + break; + } + default: { + super.readFieldXmlAttribute(name, value); + } + } + } + + @Override + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case SIDE__XML_ATTR: { + setSide(Integer.parseInt(in.getElementText())); + break; + } + default: { + super.readFieldXmlElement(in, localName); + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/validation/TestExtensionOptions.java b/de.haumacher.msgbuf.generator/src/test/java/test/validation/TestExtensionOptions.java new file mode 100644 index 00000000..5e611a07 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/validation/TestExtensionOptions.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2026 Bernhard Haumacher et al. All Rights Reserved. + */ +package test.validation; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.List; + +import de.haumacher.msgbuf.generator.Generator; +import de.haumacher.msgbuf.generator.GeneratorException; +import de.haumacher.msgbuf.generator.parser.ParseException; +import de.haumacher.msgbuf.generator.plugins.XmlStreamingPlugin; +import junit.framework.TestCase; + +/** + * Test case for rejecting extensions across files whose options generate incompatible code + * (issues #37, #38, #40, #41). + */ +@SuppressWarnings("javadoc") +public class TestExtensionOptions extends TestCase { + + private static final File FIXTURES = new File("src/test/resources/reject/options"); + + /** Formats, visitors, type kinds must agree; listener support must not be added (#37, #40). */ + public void testMismatchingOptions() throws IOException, ParseException { + assertEquals(Arrays.asList( + "reject/opt/ext/mismatch.proto: Message 'reject.opt.ext.Ping' extends message 'reject.opt.base.Event' of 'reject/opt/base/events.proto', which is generated with JSON serialization, but 'reject/opt/ext/mismatch.proto' is generated without (option NoJson). Use the same format options in both files.", + "reject/opt/ext/mismatch.proto: Message 'reject.opt.ext.Ping' extends message 'reject.opt.base.Event' of 'reject/opt/base/events.proto', but only 'reject/opt/ext/mismatch.proto' declares option NoVisitor, 'reject/opt/base/events.proto' does not. Use the same setting in both files.", + "reject/opt/ext/mismatch.proto: Message 'reject.opt.ext.Ping' extends message 'reject.opt.base.Event' of 'reject/opt/base/events.proto', but only 'reject/opt/ext/mismatch.proto' declares option NoTypeKind, 'reject/opt/base/events.proto' does not. Use the same setting in both files.", + "reject/opt/ext/mismatch.proto: Message 'reject.opt.ext.Loud' extends message 'reject.opt.base.Quiet' of 'reject/opt/base/quiet.proto', which is generated with JSON serialization, but 'reject/opt/ext/mismatch.proto' is generated without (option NoJson). Use the same format options in both files.", + "reject/opt/ext/mismatch.proto: Message 'reject.opt.ext.Loud' extends message 'reject.opt.base.Quiet' of 'reject/opt/base/quiet.proto', but only 'reject/opt/ext/mismatch.proto' declares option NoVisitor, 'reject/opt/base/quiet.proto' does not. Use the same setting in both files.", + "reject/opt/ext/mismatch.proto: Message 'reject.opt.ext.Loud' extends message 'reject.opt.base.Quiet' of 'reject/opt/base/quiet.proto', but only 'reject/opt/ext/mismatch.proto' declares option NoTypeKind, 'reject/opt/base/quiet.proto' does not. Use the same setting in both files.", + "reject/opt/ext/mismatch.proto: Message 'reject.opt.ext.Loud' extends message 'reject.opt.base.Quiet' of 'reject/opt/base/quiet.proto', which is generated without listener support (option NoListener), but 'reject/opt/ext/mismatch.proto' is generated with it. Add 'option NoListener;' to 'reject/opt/ext/mismatch.proto', or remove it from 'reject/opt/base/quiet.proto'."), + reject("ext/mismatch.proto")); + } + + /** OpenWorld on an intermediate requires OpenWorld on the root (#38). */ + public void testOpenWorldIntermediateOfClosedRoot() throws IOException, ParseException { + assertEquals(Arrays.asList( + "reject/opt/split/mid.proto: File declares option OpenWorld, but message 'reject.opt.split.Mid' belongs to the hierarchy of 'reject.opt.split.Root' of 'reject/opt/split/root.proto', which does not declare option OpenWorld. Add 'option OpenWorld;' to 'reject/opt/split/root.proto', or remove it from 'reject/opt/split/mid.proto'."), + reject("split/root.proto", "split/mid.proto")); + } + + /** OpenWorld cannot be combined with NoInterfaces or SharedGraph (#41). */ + public void testOpenWorldCombinations() throws IOException, ParseException { + assertEquals(Arrays.asList( + "reject/opt/graph/graph.proto: option OpenWorld cannot be combined with option NoInterfaces. Remove one of the options.", + "reject/opt/graph/graph.proto: option OpenWorld cannot be combined with option SharedGraph. Remove one of the options."), + reject("graph.proto")); + } + + private List reject(String... protos) throws IOException, ParseException { + File target = new File("target"); + target.mkdirs(); + File out = Files.createTempDirectory(target.toPath(), getName()).toFile(); + Generator generator = new Generator(); + generator.setOut(out); + for (String proto : protos) { + generator.load(new File(FIXTURES, proto)); + } + try { + generator.generate(new XmlStreamingPlugin()); + fail("Expected rejection of " + Arrays.toString(protos) + "."); + return null; + } catch (GeneratorException ex) { + String[] written = out.list(); + assertTrue("No code must be generated for rejected definitions.", written == null || written.length == 0); + return ex.getErrors(); + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/META-INF/services/de.haumacher.msgbuf.data.TypeRegistration b/de.haumacher.msgbuf.generator/src/test/resources/META-INF/services/de.haumacher.msgbuf.data.TypeRegistration index e3a8b0c9..20e9ff21 100644 --- a/de.haumacher.msgbuf.generator/src/test/resources/META-INF/services/de.haumacher.msgbuf.data.TypeRegistration +++ b/de.haumacher.msgbuf.generator/src/test/resources/META-INF/services/de.haumacher.msgbuf.data.TypeRegistration @@ -1,4 +1,5 @@ test.openworld.deep.ext2.Ext2Types +test.openworld.novisitor.ext.ExtTypes test.openworld.ext1.Ext1Types test.nested.owcount.OwcountTypes test.openworld.ext2.Ext2Types diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/options/base/events.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/options/base/events.proto new file mode 100644 index 00000000..ef334100 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/options/base/events.proto @@ -0,0 +1,7 @@ +package reject.opt.base; + +option OpenWorld; + +abstract message Event { + string source; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/options/base/quiet.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/options/base/quiet.proto new file mode 100644 index 00000000..b7881c29 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/options/base/quiet.proto @@ -0,0 +1,9 @@ +package reject.opt.base; + +option OpenWorld; +option NoReflection; +option NoListener; + +abstract message Quiet { + string source; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/options/ext/mismatch.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/options/ext/mismatch.proto new file mode 100644 index 00000000..b17f8b5b --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/options/ext/mismatch.proto @@ -0,0 +1,15 @@ +package reject.opt.ext; +import "../base/events.proto"; +import "../base/quiet.proto"; + +option NoJson; +option NoVisitor; +option NoTypeKind; + +message Ping extends reject.opt.base.Event { + int count; +} + +message Loud extends reject.opt.base.Quiet { + int volume; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/options/graph.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/options/graph.proto new file mode 100644 index 00000000..ace11ea7 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/options/graph.proto @@ -0,0 +1,9 @@ +package reject.opt.graph; + +option OpenWorld; +option SharedGraph; +option NoInterfaces; + +abstract message Node { + string name; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/options/split/mid.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/options/split/mid.proto new file mode 100644 index 00000000..737f68fe --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/options/split/mid.proto @@ -0,0 +1,8 @@ +package reject.opt.split; +import "root.proto"; + +option OpenWorld; + +abstract message Mid extends Root { + int level; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/options/split/root.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/options/split/root.proto new file mode 100644 index 00000000..507b5e83 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/options/split/root.proto @@ -0,0 +1,5 @@ +package reject.opt.split; + +abstract message Root { + string name; +} From 32e827ecee97d20f13eb454e9c5db58067133bc2 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 18:22:20 +0200 Subject: [PATCH 202/207] Generate visitor, tag and guard helpers for polymorphic values in TypeScript. The TypeScript target described the JSON format with types only, so a client still had to dispatch type-tagged values by hand, e.g. the events of an SSE stream, with a switch that silently misses new event types. JSON values are plain JavaScript data, so no generated classes or TypeScript runtime are needed: for each Any...Json union, the module now contains a visitor interface with an exhaustive dispatch function (a new type in the protocol is a compile error in every handler; OpenWorld hierarchies get a required visitDefault) and a type guard checking the type tag, plus a function creating the type-tagged tuple per concrete type. The helpers live at module top level even for nested messages, since namespaces with values are not erasable syntax. Names are derived from the outer-qualified message name, and names that would still clash are rejected before any output is written. Files with option SharedGraph get no helpers, since their JSON format is not described by the types either. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 7 +- README.md | 51 +- .../haumacher/msgbuf/generator/Generator.java | 18 +- .../generator/ts/TypeScriptGenerator.java | 378 +++++++++++- .../generator/ts/TestTypeScriptGenerator.java | 43 ++ .../resources/reject/ts/collide/names.proto | 15 + .../test/resources/reject/ts/open/base.proto | 6 + .../test/resources/reject/ts/open/one.proto | 6 + .../test/resources/reject/ts/open/two.proto | 7 + .../ts/expected/test/ts/commands/commands.ts | 549 ++++++++++++++++++ .../ts/expected/test/ts/common/common.ts | 59 +- .../ts/expected/test/ts/events/base/base.ts | 197 +++++++ .../ts/expected/test/ts/events/ext/ext.ts | 116 ++++ .../ts/expected/test/ts/graph/graph.ts | 28 + .../ts/expected/test/ts/shapes/shapes.ts | 108 +++- .../ts/proto/test/ts/commands/commands.proto | 127 ++++ .../ts/proto/test/ts/events/base/base.proto | 40 ++ .../ts/proto/test/ts/events/ext/ext.proto | 35 ++ .../ts/proto/test/ts/graph/graph.proto | 15 + 19 files changed, 1793 insertions(+), 12 deletions(-) create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/ts/collide/names.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/ts/open/base.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/ts/open/one.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/ts/open/two.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/commands/commands.ts create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/events/base/base.ts create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/events/ext/ext.ts create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/graph/graph.ts create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/commands/commands.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/events/base/base.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/events/ext/ext.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/graph/graph.proto diff --git a/CHANGELOG.md b/CHANGELOG.md index d2863086..51fa9f49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,12 +3,17 @@ ## 1.2.3 ### New Features -- **TypeScript type definitions**: Generate a types-only TypeScript module per `.proto` file describing its JSON +- **TypeScript type definitions**: Generate a TypeScript module per `.proto` file describing its JSON format (interfaces for messages, string-literal unions for enums, type-tagged tuple unions for polymorphic values). Top-level types are named with the suffix `Json` (e.g. `ShapeJson`, `AnyShapeJson`), since they describe the JSON format, not the data itself. Properties the Java writer always emits are required, only nullable fields are optional. Enabled for all files with the Maven plugin parameter `typeScriptOutputDirectory` or the `-ts
` CLI argument, or per file with `option TypeScript = "path/to/module.ts";`. + For polymorphic values, the modules contain small helpers operating on the plain JSON values (#10): a visitor + interface and an exhaustive dispatch function (`visitShapeJson(value, visitor)`, with a required `visitDefault` for + `option OpenWorld`) and a type guard checking the type tag (`isAnyShapeJson(value)`) per `Any...Json` union, and a + function creating the type-tagged tuple per concrete type (`tagCircle(self)`). No helpers are generated for + `option SharedGraph`. Helper names that would clash (e.g. of `message A_B` and a nested `A.B`) are rejected. - **File documentation comment**: A doc comment before the `syntax` or `package` declaration is kept as the documentation of the `.proto` file (`DefinitionFile.comment`) and emitted as TSDoc `@packageDocumentation` of the TypeScript module. diff --git a/README.md b/README.md index 3c102b51..9c550c2a 100644 --- a/README.md +++ b/README.md @@ -498,8 +498,9 @@ message MyMessage { ### TypeScript type definitions The generator can create a TypeScript module with type definitions for the JSON format of each `.proto` file. The -modules contain types only (no readers, writers or other runtime code) and let a TypeScript client share the protocol -contract with the Java side. +modules let a TypeScript client share the protocol contract with the Java side. Besides the types, they only contain +small helper functions for type-tagged polymorphic values (visitor dispatch, tagging, tag guards, see below) that +operate on the plain values of `JSON.parse()`: no classes, no readers or writers, no runtime library. Since the types describe the JSON format and not the data itself, a top-level type is named after its definition with the suffix `Json`, e.g. `ShapeJson` for `message Shape`. This keeps the plain names free for types representing the @@ -543,6 +544,8 @@ Mapping of protocol definitions: | `map` (other key types) | `Array<{ key: K; value: V }>` | | Nested definitions | Declarations in a namespace named after the outer message, keeping their names, e.g. `OuterJson.Inner` | | Types from imported `.proto` files | `import type { ... } from '';` | +| `abstract message A` with `AnyAJson` | Visitor interface `AJsonVisitor`, dispatch function `visitAJson(value, visitor)`, type guard `isAnyAJson(value)` | +| `message C extends A` (in a hierarchy with abstract root) | Function `tagC(self: CJson): ['TypeIdOfC', CJson]` creating the type-tagged tuple | Details: @@ -572,6 +575,48 @@ Details: generated and used as type of fields referencing `A`. For `option OpenWorld` hierarchies, the union additionally contains `[string, AJson]` for extension types from other modules. References to concrete messages (and all messages in a hierarchy with a concrete root) are written without type information and use the interface directly. +* **Helpers for polymorphic values**: For each union `AnyAJson`, a visitor interface with one method per concrete + type of the union, a dispatch function and a type guard are generated, and a tag function for each concrete type + of such a hierarchy: + + ```ts + export interface SSEEventJsonVisitor { + visitPatchEvent(self: PatchEventJson): R; + visitStateEvent(self: StateEventJson): R; + } + export function visitSSEEventJson(value: AnySSEEventJson, visitor: SSEEventJsonVisitor): R; + export function isAnySSEEventJson(value: unknown): value is AnySSEEventJson; + export function tagPatchEvent(self: PatchEventJson): ['PatchEvent', PatchEventJson]; + ``` + + Usage: + + ```ts + const event: unknown = JSON.parse(data); + if (isAnySSEEventJson(event)) { + visitSSEEventJson(event, { + visitPatchEvent: patch => applyPatch(patch), + visitStateEvent: state => replaceState(state), + }); + } + socket.send(JSON.stringify(tagPatchEvent({ timestamp: Date.now(), patch: '...' }))); + ``` + + * The name part of a helper (`SSEEvent`, `PatchEvent`) is the message name qualified with the names of its outer + messages, joined with `_`, first letter in upper case, e.g. `visitGroup_Info` and `tagGroup_Info` for message + `Info` nested in `Group`. The package is not part of the name. All helpers are declared at the top level of the + module, also for nested messages (a namespace containing functions is not erasable TypeScript syntax). The + generator rejects a `.proto` file whose helper names clash, i.e. two concrete types of one hierarchy (also from + different files) or two messages of one file with the same name part, e.g. `message A_B` and `A.B`. + * A visitor method has the same name in the visitors of all abstract types of a hierarchy, so a visitor of the root + can also be passed to the dispatch function of an abstract intermediate type. + * The dispatch function of a closed hierarchy is checked for exhaustiveness by the compiler and throws an `Error` + for an unknown type ID. For `option OpenWorld` hierarchies, the visitor has an additional required method + `visitDefault(self: AJson, typeId: string)` that receives values of types not known to the module (like the + `visitDefault()` of the Java visitor). + * The type guard checks the type tag only: an array of two elements, the first a known type ID (any string for + `option OpenWorld`), the second an object. The properties of the object are not validated. + * Tag functions return the exact tuple type, which is assignable to each `Any...Json` union containing the type. * **Documentation**: Doc comments become TSDoc comments. JavaDoc inline tags are translated: `{@code x}` becomes `` `x` ``, `{@link Type}`, `{@link #field}` and `{@link Type#field label}` become links to the TypeScript type or property (`{@link Type.prop label}`, using the JSON property name), a link to an enum constant becomes its protocol @@ -583,7 +628,7 @@ Details: at the location the same generator configuration would produce for it (its `option TypeScript`, or its package path within the TypeScript output directory). * **Limitations**: The JSON format of `option SharedGraph` protocols (objects as `[type, id, {...}]`, references as - IDs, incremental updates) is not described by the generated types. A generated `AnyAJson` union type may clash with + IDs, incremental updates) is not described by the generated types, no helper functions are generated for them. A generated `AnyAJson` union type may clash with a message named `AnyA`. ## Installation in Eclipse diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java index 21834e87..63c9180c 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java @@ -216,6 +216,15 @@ public void generate(GeneratorPlugin plugin) { synthesizer.process(file); } + for (DefinitionFile file : _files) { + if (!_importedFiles.contains(file) && generatesTypeScript(file)) { + TypeScriptGenerator.validate(file, this::sourceDescription, errors); + } + } + if (!errors.isEmpty()) { + throw new GeneratorException(errors); + } + for (DefinitionFile file : _files) { if (_importedFiles.contains(file)) { continue; // Imported for type resolution only, don't generate code @@ -235,7 +244,7 @@ public void generate(GeneratorPlugin plugin) { new DartLibGenerator(new File(_out, ((StringOption) dartLib).getValue()), file).run(); } - if (_tsOut != null || file.getOptions().get(TYPESCRIPT_OPTION) != null) { + if (generatesTypeScript(file)) { File tsFile = typeScriptModule(file); new TypeScriptGenerator(tsFile, file, sourceDescription(file), other -> moduleSpecifier(tsFile, typeScriptModule(other)), _table).run(); @@ -259,6 +268,13 @@ public void generate(GeneratorPlugin plugin) { } } + /** + * Whether a TypeScript module is generated for the given definitions. + */ + private boolean generatesTypeScript(DefinitionFile file) { + return _tsOut != null || file.getOptions().get(TYPESCRIPT_OPTION) != null; + } + /** * The TypeScript module file for the given definitions. * diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java index 83b71d09..655e2c50 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/ts/TypeScriptGenerator.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Consumer; import java.util.function.Function; import java.util.regex.Pattern; @@ -34,15 +35,17 @@ import de.haumacher.msgbuf.generator.common.MsgBufJsonProtocol; import de.haumacher.msgbuf.generator.common.Util; import de.haumacher.msgbuf.generator.util.AbstractTypeScriptGenerator; +import de.haumacher.msgbuf.generator.util.CodeUtil; /** * Generator for a TypeScript module with type definitions describing the msgbuf JSON * format of all messages and enums of a .proto file. * *

- * The module contains types only (no runtime code). Since the types describe the JSON format and - * not the data itself, the name of a top-level type is the name of its definition with the suffix - * {@value #JSON_SUFFIX}, e.g. ShapeJson for message Shape: + * The module contains types and, for type-tagged polymorphic values, small helper functions + * operating on plain JSON values (no classes, no readers or writers, no runtime library). Since the + * types describe the JSON format and not the data itself, the name of a top-level type is the name + * of its definition with the suffix {@value #JSON_SUFFIX}, e.g. ShapeJson for message Shape: *

*
    *
  • A message becomes an interface whose properties are named with the JSON @@ -63,6 +66,15 @@ *
  • Nested definitions are placed in a namespace named after the outer message and keep their * names, e.g. GroupJson.Info.
  • *
  • Types from other .proto files are imported with import type.
  • + *
  • For each Any<Name>Json union, a visitor interface + * <Part>JsonVisitor with a method visit<Part> per concrete type + * (and visitDefault for option OpenWorld), a dispatch function + * visit<Part>Json and a type guard isAny<Part>Json checking the + * type tag are generated. Each concrete message in such hierarchy gets a function + * tag<Part> creating its type-tagged tuple. <Part> is the message + * name qualified with the names of its outer messages, joined with _, e.g. + * Group_Info. All helpers are declared at the top level of the module, also + * for nested messages. No helpers are generated for option SharedGraph.
  • *
*/ public class TypeScriptGenerator extends AbstractTypeScriptGenerator { @@ -94,6 +106,11 @@ public class TypeScriptGenerator extends AbstractTypeScriptGenerator { private final NameTable _table; + /** + * Whether helper functions for polymorphic values are generated, see {@link #hasHelpers(DefinitionFile)}. + */ + private final boolean _helpers; + /** * Local names bound per imported file (by top-level name in that file). */ @@ -136,6 +153,7 @@ public TypeScriptGenerator(File file, DefinitionFile proto, String source, Funct _source = source; _moduleSpecifier = moduleSpecifier; _table = table; + _helpers = hasHelpers(proto); } /** @@ -160,11 +178,17 @@ protected void generate() { line("// Generated by msgbuf from '" + _source + "'. Do not edit."); line("//"); - line("// Type definitions for the msgbuf JSON format of the protocol (types only, no runtime code)."); + if (hasHelpers()) { + line("// Type definitions for the msgbuf JSON format of the protocol, and helper functions for its"); + line("// type-tagged polymorphic values (visitor dispatch, tagging, tag guards)."); + } else { + line("// Type definitions for the msgbuf JSON format of the protocol (types only, no runtime code)."); + } if (Util.getFlag(_proto, "SharedGraph")) { line("//"); line("// Note: The protocol uses 'option SharedGraph'. Its JSON format (objects as [type, id, {...}],"); - line("// references as object IDs, incremental updates) is not described by these types."); + line("// references as object IDs, incremental updates) is not described by these types. No helper"); + line("// functions for polymorphic values are generated."); } _separate = true; @@ -188,6 +212,9 @@ protected void generate() { } for (Definition def : _proto.getDefinitions()) { generateDefinition(def); + if (_helpers) { + generateHelpers(def); + } } for (Map.Entry alias : _aliases.entrySet()) { @@ -218,6 +245,11 @@ private void resolveReferences() { _topLevelNames.add(polymorphicName(def)); } } + if (_helpers) { + for (Definition def : _proto.getDefinitions()) { + forEachMessage(def, message -> _topLevelNames.addAll(helperNames(message))); + } + } for (Definition def : _proto.getDefinitions()) { resolveReferences(def); } @@ -259,6 +291,13 @@ private void resolveReferences(Definition def) { } if (hasPolymorphicType(message)) { polymorphicType(message); + if (_helpers) { + // References of the top-level helper declarations. + ref(message, null); + for (MessageDef specialization : Util.concreteTransitiveSpecializations(message)) { + ref(specialization, null); + } + } } for (Definition inner : message.getDefinitions()) { resolveReferences(inner); @@ -341,6 +380,335 @@ private void generateMessage(MessageDef def) { } } + /** + * Whether helper functions for polymorphic values are generated for the given file. + * + *

+ * The JSON format of option SharedGraph is not described by the generated types, + * helpers operating on these types would be misleading. + *

+ */ + private static boolean hasHelpers(DefinitionFile file) { + return !Util.getFlag(file, "SharedGraph"); + } + + /** + * Whether the generated module contains helper functions. + */ + private boolean hasHelpers() { + if (!_helpers) { + return false; + } + boolean[] result = { false }; + for (Definition def : _proto.getDefinitions()) { + forEachMessage(def, message -> result[0] |= !helperNames(message).isEmpty()); + } + return result[0]; + } + + private static void forEachMessage(Definition def, Consumer action) { + if (def instanceof MessageDef) { + MessageDef message = (MessageDef) def; + action.accept(message); + for (Definition inner : message.getDefinitions()) { + forEachMessage(inner, action); + } + } + } + + /** + * Whether a value of the given message is written with a type tag, when referenced through one of + * its abstract generalizations. + * + *

+ * This is the case for a concrete message whose hierarchy root is abstract. + *

+ */ + private static boolean isTagged(MessageDef def) { + return !def.isAbstract() && def.getExtendedDef() != null && root(def).isAbstract(); + } + + /** + * The top-level names of the helper declarations generated for the given message (not + * including the helpers of nested messages). + */ + private static List helperNames(MessageDef def) { + List result = new ArrayList<>(); + if (hasPolymorphicType(def)) { + result.add(visitorName(def)); + result.add(dispatchName(def)); + result.add(guardName(def)); + } + if (isTagged(def)) { + result.add(tagName(def)); + } + return result; + } + + /** + * The name part of helper declarations for the given message. + * + *

+ * The name of the message qualified with the names of its outer messages, separated by + * _, with the first letter in upper case, e.g. Group_Info for + * message Info nested in Group. The package is not part of the name. + *

+ */ + private static String helperPart(MessageDef def) { + List names = new ArrayList<>(); + for (Definition current = def; current != null; current = current.getOuter()) { + names.add(0, current.getName()); + } + return CodeUtil.firstUpperCase(String.join("_", names)); + } + + /** + * Name of the visitor interface for the given abstract message. + */ + private static String visitorName(MessageDef def) { + return helperPart(def) + JSON_SUFFIX + "Visitor"; + } + + /** + * Name of the function dispatching a polymorphic value of the given abstract message to a + * visitor. + */ + private static String dispatchName(MessageDef def) { + return "visit" + helperPart(def) + JSON_SUFFIX; + } + + /** + * Name of the type guard for polymorphic values of the given abstract message. + */ + private static String guardName(MessageDef def) { + return "is" + POLYMORPHIC_PREFIX + helperPart(def) + JSON_SUFFIX; + } + + /** + * Name of the visitor method handling the given concrete message. + */ + private static String visitMethodName(MessageDef def) { + return "visit" + helperPart(def); + } + + /** + * Name of the function creating the type-tagged representation of the given concrete message. + */ + private static String tagName(MessageDef def) { + return "tag" + helperPart(def); + } + + /** + * Whether the polymorphic values of the given abstract message may have types that are not + * known to the generated module (option OpenWorld of the hierarchy root). + */ + private static boolean isOpen(MessageDef def) { + return Util.getFlag(Util.definingFile(root(def)), "OpenWorld"); + } + + /** + * Checks that the names of the TypeScript helper declarations of the given file are unique. + * + *

+ * The visitor method names of a hierarchy must be unique within the hierarchy (also across + * files), and the helper function names of a module must be unique within the module. + *

+ * + * @param file + * The file to generate a TypeScript module for. + * @param source + * Description of a file for error messages. + * @param errors + * The errors found. + */ + public static void validate(DefinitionFile file, Function source, List errors) { + if (!hasHelpers(file)) { + return; + } + Set reported = new HashSet<>(); + Map moduleNames = new LinkedHashMap<>(); + for (Definition def : file.getDefinitions()) { + forEachMessage(def, message -> { + for (String name : helperNames(message)) { + MessageDef clash = moduleNames.putIfAbsent(name, message); + if (clash != null) { + errors.add(source.apply(file) + ": The TypeScript declaration '" + name + "' is generated for message '" + + protoName(clash) + "' and for message '" + protoName(message) + "'. " + renameHint()); + } + } + + if (hasPolymorphicType(message)) { + Map methods = new LinkedHashMap<>(); + for (MessageDef specialization : Util.concreteTransitiveSpecializations(message)) { + String method = visitMethodName(specialization); + MessageDef clash = methods.putIfAbsent(method, specialization); + if (clash != null && reported.add(protoName(clash) + " " + protoName(specialization))) { + errors.add(source.apply(file) + ": The TypeScript visitor '" + visitorName(message) + "' of message '" + + protoName(message) + "' requires a method '" + method + "' for message '" + protoName(clash) + + "' of '" + source.apply(Util.definingFile(clash)) + "' and for message '" + + protoName(specialization) + "' of '" + source.apply(Util.definingFile(specialization)) + + "'. " + renameHint()); + } + } + } + }); + } + } + + /** + * The name of the given definition qualified with its package and outer messages, as written in + * the .proto file. + */ + private static String protoName(Definition def) { + List names = new ArrayList<>(); + for (Definition current = def; current != null; current = current.getOuter()) { + names.add(0, current.getName()); + } + QName pkg = Util.definingFile(def).getPackage(); + if (pkg != null) { + names.addAll(0, pkg.getNames()); + } + return String.join(".", names); + } + + private static String renameHint() { + return "Rename one of the messages (TypeScript helper names are derived from the message name qualified with" + + " the names of its outer messages, joined with '_', without the package)."; + } + + /** + * Generates the helper declarations for the given top-level definition and its nested + * definitions. + * + *

+ * All helpers are placed at the top level of the module, also for nested definitions: A + * namespace containing values is not erasable TypeScript syntax, only type declarations are + * placed in namespaces. + *

+ */ + private void generateHelpers(Definition def) { + forEachMessage(def, message -> { + if (hasPolymorphicType(message)) { + generateVisitor(message); + generateDispatch(message); + generateGuard(message); + } + if (isTagged(message)) { + generateTag(message); + } + }); + } + + private void generateVisitor(MessageDef def) { + List specializations = Util.concreteTransitiveSpecializations(def); + boolean open = isOpen(def); + String type = ref(def, null); + + separate(); + String comment = "Handlers for all concrete types of {@link " + type + "}."; + if (open) { + comment += "\n\nThe hierarchy is open (option OpenWorld), a type not known to this module is handled by {@link " + + visitorName(def) + ".visitDefault}."; + } + docComment(comment); + if (specializations.isEmpty() && !open) { + line("export interface " + visitorName(def) + " {}"); + return; + } + line("export interface " + visitorName(def) + " {"); + boolean first = true; + for (MessageDef specialization : specializations) { + if (first) { + first = false; + } else { + nl(); + } + String specializationType = ref(specialization, null); + docComment("Handles a {@link " + specializationType + "}."); + line("" + visitMethodName(specialization) + "(self: " + specializationType + "): R;"); + } + if (open) { + if (!first) { + nl(); + } + docComment("Handles a type that is not known to this module, e.g. an extension defined in another module.\n\n" + + "@param self - The properties of the value.\n" + + "@param typeId - The type ID of the value."); + line("visitDefault(self: " + type + ", typeId: string): R;"); + } + line("}"); + } + + private void generateDispatch(MessageDef def) { + boolean open = isOpen(def); + separate(); + docComment("Dispatches a type-tagged {@link " + polymorphicRef(def, null) + + "} value to the handler of its concrete type.\n\n" + + (open + ? "A type ID not known to this module is dispatched to {@link " + visitorName(def) + ".visitDefault}." + : "@throws Error if the type ID is not known.")); + line("export function " + dispatchName(def) + "(value: " + polymorphicRef(def, null) + ", visitor: " + + visitorName(def) + "): R {"); + line("switch (value[0]) {"); + for (MessageDef specialization : Util.concreteTransitiveSpecializations(def)) { + String self = open ? "value[1] as " + ref(specialization, null) : "value[1]"; + line("case " + stringLiteral(MsgBufJsonProtocol.typeId(specialization)) + ": return visitor." + + visitMethodName(specialization) + "(" + self + ");"); + } + if (open) { + line("default: return visitor.visitDefault(value[1], value[0]);"); + } else { + // A missing case is a compile error: the type ID is not narrowed to never. + line("default: {"); + line("const unknownType: never = value[0];"); + line("throw new Error('Unknown type ID: ' + unknownType);"); + line("}"); + } + line("}"); + line("}"); + } + + private void generateGuard(MessageDef def) { + boolean open = isOpen(def); + List specializations = Util.concreteTransitiveSpecializations(def); + String type = polymorphicRef(def, null); + + separate(); + docComment("Checks whether the given value is a type-tagged {@link " + type + "} value: a tuple of a " + + (open ? "type ID" : "known type ID") + " and an object.\n\n" + + "Only the type ID and the shape of the tuple are checked, not the properties of the object."); + line("export function " + guardName(def) + "(value: unknown): value is " + type + " {"); + if (specializations.isEmpty() && !open) { + line("// No concrete type is known."); + line("return false;"); + } else { + String tagCheck; + if (open) { + tagCheck = "typeof value[0] === 'string'"; + } else { + List checks = new ArrayList<>(); + for (MessageDef specialization : specializations) { + checks.add("value[0] === " + stringLiteral(MsgBufJsonProtocol.typeId(specialization))); + } + tagCheck = checks.size() == 1 ? checks.get(0) : "(" + String.join(" || ", checks) + ")"; + } + line("return Array.isArray(value) && value.length === 2"); + line("\t&& " + tagCheck); + line("\t&& typeof value[1] === 'object' && value[1] !== null && !Array.isArray(value[1]);"); + } + line("}"); + } + + private void generateTag(MessageDef def) { + String type = ref(def, null); + String tag = stringLiteral(MsgBufJsonProtocol.typeId(def)); + separate(); + docComment("Creates the type-tagged JSON representation of a {@link " + type + "}."); + line("export function " + tagName(def) + "(self: " + type + "): [" + tag + ", " + type + "] {"); + line("return [" + tag + ", self];"); + line("}"); + } + private String fileComment() { String comment = doc(_proto.getComment(), null); return comment == null || comment.isEmpty() ? "" : comment + "\n\n@packageDocumentation"; diff --git a/de.haumacher.msgbuf.generator/src/test/java/de/haumacher/msgbuf/generator/ts/TestTypeScriptGenerator.java b/de.haumacher.msgbuf.generator/src/test/java/de/haumacher/msgbuf/generator/ts/TestTypeScriptGenerator.java index 22057caa..5a38d758 100644 --- a/de.haumacher.msgbuf.generator/src/test/java/de/haumacher/msgbuf/generator/ts/TestTypeScriptGenerator.java +++ b/de.haumacher.msgbuf.generator/src/test/java/de/haumacher/msgbuf/generator/ts/TestTypeScriptGenerator.java @@ -8,6 +8,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -15,7 +16,9 @@ import java.util.stream.Stream; import de.haumacher.msgbuf.generator.Generator; +import de.haumacher.msgbuf.generator.GeneratorException; import de.haumacher.msgbuf.generator.GeneratorPlugin; +import de.haumacher.msgbuf.generator.parser.ParseException; import junit.framework.TestCase; /** @@ -36,6 +39,8 @@ public class TestTypeScriptGenerator extends TestCase { private static final File EXPECTED_DIR = new File(BASE, "expected"); + private static final File REJECT_DIR = new File("src/test/resources/reject/ts"); + public void testGolden() throws Exception { File outDir = new File("target/ts-test"); deleteRecursively(outDir.toPath()); @@ -73,6 +78,44 @@ public void testGolden() throws Exception { } } + /** Helper names generated for different messages of a module or hierarchy must not clash. */ + public void testHelperNameClash() throws Exception { + String hint = " Rename one of the messages (TypeScript helper names are derived from the message name qualified with" + + " the names of its outer messages, joined with '_', without the package)."; + assertEquals(Arrays.asList( + "reject/ts/collide/names.proto: The TypeScript visitor 'RootJsonVisitor' of message 'reject.ts.collide.Root' requires a method 'visitA_B' for message 'reject.ts.collide.A_B' of 'reject/ts/collide/names.proto' and for message 'reject.ts.collide.A.B' of 'reject/ts/collide/names.proto'." + hint, + "reject/ts/collide/names.proto: The TypeScript declaration 'tagA_B' is generated for message 'reject.ts.collide.A_B' and for message 'reject.ts.collide.A.B'." + hint), + reject("collide/names.proto")); + } + + /** Visitor method names must be unique in a hierarchy across files. */ + public void testVisitorMethodClashAcrossFiles() throws Exception { + assertEquals(Arrays.asList( + "reject/ts/open/base.proto: The TypeScript visitor 'ShapeJsonVisitor' of message 'reject.ts.open.Shape' requires a method 'visitCircle' for message 'reject.ts.one.Circle' of 'reject/ts/one/one.proto' and for message 'reject.ts.two.Circle' of 'reject/ts/two/two.proto'. Rename one of the messages (TypeScript helper names are derived from the message name qualified with the names of its outer messages, joined with '_', without the package)."), + reject("open/base.proto", "open/one.proto", "open/two.proto")); + } + + private List reject(String... protos) throws IOException, ParseException { + File target = new File("target"); + target.mkdirs(); + File out = Files.createTempDirectory(target.toPath(), getName()).toFile(); + Generator generator = new Generator(); + generator.setOut(new File(out, "java")); + generator.setTypeScriptOut(new File(out, "ts")); + for (String proto : protos) { + generator.load(new File(REJECT_DIR, proto)); + } + try { + generator.generate(GeneratorPlugin.none()); + fail("Expected rejection of " + Arrays.toString(protos) + "."); + return null; + } catch (GeneratorException ex) { + String[] written = out.list(); + assertTrue("No code must be generated for rejected definitions.", written == null || written.length == 0); + return ex.getErrors(); + } + } + private static List protoFiles() throws IOException { try (Stream files = Files.walk(PROTO_DIR.toPath())) { return files diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/ts/collide/names.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/ts/collide/names.proto new file mode 100644 index 00000000..b17d83c8 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/ts/collide/names.proto @@ -0,0 +1,15 @@ +package reject.ts.collide; + +abstract message Root { +} + +/** Helper name part 'A_B'. */ +message A_B extends Root { +} + +message A { + /** Helper name part 'A_B' as well. */ + @Name("A.B") + message B extends Root { + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/ts/open/base.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/ts/open/base.proto new file mode 100644 index 00000000..091d4c48 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/ts/open/base.proto @@ -0,0 +1,6 @@ +package reject.ts.open; + +option OpenWorld; + +abstract message Shape { +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/ts/open/one.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/ts/open/one.proto new file mode 100644 index 00000000..0f2ca719 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/ts/open/one.proto @@ -0,0 +1,6 @@ +package reject.ts.one; + +import "base.proto"; + +message Circle extends reject.ts.open.Shape { +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/ts/open/two.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/ts/open/two.proto new file mode 100644 index 00000000..8409a512 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/ts/open/two.proto @@ -0,0 +1,7 @@ +package reject.ts.two; + +import "base.proto"; + +@Name("two.Circle") +message Circle extends reject.ts.open.Shape { +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/commands/commands.ts b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/commands/commands.ts new file mode 100644 index 00000000..6cf31ff5 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/commands/commands.ts @@ -0,0 +1,549 @@ +// Generated by msgbuf from 'test/ts/commands/commands.proto'. Do not edit. +// +// Type definitions for the msgbuf JSON format of the protocol, and helper functions for its +// type-tagged polymorphic values (visitor dispatch, tagging, tag guards). + +/** + * Commands for testing the TypeScript helpers of polymorphic values in a closed hierarchy. + * + * @packageDocumentation + */ + +/** + * Root of a closed hierarchy. + * + * Abstract type, the properties are only present in the JSON of its concrete specializations. + */ +export interface CommandJson { + /** + * The command ID. + */ + id: string; +} + +/** + * Polymorphic JSON representation of a {@link CommandJson}: a tuple of the type ID and the properties of a concrete type. + */ +export type AnyCommandJson = ['Script', ScriptJson] | ['Batch', BatchJson] | ['Batch.Item', BatchJson.Item] | ['Macro', MacroJson] | ['Insert', InsertJson] | ['delete', deleteJson] | ['Macro.Item', MacroJson.Item] | ['Bold', BoldJson] | ['Replace', ReplaceJson]; + +/** + * Handlers for all concrete types of {@link CommandJson}. + */ +export interface CommandJsonVisitor { + /** + * Handles a {@link ScriptJson}. + */ + visitScript(self: ScriptJson): R; + + /** + * Handles a {@link BatchJson}. + */ + visitBatch(self: BatchJson): R; + + /** + * Handles a {@link BatchJson.Item}. + */ + visitBatch_Item(self: BatchJson.Item): R; + + /** + * Handles a {@link MacroJson}. + */ + visitMacro(self: MacroJson): R; + + /** + * Handles a {@link InsertJson}. + */ + visitInsert(self: InsertJson): R; + + /** + * Handles a {@link deleteJson}. + */ + visitDelete(self: deleteJson): R; + + /** + * Handles a {@link MacroJson.Item}. + */ + visitMacro_Item(self: MacroJson.Item): R; + + /** + * Handles a {@link BoldJson}. + */ + visitBold(self: BoldJson): R; + + /** + * Handles a {@link ReplaceJson}. + */ + visitReplace(self: ReplaceJson): R; +} + +/** + * Dispatches a type-tagged {@link AnyCommandJson} value to the handler of its concrete type. + * + * @throws Error if the type ID is not known. + */ +export function visitCommandJson(value: AnyCommandJson, visitor: CommandJsonVisitor): R { + switch (value[0]) { + case 'Script': return visitor.visitScript(value[1]); + case 'Batch': return visitor.visitBatch(value[1]); + case 'Batch.Item': return visitor.visitBatch_Item(value[1]); + case 'Macro': return visitor.visitMacro(value[1]); + case 'Insert': return visitor.visitInsert(value[1]); + case 'delete': return visitor.visitDelete(value[1]); + case 'Macro.Item': return visitor.visitMacro_Item(value[1]); + case 'Bold': return visitor.visitBold(value[1]); + case 'Replace': return visitor.visitReplace(value[1]); + default: { + const unknownType: never = value[0]; + throw new Error('Unknown type ID: ' + unknownType); + } + } +} + +/** + * Checks whether the given value is a type-tagged {@link AnyCommandJson} value: a tuple of a known type ID and an object. + * + * Only the type ID and the shape of the tuple are checked, not the properties of the object. + */ +export function isAnyCommandJson(value: unknown): value is AnyCommandJson { + return Array.isArray(value) && value.length === 2 + && (value[0] === 'Script' || value[0] === 'Batch' || value[0] === 'Batch.Item' || value[0] === 'Macro' || value[0] === 'Insert' || value[0] === 'delete' || value[0] === 'Macro.Item' || value[0] === 'Bold' || value[0] === 'Replace') + && typeof value[1] === 'object' && value[1] !== null && !Array.isArray(value[1]); +} + +/** + * Abstract intermediate at level two. + * + * Abstract type, the properties are only present in the JSON of its concrete specializations. + */ +export interface EditJson extends CommandJson { + /** + * The edited element. + */ + target: string; +} + +/** + * Polymorphic JSON representation of a {@link EditJson}: a tuple of the type ID and the properties of a concrete type. + */ +export type AnyEditJson = ['Insert', InsertJson] | ['delete', deleteJson] | ['Macro.Item', MacroJson.Item] | ['Bold', BoldJson] | ['Replace', ReplaceJson]; + +/** + * Handlers for all concrete types of {@link EditJson}. + */ +export interface EditJsonVisitor { + /** + * Handles a {@link InsertJson}. + */ + visitInsert(self: InsertJson): R; + + /** + * Handles a {@link deleteJson}. + */ + visitDelete(self: deleteJson): R; + + /** + * Handles a {@link MacroJson.Item}. + */ + visitMacro_Item(self: MacroJson.Item): R; + + /** + * Handles a {@link BoldJson}. + */ + visitBold(self: BoldJson): R; + + /** + * Handles a {@link ReplaceJson}. + */ + visitReplace(self: ReplaceJson): R; +} + +/** + * Dispatches a type-tagged {@link AnyEditJson} value to the handler of its concrete type. + * + * @throws Error if the type ID is not known. + */ +export function visitEditJson(value: AnyEditJson, visitor: EditJsonVisitor): R { + switch (value[0]) { + case 'Insert': return visitor.visitInsert(value[1]); + case 'delete': return visitor.visitDelete(value[1]); + case 'Macro.Item': return visitor.visitMacro_Item(value[1]); + case 'Bold': return visitor.visitBold(value[1]); + case 'Replace': return visitor.visitReplace(value[1]); + default: { + const unknownType: never = value[0]; + throw new Error('Unknown type ID: ' + unknownType); + } + } +} + +/** + * Checks whether the given value is a type-tagged {@link AnyEditJson} value: a tuple of a known type ID and an object. + * + * Only the type ID and the shape of the tuple are checked, not the properties of the object. + */ +export function isAnyEditJson(value: unknown): value is AnyEditJson { + return Array.isArray(value) && value.length === 2 + && (value[0] === 'Insert' || value[0] === 'delete' || value[0] === 'Macro.Item' || value[0] === 'Bold' || value[0] === 'Replace') + && typeof value[1] === 'object' && value[1] !== null && !Array.isArray(value[1]); +} + +/** + * Abstract intermediate at level three. + * + * Abstract type, the properties are only present in the JSON of its concrete specializations. + */ +export interface StyledEditJson extends EditJson { + /** + * The style to apply. + */ + style: string; +} + +/** + * Polymorphic JSON representation of a {@link StyledEditJson}: a tuple of the type ID and the properties of a concrete type. + */ +export type AnyStyledEditJson = ['Bold', BoldJson]; + +/** + * Handlers for all concrete types of {@link StyledEditJson}. + */ +export interface StyledEditJsonVisitor { + /** + * Handles a {@link BoldJson}. + */ + visitBold(self: BoldJson): R; +} + +/** + * Dispatches a type-tagged {@link AnyStyledEditJson} value to the handler of its concrete type. + * + * @throws Error if the type ID is not known. + */ +export function visitStyledEditJson(value: AnyStyledEditJson, visitor: StyledEditJsonVisitor): R { + switch (value[0]) { + case 'Bold': return visitor.visitBold(value[1]); + default: { + const unknownType: never = value[0]; + throw new Error('Unknown type ID: ' + unknownType); + } + } +} + +/** + * Checks whether the given value is a type-tagged {@link AnyStyledEditJson} value: a tuple of a known type ID and an object. + * + * Only the type ID and the shape of the tuple are checked, not the properties of the object. + */ +export function isAnyStyledEditJson(value: unknown): value is AnyStyledEditJson { + return Array.isArray(value) && value.length === 2 + && value[0] === 'Bold' + && typeof value[1] === 'object' && value[1] !== null && !Array.isArray(value[1]); +} + +/** + * A concrete edit at level three. + */ +export interface InsertJson extends EditJson { + text: string; +} + +/** + * Creates the type-tagged JSON representation of a {@link InsertJson}. + */ +export function tagInsert(self: InsertJson): ['Insert', InsertJson] { + return ['Insert', self]; +} + +/** + * A concrete type specializing a concrete type. + */ +export interface ReplaceJson extends InsertJson { + length: number; +} + +/** + * Creates the type-tagged JSON representation of a {@link ReplaceJson}. + */ +export function tagReplace(self: ReplaceJson): ['Replace', ReplaceJson] { + return ['Replace', self]; +} + +/** + * A concrete edit at level four. + */ +export interface BoldJson extends StyledEditJson {} + +/** + * Creates the type-tagged JSON representation of a {@link BoldJson}. + */ +export function tagBold(self: BoldJson): ['Bold', BoldJson] { + return ['Bold', self]; +} + +/** + * A message whose name is a reserved word in TypeScript. + */ +export interface deleteJson extends EditJson { + count: number; +} + +/** + * Creates the type-tagged JSON representation of a {@link deleteJson}. + */ +export function tagDelete(self: deleteJson): ['delete', deleteJson] { + return ['delete', self]; +} + +/** + * A message with polymorphic collections. + */ +export interface ScriptJson extends CommandJson { + /** + * A polymorphic list. + */ + steps: AnyCommandJson[]; + + /** + * A polymorphic map. + */ + named: Record; + + /** + * A polymorphic map with a key that is not a string. + */ + numbered: Array<{ key: number; value: AnyEditJson }>; + + /** + * An optional polymorphic value of an intermediate. + */ + style?: AnyStyledEditJson; +} + +/** + * Creates the type-tagged JSON representation of a {@link ScriptJson}. + */ +export function tagScript(self: ScriptJson): ['Script', ScriptJson] { + return ['Script', self]; +} + +/** + * Container of a nested message named like one in {@link MacroJson}. + */ +export interface BatchJson extends CommandJson { + /** + * Monomorphic references. + */ + items: BatchJson.Item[]; +} + +export namespace BatchJson { + /** + * Nested specialization of the root. + */ + export interface Item extends CommandJson { + note: string; + } +} + +/** + * Creates the type-tagged JSON representation of a {@link BatchJson}. + */ +export function tagBatch(self: BatchJson): ['Batch', BatchJson] { + return ['Batch', self]; +} + +/** + * Creates the type-tagged JSON representation of a {@link BatchJson.Item}. + */ +export function tagBatch_Item(self: BatchJson.Item): ['Batch.Item', BatchJson.Item] { + return ['Batch.Item', self]; +} + +/** + * Container of a nested message named like one in {@link BatchJson}, and of a nested hierarchy. + */ +export interface MacroJson extends CommandJson { + /** + * Steps of the nested hierarchy. + */ + steps: MacroJson.AnyStep[]; + + /** + * Items of the intermediate. + */ + edits: AnyEditJson[]; +} + +export namespace MacroJson { + /** + * Nested specialization of an intermediate. + */ + export interface Item extends EditJson { + repeat: number; + } + + /** + * Root of a nested hierarchy. + * + * Abstract type, the properties are only present in the JSON of its concrete specializations. + */ + export interface Step {} + + /** + * Polymorphic JSON representation of a {@link Step}: a tuple of the type ID and the properties of a concrete type. + */ + export type AnyStep = ['Wait', MacroJson.Wait] | ['Group.Wait', MacroJson.Group.Wait]; + + /** + * Specialization in the nested hierarchy. + */ + export interface Wait extends MacroJson.Step { + millis: number; + } + + /** + * Specialization in the nested hierarchy nested in another nested message. + */ + export interface Group {} + + export namespace Group { + /** + * Needs a type ID different from the one of {@link MacroJson.Wait}. + */ + export interface Wait extends MacroJson.Step { + count: number; + } + } +} + +/** + * Creates the type-tagged JSON representation of a {@link MacroJson}. + */ +export function tagMacro(self: MacroJson): ['Macro', MacroJson] { + return ['Macro', self]; +} + +/** + * Creates the type-tagged JSON representation of a {@link MacroJson.Item}. + */ +export function tagMacro_Item(self: MacroJson.Item): ['Macro.Item', MacroJson.Item] { + return ['Macro.Item', self]; +} + +/** + * Handlers for all concrete types of {@link MacroJson.Step}. + */ +export interface Macro_StepJsonVisitor { + /** + * Handles a {@link MacroJson.Wait}. + */ + visitMacro_Wait(self: MacroJson.Wait): R; + + /** + * Handles a {@link MacroJson.Group.Wait}. + */ + visitMacro_Group_Wait(self: MacroJson.Group.Wait): R; +} + +/** + * Dispatches a type-tagged {@link MacroJson.AnyStep} value to the handler of its concrete type. + * + * @throws Error if the type ID is not known. + */ +export function visitMacro_StepJson(value: MacroJson.AnyStep, visitor: Macro_StepJsonVisitor): R { + switch (value[0]) { + case 'Wait': return visitor.visitMacro_Wait(value[1]); + case 'Group.Wait': return visitor.visitMacro_Group_Wait(value[1]); + default: { + const unknownType: never = value[0]; + throw new Error('Unknown type ID: ' + unknownType); + } + } +} + +/** + * Checks whether the given value is a type-tagged {@link MacroJson.AnyStep} value: a tuple of a known type ID and an object. + * + * Only the type ID and the shape of the tuple are checked, not the properties of the object. + */ +export function isAnyMacro_StepJson(value: unknown): value is MacroJson.AnyStep { + return Array.isArray(value) && value.length === 2 + && (value[0] === 'Wait' || value[0] === 'Group.Wait') + && typeof value[1] === 'object' && value[1] !== null && !Array.isArray(value[1]); +} + +/** + * Creates the type-tagged JSON representation of a {@link MacroJson.Wait}. + */ +export function tagMacro_Wait(self: MacroJson.Wait): ['Wait', MacroJson.Wait] { + return ['Wait', self]; +} + +/** + * Creates the type-tagged JSON representation of a {@link MacroJson.Group.Wait}. + */ +export function tagMacro_Group_Wait(self: MacroJson.Group.Wait): ['Group.Wait', MacroJson.Group.Wait] { + return ['Group.Wait', self]; +} + +/** + * An abstract root without concrete types. + * + * Abstract type, the properties are only present in the JSON of its concrete specializations. + */ +export interface EmptyJson {} + +/** + * Polymorphic JSON representation of a {@link EmptyJson}: a tuple of the type ID and the properties of a concrete type. + */ +export type AnyEmptyJson = never; + +/** + * Handlers for all concrete types of {@link EmptyJson}. + */ +export interface EmptyJsonVisitor {} + +/** + * Dispatches a type-tagged {@link AnyEmptyJson} value to the handler of its concrete type. + * + * @throws Error if the type ID is not known. + */ +export function visitEmptyJson(value: AnyEmptyJson, visitor: EmptyJsonVisitor): R { + switch (value[0]) { + default: { + const unknownType: never = value[0]; + throw new Error('Unknown type ID: ' + unknownType); + } + } +} + +/** + * Checks whether the given value is a type-tagged {@link AnyEmptyJson} value: a tuple of a known type ID and an object. + * + * Only the type ID and the shape of the tuple are checked, not the properties of the object. + */ +export function isAnyEmptyJson(value: unknown): value is AnyEmptyJson { + // No concrete type is known. + return false; +} + +/** + * Concrete root of a hierarchy without type tags: no helpers. + */ +export interface PlainJson { + name: string; +} + +/** + * Specialization of a concrete root: no helpers. + */ +export interface FancyJson extends PlainJson { + color: string; +} + +/** + * An abstract message below a concrete root: no helpers. + * + * Abstract type, the properties are only present in the JSON of its concrete specializations. + */ +export interface AbstractedJson extends PlainJson {} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/common/common.ts b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/common/common.ts index b6b3f720..cf9c5b6c 100644 --- a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/common/common.ts +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/common/common.ts @@ -1,6 +1,7 @@ // Generated by msgbuf from 'test/ts/common/common.proto'. Do not edit. // -// Type definitions for the msgbuf JSON format of the protocol (types only, no runtime code). +// Type definitions for the msgbuf JSON format of the protocol, and helper functions for its +// type-tagged polymorphic values (visitor dispatch, tagging, tag guards). /** * Common types, documented at the package declaration. @@ -57,6 +58,48 @@ export interface NodeJson { */ export type AnyNodeJson = ['Leaf', LeafJson] | ['Inner', InnerJson]; +/** + * Handlers for all concrete types of {@link NodeJson}. + */ +export interface NodeJsonVisitor { + /** + * Handles a {@link LeafJson}. + */ + visitLeaf(self: LeafJson): R; + + /** + * Handles a {@link InnerJson}. + */ + visitInner(self: InnerJson): R; +} + +/** + * Dispatches a type-tagged {@link AnyNodeJson} value to the handler of its concrete type. + * + * @throws Error if the type ID is not known. + */ +export function visitNodeJson(value: AnyNodeJson, visitor: NodeJsonVisitor): R { + switch (value[0]) { + case 'Leaf': return visitor.visitLeaf(value[1]); + case 'Inner': return visitor.visitInner(value[1]); + default: { + const unknownType: never = value[0]; + throw new Error('Unknown type ID: ' + unknownType); + } + } +} + +/** + * Checks whether the given value is a type-tagged {@link AnyNodeJson} value: a tuple of a known type ID and an object. + * + * Only the type ID and the shape of the tuple are checked, not the properties of the object. + */ +export function isAnyNodeJson(value: unknown): value is AnyNodeJson { + return Array.isArray(value) && value.length === 2 + && (value[0] === 'Leaf' || value[0] === 'Inner') + && typeof value[1] === 'object' && value[1] !== null && !Array.isArray(value[1]); +} + /** * A leaf node. */ @@ -67,6 +110,13 @@ export interface LeafJson extends NodeJson { value: number; } +/** + * Creates the type-tagged JSON representation of a {@link LeafJson}. + */ +export function tagLeaf(self: LeafJson): ['Leaf', LeafJson] { + return ['Leaf', self]; +} + /** * An inner node. */ @@ -76,3 +126,10 @@ export interface InnerJson extends NodeJson { */ children: AnyNodeJson[]; } + +/** + * Creates the type-tagged JSON representation of a {@link InnerJson}. + */ +export function tagInner(self: InnerJson): ['Inner', InnerJson] { + return ['Inner', self]; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/events/base/base.ts b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/events/base/base.ts new file mode 100644 index 00000000..dc61df41 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/events/base/base.ts @@ -0,0 +1,197 @@ +// Generated by msgbuf from 'test/ts/events/base/base.proto'. Do not edit. +// +// Type definitions for the msgbuf JSON format of the protocol, and helper functions for its +// type-tagged polymorphic values (visitor dispatch, tagging, tag guards). + +/** + * An OpenWorld hierarchy extended in another file. + * + * @packageDocumentation + */ + +import type { OuterJson, RemoveJson, AlertJson } from '../ext/ext'; + +/** + * Root of an open hierarchy. + * + * Abstract type, the properties are only present in the JSON of its concrete specializations. + */ +export interface EventJson { + /** + * Time of the event. + */ + timestamp: number; +} + +/** + * Polymorphic JSON representation of a {@link EventJson}: a tuple of the type ID and the properties of a concrete type. + */ +export type AnyEventJson = ['Ping', PingJson] | ['Outer.Ping', OuterJson.Ping] | ['set', UpdateJson] | ['Remove', RemoveJson] | ['Alert', AlertJson] | [string, EventJson]; + +/** + * Handlers for all concrete types of {@link EventJson}. + * + * The hierarchy is open (option OpenWorld), a type not known to this module is handled by {@link EventJsonVisitor.visitDefault}. + */ +export interface EventJsonVisitor { + /** + * Handles a {@link PingJson}. + */ + visitPing(self: PingJson): R; + + /** + * Handles a {@link OuterJson.Ping}. + */ + visitOuter_Ping(self: OuterJson.Ping): R; + + /** + * Handles a {@link UpdateJson}. + */ + visitUpdate(self: UpdateJson): R; + + /** + * Handles a {@link RemoveJson}. + */ + visitRemove(self: RemoveJson): R; + + /** + * Handles a {@link AlertJson}. + */ + visitAlert(self: AlertJson): R; + + /** + * Handles a type that is not known to this module, e.g. an extension defined in another module. + * + * @param self - The properties of the value. + * @param typeId - The type ID of the value. + */ + visitDefault(self: EventJson, typeId: string): R; +} + +/** + * Dispatches a type-tagged {@link AnyEventJson} value to the handler of its concrete type. + * + * A type ID not known to this module is dispatched to {@link EventJsonVisitor.visitDefault}. + */ +export function visitEventJson(value: AnyEventJson, visitor: EventJsonVisitor): R { + switch (value[0]) { + case 'Ping': return visitor.visitPing(value[1] as PingJson); + case 'Outer.Ping': return visitor.visitOuter_Ping(value[1] as OuterJson.Ping); + case 'set': return visitor.visitUpdate(value[1] as UpdateJson); + case 'Remove': return visitor.visitRemove(value[1] as RemoveJson); + case 'Alert': return visitor.visitAlert(value[1] as AlertJson); + default: return visitor.visitDefault(value[1], value[0]); + } +} + +/** + * Checks whether the given value is a type-tagged {@link AnyEventJson} value: a tuple of a type ID and an object. + * + * Only the type ID and the shape of the tuple are checked, not the properties of the object. + */ +export function isAnyEventJson(value: unknown): value is AnyEventJson { + return Array.isArray(value) && value.length === 2 + && typeof value[0] === 'string' + && typeof value[1] === 'object' && value[1] !== null && !Array.isArray(value[1]); +} + +/** + * A local concrete type. + */ +export interface PingJson extends EventJson {} + +/** + * Creates the type-tagged JSON representation of a {@link PingJson}. + */ +export function tagPing(self: PingJson): ['Ping', PingJson] { + return ['Ping', self]; +} + +/** + * An abstract intermediate, extended in another file. + * + * Abstract type, the properties are only present in the JSON of its concrete specializations. + */ +export interface ChangeJson extends EventJson { + /** + * The changed key. + */ + key: string; +} + +/** + * Polymorphic JSON representation of a {@link ChangeJson}: a tuple of the type ID and the properties of a concrete type. + */ +export type AnyChangeJson = ['set', UpdateJson] | ['Remove', RemoveJson] | [string, ChangeJson]; + +/** + * Handlers for all concrete types of {@link ChangeJson}. + * + * The hierarchy is open (option OpenWorld), a type not known to this module is handled by {@link ChangeJsonVisitor.visitDefault}. + */ +export interface ChangeJsonVisitor { + /** + * Handles a {@link UpdateJson}. + */ + visitUpdate(self: UpdateJson): R; + + /** + * Handles a {@link RemoveJson}. + */ + visitRemove(self: RemoveJson): R; + + /** + * Handles a type that is not known to this module, e.g. an extension defined in another module. + * + * @param self - The properties of the value. + * @param typeId - The type ID of the value. + */ + visitDefault(self: ChangeJson, typeId: string): R; +} + +/** + * Dispatches a type-tagged {@link AnyChangeJson} value to the handler of its concrete type. + * + * A type ID not known to this module is dispatched to {@link ChangeJsonVisitor.visitDefault}. + */ +export function visitChangeJson(value: AnyChangeJson, visitor: ChangeJsonVisitor): R { + switch (value[0]) { + case 'set': return visitor.visitUpdate(value[1] as UpdateJson); + case 'Remove': return visitor.visitRemove(value[1] as RemoveJson); + default: return visitor.visitDefault(value[1], value[0]); + } +} + +/** + * Checks whether the given value is a type-tagged {@link AnyChangeJson} value: a tuple of a type ID and an object. + * + * Only the type ID and the shape of the tuple are checked, not the properties of the object. + */ +export function isAnyChangeJson(value: unknown): value is AnyChangeJson { + return Array.isArray(value) && value.length === 2 + && typeof value[0] === 'string' + && typeof value[1] === 'object' && value[1] !== null && !Array.isArray(value[1]); +} + +/** + * A local concrete type of the intermediate. + */ +export interface UpdateJson extends ChangeJson { + value: string; +} + +/** + * Creates the type-tagged JSON representation of a {@link UpdateJson}. + */ +export function tagUpdate(self: UpdateJson): ['set', UpdateJson] { + return ['set', self]; +} + +/** + * Polymorphic collections of the open hierarchy. + */ +export interface LogJson { + events: AnyEventJson[]; + + latest: Record; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/events/ext/ext.ts b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/events/ext/ext.ts new file mode 100644 index 00000000..e1b745fe --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/events/ext/ext.ts @@ -0,0 +1,116 @@ +// Generated by msgbuf from 'test/ts/events/ext/ext.proto'. Do not edit. +// +// Type definitions for the msgbuf JSON format of the protocol, and helper functions for its +// type-tagged polymorphic values (visitor dispatch, tagging, tag guards). + +/** + * Extensions of the OpenWorld hierarchy of another file. + * + * @packageDocumentation + */ + +import type { ChangeJson, EventJson } from '../base/base'; + +/** + * Specialization of the intermediate of another file. + */ +export interface RemoveJson extends ChangeJson {} + +/** + * Creates the type-tagged JSON representation of a {@link RemoveJson}. + */ +export function tagRemove(self: RemoveJson): ['Remove', RemoveJson] { + return ['Remove', self]; +} + +/** + * An abstract intermediate of the extension file. + * + * Abstract type, the properties are only present in the JSON of its concrete specializations. + */ +export interface NoticeJson extends EventJson { + text: string; +} + +/** + * Polymorphic JSON representation of a {@link NoticeJson}: a tuple of the type ID and the properties of a concrete type. + */ +export type AnyNoticeJson = ['Alert', AlertJson] | [string, NoticeJson]; + +/** + * Handlers for all concrete types of {@link NoticeJson}. + * + * The hierarchy is open (option OpenWorld), a type not known to this module is handled by {@link NoticeJsonVisitor.visitDefault}. + */ +export interface NoticeJsonVisitor { + /** + * Handles a {@link AlertJson}. + */ + visitAlert(self: AlertJson): R; + + /** + * Handles a type that is not known to this module, e.g. an extension defined in another module. + * + * @param self - The properties of the value. + * @param typeId - The type ID of the value. + */ + visitDefault(self: NoticeJson, typeId: string): R; +} + +/** + * Dispatches a type-tagged {@link AnyNoticeJson} value to the handler of its concrete type. + * + * A type ID not known to this module is dispatched to {@link NoticeJsonVisitor.visitDefault}. + */ +export function visitNoticeJson(value: AnyNoticeJson, visitor: NoticeJsonVisitor): R { + switch (value[0]) { + case 'Alert': return visitor.visitAlert(value[1] as AlertJson); + default: return visitor.visitDefault(value[1], value[0]); + } +} + +/** + * Checks whether the given value is a type-tagged {@link AnyNoticeJson} value: a tuple of a type ID and an object. + * + * Only the type ID and the shape of the tuple are checked, not the properties of the object. + */ +export function isAnyNoticeJson(value: unknown): value is AnyNoticeJson { + return Array.isArray(value) && value.length === 2 + && typeof value[0] === 'string' + && typeof value[1] === 'object' && value[1] !== null && !Array.isArray(value[1]); +} + +/** + * Specialization of the local intermediate. + */ +export interface AlertJson extends NoticeJson { + level: number; +} + +/** + * Creates the type-tagged JSON representation of a {@link AlertJson}. + */ +export function tagAlert(self: AlertJson): ['Alert', AlertJson] { + return ['Alert', self]; +} + +/** + * Outer message of a nested extension. + */ +export interface OuterJson { + notices: AnyNoticeJson[]; +} + +export namespace OuterJson { + /** + * A nested extension named like a type of the base file. + */ + export interface Ping extends EventJson {} +} + +/** + * Creates the type-tagged JSON representation of a {@link OuterJson.Ping}. + */ +export function tagOuter_Ping(self: OuterJson.Ping): ['Outer.Ping', OuterJson.Ping] { + return ['Outer.Ping', self]; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/graph/graph.ts b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/graph/graph.ts new file mode 100644 index 00000000..97748ffd --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/graph/graph.ts @@ -0,0 +1,28 @@ +// Generated by msgbuf from 'test/ts/graph/graph.proto'. Do not edit. +// +// Type definitions for the msgbuf JSON format of the protocol (types only, no runtime code). +// +// Note: The protocol uses 'option SharedGraph'. Its JSON format (objects as [type, id, {...}], +// references as object IDs, incremental updates) is not described by these types. No helper +// functions for polymorphic values are generated. + +/** + * Root of a hierarchy of a shared graph: no helpers. + * + * Abstract type, the properties are only present in the JSON of its concrete specializations. + */ +export interface ElementJson { + name: string; +} + +/** + * Polymorphic JSON representation of a {@link ElementJson}: a tuple of the type ID and the properties of a concrete type. + */ +export type AnyElementJson = ['Vertex', VertexJson]; + +/** + * A concrete element. + */ +export interface VertexJson extends ElementJson { + children: AnyElementJson[]; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/shapes/shapes.ts b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/shapes/shapes.ts index 7c98da66..b484d553 100644 --- a/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/shapes/shapes.ts +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/expected/test/ts/shapes/shapes.ts @@ -1,6 +1,7 @@ // Generated by msgbuf from 'test/ts/shapes/shapes.proto'. Do not edit. // -// Type definitions for the msgbuf JSON format of the protocol (types only, no runtime code). +// Type definitions for the msgbuf JSON format of the protocol, and helper functions for its +// type-tagged polymorphic values (visitor dispatch, tagging, tag guards). /** * Shapes and button states for testing the TypeScript generator. @@ -153,6 +154,54 @@ export interface ShapeJson { */ export type AnyShapeJson = ['Rectangle', RectangleJson] | ['Group', GroupJson] | ['circle', CircleJson]; +/** + * Handlers for all concrete types of {@link ShapeJson}. + */ +export interface ShapeJsonVisitor { + /** + * Handles a {@link RectangleJson}. + */ + visitRectangle(self: RectangleJson): R; + + /** + * Handles a {@link GroupJson}. + */ + visitGroup(self: GroupJson): R; + + /** + * Handles a {@link CircleJson}. + */ + visitCircle(self: CircleJson): R; +} + +/** + * Dispatches a type-tagged {@link AnyShapeJson} value to the handler of its concrete type. + * + * @throws Error if the type ID is not known. + */ +export function visitShapeJson(value: AnyShapeJson, visitor: ShapeJsonVisitor): R { + switch (value[0]) { + case 'Rectangle': return visitor.visitRectangle(value[1]); + case 'Group': return visitor.visitGroup(value[1]); + case 'circle': return visitor.visitCircle(value[1]); + default: { + const unknownType: never = value[0]; + throw new Error('Unknown type ID: ' + unknownType); + } + } +} + +/** + * Checks whether the given value is a type-tagged {@link AnyShapeJson} value: a tuple of a known type ID and an object. + * + * Only the type ID and the shape of the tuple are checked, not the properties of the object. + */ +export function isAnyShapeJson(value: unknown): value is AnyShapeJson { + return Array.isArray(value) && value.length === 2 + && (value[0] === 'Rectangle' || value[0] === 'Group' || value[0] === 'circle') + && typeof value[1] === 'object' && value[1] !== null && !Array.isArray(value[1]); +} + /** * Abstract intermediate class. * @@ -165,6 +214,42 @@ export interface RoundedJson extends ShapeJson {} */ export type AnyRoundedJson = ['circle', CircleJson]; +/** + * Handlers for all concrete types of {@link RoundedJson}. + */ +export interface RoundedJsonVisitor { + /** + * Handles a {@link CircleJson}. + */ + visitCircle(self: CircleJson): R; +} + +/** + * Dispatches a type-tagged {@link AnyRoundedJson} value to the handler of its concrete type. + * + * @throws Error if the type ID is not known. + */ +export function visitRoundedJson(value: AnyRoundedJson, visitor: RoundedJsonVisitor): R { + switch (value[0]) { + case 'circle': return visitor.visitCircle(value[1]); + default: { + const unknownType: never = value[0]; + throw new Error('Unknown type ID: ' + unknownType); + } + } +} + +/** + * Checks whether the given value is a type-tagged {@link AnyRoundedJson} value: a tuple of a known type ID and an object. + * + * Only the type ID and the shape of the tuple are checked, not the properties of the object. + */ +export function isAnyRoundedJson(value: unknown): value is AnyRoundedJson { + return Array.isArray(value) && value.length === 2 + && value[0] === 'circle' + && typeof value[1] === 'object' && value[1] !== null && !Array.isArray(value[1]); +} + /** * A circle. */ @@ -175,6 +260,13 @@ export interface CircleJson extends RoundedJson { r: number; } +/** + * Creates the type-tagged JSON representation of a {@link CircleJson}. + */ +export function tagCircle(self: CircleJson): ['circle', CircleJson] { + return ['circle', self]; +} + /** * A rectangle. */ @@ -184,6 +276,13 @@ export interface RectangleJson extends ShapeJson { height: number; } +/** + * Creates the type-tagged JSON representation of a {@link RectangleJson}. + */ +export function tagRectangle(self: RectangleJson): ['Rectangle', RectangleJson] { + return ['Rectangle', self]; +} + /** * A group of shapes. */ @@ -244,6 +343,13 @@ export namespace GroupJson { } } +/** + * Creates the type-tagged JSON representation of a {@link GroupJson}. + */ +export function tagGroup(self: GroupJson): ['Group', GroupJson] { + return ['Group', self]; +} + /** * An empty enum. */ diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/commands/commands.proto b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/commands/commands.proto new file mode 100644 index 00000000..62751f42 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/commands/commands.proto @@ -0,0 +1,127 @@ +/** + * Commands for testing the TypeScript helpers of polymorphic values in a closed hierarchy. + */ +syntax = "msgbuf"; + +package test.ts.commands; + +option NoXml; + +/* The Java TypeKind enums would contain the constants ITEM and WAIT twice (nested messages with equal names). */ +option NoTypeKind; + +/** Root of a closed hierarchy. */ +abstract message Command { + /** The command ID. */ + string id; +} + +/** Abstract intermediate at level two. */ +abstract message Edit extends Command { + /** The edited element. */ + string target; +} + +/** Abstract intermediate at level three. */ +abstract message StyledEdit extends Edit { + /** The style to apply. */ + string style; +} + +/** A concrete edit at level three. */ +message Insert extends Edit { + string text; +} + +/** A concrete type specializing a concrete type. */ +message Replace extends Insert { + int32 length; +} + +/** A concrete edit at level four. */ +message Bold extends StyledEdit { +} + +/** A message whose name is a reserved word in TypeScript. */ +message `delete` extends Edit { + int32 count; +} + +/** A message with polymorphic collections. */ +message Script extends Command { + /** A polymorphic list. */ + repeated Command steps; + + /** A polymorphic map. */ + map named; + + /** A polymorphic map with a key that is not a string. */ + map numbered; + + /** An optional polymorphic value of an intermediate. */ + @Nullable + StyledEdit style; +} + +/** Container of a nested message named like one in {@link Macro}. */ +message Batch extends Command { + /** Nested specialization of the root. */ + @Name("Batch.Item") + message Item extends Command { + string note; + } + + /** Monomorphic references. */ + repeated Item items; +} + +/** Container of a nested message named like one in {@link Batch}, and of a nested hierarchy. */ +message Macro extends Command { + /** Nested specialization of an intermediate. */ + @Name("Macro.Item") + message Item extends Edit { + int32 repeat; + } + + /** Root of a nested hierarchy. */ + abstract message Step { + } + + /** Specialization in the nested hierarchy. */ + message Wait extends Step { + int32 millis; + } + + /** Specialization in the nested hierarchy nested in another nested message. */ + message Group { + /** Needs a type ID different from the one of {@link Macro.Wait}. */ + @Name("Group.Wait") + message Wait extends Step { + int32 count; + } + } + + /** Steps of the nested hierarchy. */ + repeated Step steps; + + /** Items of the intermediate. */ + repeated Edit edits; +} + +/** An abstract root without concrete types. */ +abstract message Empty { +} + +/** Concrete root of a hierarchy without type tags: no helpers. */ +message Plain { + string name; +} + +/** Specialization of a concrete root: no helpers. */ +message Fancy extends Plain { + string color; +} + +/** An abstract message below a concrete root: no helpers. */ +abstract message Abstracted extends Plain { +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/events/base/base.proto b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/events/base/base.proto new file mode 100644 index 00000000..5b89db8f --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/events/base/base.proto @@ -0,0 +1,40 @@ +/** + * An OpenWorld hierarchy extended in another file. + */ +syntax = "msgbuf"; + +package test.ts.events.base; + +option OpenWorld; + +/* Maps are not supported in XML. */ +option NoXml; + +/** Root of an open hierarchy. */ +abstract message Event { + /** Time of the event. */ + int64 timestamp; +} + +/** A local concrete type. */ +message Ping extends Event { +} + +/** An abstract intermediate, extended in another file. */ +abstract message Change extends Event { + /** The changed key. */ + string key; +} + +/** A local concrete type of the intermediate. */ +@Name("set") +message Update extends Change { + string value; +} + +/** Polymorphic collections of the open hierarchy. */ +message Log { + repeated Event events; + + map latest; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/events/ext/ext.proto b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/events/ext/ext.proto new file mode 100644 index 00000000..8372ad71 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/events/ext/ext.proto @@ -0,0 +1,35 @@ +/** + * Extensions of the OpenWorld hierarchy of another file. + */ +syntax = "msgbuf"; + +package test.ts.events.ext; + +import "../base/base.proto"; + +/* Same format options as the base file. */ +option NoXml; + +/** Specialization of the intermediate of another file. */ +message Remove extends test.ts.events.base.Change { +} + +/** An abstract intermediate of the extension file. */ +abstract message Notice extends test.ts.events.base.Event { + string text; +} + +/** Specialization of the local intermediate. */ +message Alert extends Notice { + int32 level; +} + +/** Outer message of a nested extension. */ +message Outer { + /** A nested extension named like a type of the base file. */ + @Name("Outer.Ping") + message Ping extends test.ts.events.base.Event { + } + + repeated Notice notices; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/graph/graph.proto b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/graph/graph.proto new file mode 100644 index 00000000..d78b927b --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/ts/proto/test/ts/graph/graph.proto @@ -0,0 +1,15 @@ +syntax = "msgbuf"; + +package test.ts.graph; + +option SharedGraph; + +/** Root of a hierarchy of a shared graph: no helpers. */ +abstract message Element { + string name; +} + +/** A concrete element. */ +message Vertex extends Element { + repeated Element children; +} From e392a604d5af2cbb3bde9b0150586cc06a8de3b3 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 18:49:10 +0200 Subject: [PATCH 203/207] Fix uncompilable XML primitives, reject clashing type IDs and resolve names by package and imports. Reviewing the TypeScript helpers of #10 turned up three generator bugs that produced uncompilable or silently wrong code. The XML templates for bytes, fixed32 and uint32 did not compile since 1.1.0 (#44); auditing them also fixed null values and empty lists in XML, a binary writer that ignored the zig-zag and fixed-length encodings its own readers expected, and a 64 bit varint decoding bug in msgbuf-api. Messages of one hierarchy with equal type IDs, XML names or TypeKind constants, or named like a nested type of a generalization, generated duplicate cases and constants and are now rejected with an error naming both definitions (#45). Unqualified type names were looked up in one global table where the last loaded file won, so a file's meaning depended on unrelated files generated in the same run; they now resolve in the own package, then the imported files by import depth, and only then in the unique definition of any other file, and duplicate definitions stop the generation (#46). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 31 + README.md | 19 + .../msgbuf/generator/CodeConvention.java | 37 +- .../haumacher/msgbuf/generator/Generator.java | 239 ++- .../msgbuf/generator/GeneratorPlugin.java | 27 + .../msgbuf/generator/MessageGenerator.java | 28 +- .../haumacher/msgbuf/generator/NameTable.java | 242 ++- .../msgbuf/generator/common/Util.java | 29 + .../generator/plugins/XmlStreamingPlugin.java | 58 +- .../generator/ts/TypeScriptGenerator.java | 13 +- .../hierarchynames/TestHierarchyNames.java | 60 + .../test/java/test/hierarchynames/data/A.java | 92 + .../test/java/test/hierarchynames/data/B.java | 92 + .../test/hierarchynames/data/Container.java | 78 + .../java/test/hierarchynames/data/Item.java | 55 + .../java/test/hierarchynames/data/Msg.java | 64 + .../java/test/hierarchynames/data/Outer.java | 155 ++ .../test/hierarchynames/data/impl/A_Impl.java | 353 ++++ .../test/hierarchynames/data/impl/B_Impl.java | 353 ++++ .../data/impl/Container_Impl.java | 318 +++ .../hierarchynames/data/impl/Item_Impl.java | 188 ++ .../hierarchynames/data/impl/Msg_Impl.java | 164 ++ .../hierarchynames/data/impl/Outer_Impl.java | 579 ++++++ .../test/hierarchynames/hierarchynames.proto | 43 + .../nested/data/impl/SearchResponse_Impl.java | 5 +- .../java/test/nested/data/impl/Zoo_Impl.java | 5 +- .../data/impl/NullableValues_Impl.java | 38 +- .../test/validation/TestHierarchyClashes.java | 127 ++ .../test/validation/TestNameResolution.java | 180 ++ .../test/xmlprimitives/TestXmlPrimitives.java | 264 +++ .../java/test/xmlprimitives/data/Color.java | 64 + .../java/test/xmlprimitives/data/Lists.java | 413 ++++ .../test/xmlprimitives/data/Nullables.java | 463 +++++ .../java/test/xmlprimitives/data/Values.java | 271 +++ .../xmlprimitives/data/impl/Lists_Impl.java | 1800 +++++++++++++++++ .../data/impl/Nullables_Impl.java | 1549 ++++++++++++++ .../xmlprimitives/data/impl/Values_Impl.java | 926 +++++++++ .../test/xmlprimitives/xmlprimitives.proto | 77 + .../resources/reject/hierarchy/issue.proto | 9 + .../reject/hierarchy/open/base.proto | 5 + .../resources/reject/hierarchy/open/one.proto | 5 + .../resources/reject/hierarchy/open/two.proto | 5 + .../resources/reject/hierarchy/protocol.proto | 35 + .../resources/reject/hierarchy/shadow.proto | 18 + .../resources/reject/hierarchy/typekind.proto | 21 + .../src/test/resources/reject/names/a/a.proto | 21 + .../src/test/resources/reject/names/b/b.proto | 5 + .../src/test/resources/reject/names/c/c.proto | 6 + .../test/resources/reject/names/dup/one.proto | 3 + .../resources/reject/names/dup/twice.proto | 5 + .../test/resources/reject/names/dup/two.proto | 3 + .../test/resources/reject/names/imp/lib.proto | 3 + .../resources/reject/names/imp/main.proto | 7 + .../resources/reject/names/imports/a/a.proto | 5 + .../resources/reject/names/imports/b/b.proto | 3 + .../resources/reject/names/imports/c/c.proto | 6 + .../resources/reject/names/imports/d/d.proto | 6 + .../resources/reject/names/imports/e/e.proto | 7 + .../msgbuf/binary/OctetDataReader.java | 2 +- .../msgbuf/binary/TestDataReaderWriter.java | 31 + 60 files changed, 9626 insertions(+), 84 deletions(-) create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchynames/TestHierarchyNames.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchynames/data/A.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchynames/data/B.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchynames/data/Container.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchynames/data/Item.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchynames/data/Msg.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchynames/data/Outer.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchynames/data/impl/A_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchynames/data/impl/B_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchynames/data/impl/Container_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchynames/data/impl/Item_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchynames/data/impl/Msg_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchynames/data/impl/Outer_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/hierarchynames/hierarchynames.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/validation/TestHierarchyClashes.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/validation/TestNameResolution.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/TestXmlPrimitives.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Color.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Lists.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Nullables.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Values.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/impl/Lists_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/impl/Nullables_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/impl/Values_Impl.java create mode 100644 de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/xmlprimitives.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/issue.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/open/base.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/open/one.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/open/two.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/protocol.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/shadow.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/typekind.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/names/a/a.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/names/b/b.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/names/c/c.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/names/dup/one.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/names/dup/twice.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/names/dup/two.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/names/imp/lib.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/names/imp/main.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/a/a.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/b/b.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/c/c.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/d/d.proto create mode 100644 de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/e/e.proto diff --git a/CHANGELOG.md b/CHANGELOG.md index 51fa9f49..d758e540 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,37 @@ now read the types of other files. The generated registration class (e.g. `Ext1Types`) additionally registers the XML element name of each extension type with the root (`registerXml()`, `XML_REGISTRY`), if the files generate XML. The wire formats are unchanged. +- **Primitive types in XML and binary format** (#44): `bytes`, `fixed32` and `uint32` fields no longer generate + uncompilable XML code (all versions since 1.1.0). `bytes` are written in Base64, `fixed32`/`uint32` as unsigned + decimal (the readers also accept the signed form). Nullable fields that are not set are omitted in XML format, and + `bytes` fields without a value in XML and binary format, instead of failing with a `NullPointerException`. An empty `repeated` + value (written as empty attribute) is read as empty list (before, reading failed for numbers, and a list of strings + contained one empty string). In binary format, `sint32`/`sint64` values are now written zig-zag encoded and + `fixed32`/`sfixed32`/`fixed64`/`sfixed64` values in fixed length, as the readers always expected, and 64 bit values + above 32 bits are read correctly (fix in `msgbuf-api`). **Wire format change:** the binary encoding of these six + types changes; values written before could not be read back correctly (except `0`), and writing a `repeated` field + of these types failed. +- **Clashing type IDs in a hierarchy** (#45): Two concrete specializations of an abstract message with the same type + ID (by default the simple name, e.g. a top-level `Item` and a nested `Msg.Item`, or an equal `@Name`), the same XML + element name, or the same explicit `@type_id`, also in extension files of an `option OpenWorld` hierarchy generated + together, are rejected with an error naming both definitions. So are messages of one hierarchy with the same + `TypeKind` constant (fix: rename, or `option NoTypeKind`), and a message with the name of a nested definition of + one of its generalizations, which the generated class could not refer to. A top-level specialization whose simple + name is shadowed by a nested definition in the scope of its generalization is referenced by its qualified name in + the readers (before, the reader dispatched to the nested definition). **Source compatibility:** these definitions + generated uncompilable code before (or silently wrong readers), except equal type IDs in the `option OpenWorld` + registry of extensions of different files, where the last registered type won. +- **Name resolution across packages** (#46): An unqualified type name resolves (after nested definitions of the + message using it and its outer messages) to a definition of the package of the file using it, then to a definition + of the files it imports (directly, then indirectly), and only then to a definition of any other file generated in + the same run, if it is unique (see README, "Type names and imports"). Before, one global table of simple names was + used, and the definition of the last file loaded won. So the resolution of a file's names no longer depends on + unrelated files generated together, as long as it uses definitions of its own package or its imports. Duplicate + definitions in a package (in one or several files) stop the generation with an error naming the files, instead of + only a message on the console. A file given to the generator twice, or given after it + has been loaded as an import, is loaded only once (and generated). **Source compatibility:** an unqualified name + that is defined in two imported files (at the same import depth), or not in the own package or imports but in + several other files generated together, is now rejected as ambiguous; use a qualified name. ## 1.2.1 diff --git a/README.md b/README.md index 9c550c2a..221e78a0 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,25 @@ message SearchResponse { } ``` +### Type names and imports + +Messages and enums of other `.proto` files are made available with `import "path/to/other.proto";` (resolved relative +to the importing file, then in the include paths, then on the classpath). A type can always be referenced by its +qualified name (`package.Type`, `package.Outer.Inner`). An unqualified name `Type` (or `Type.Inner`) is resolved in +the following order; the first step that finds a definition wins: + +1. A nested definition of the message using the name, or of one of its outer messages (innermost first). +2. A top-level definition of the package of the file using the name (in any file of that package generated in the same + run). +3. A top-level definition of a file imported by that file. If none of the imported files defines the name, the files + they import are searched, and so on. Two definitions found in the same step are an error: use a qualified name. +4. For compatibility, a top-level definition of any other file generated in the same run, if exactly one file defines + the name. Otherwise, the name is rejected as ambiguous. + +Because of step 3, adding an unrelated file to the files generated together (e.g. a new `.proto` file in a Maven +project) does not change how the names of a file resolve, as long as the definitions it uses come from its own package +or its imports. A package must not define a top-level name twice, not even in different files. + ### Transient fields Fields marked with `transient` are not serialized in any format (JSON, binary, XML). They exist only in the in-memory diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java index 46c6abe4..902f54c4 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/CodeConvention.java @@ -279,11 +279,44 @@ public static String jsonTypeConstant(MessageDef def) { } public static String jsonTypeConstantRef(MessageDef def) { - // A nested specialization is not in scope by its simple name in the code of its generalization. - String typeRef = def.getFile() == null ? qTypeName(def) : typeName(def); + String typeRef = simpleNameInScopeOfGeneralizations(def) ? typeName(def) : qTypeName(def); return typeRef + "." + jsonTypeConstant(def); } + /** + * Whether the given message can be referenced by its simple name (the simple name of its + * interface or implementation class) from the generated code of its generalizations. + * + *

+ * A nested specialization is not in scope by its simple name in the code of its generalization. + * A top-level specialization is in scope, unless a nested definition with the same name + * shadows it: a nested definition of a generalization, of one of its outer messages, or of one + * of their generalizations. In these cases, the qualified name must be used. + *

+ */ + public static boolean simpleNameInScopeOfGeneralizations(MessageDef def) { + if (def.getFile() == null) { + return false; + } + String name = def.getName(); + java.util.Set seen = new java.util.HashSet<>(); + for (MessageDef generalization = def.getExtendedDef(); generalization != null && seen.add(generalization); + generalization = generalization.getExtendedDef()) { + for (MessageDef scope = generalization; scope != null; scope = scope.getOuter()) { + java.util.Set seenInherited = new java.util.HashSet<>(); + for (MessageDef inherited = scope; inherited != null && seenInherited.add(inherited); + inherited = inherited.getExtendedDef()) { + for (Definition member : inherited.getDefinitions()) { + if (member.getName().equals(name)) { + return false; + } + } + } + } + } + return true; + } + public static String mkBinaryTypeConstant(MessageDef def) { return allUpperCase(def.getName()) + "__TYPE_ID"; } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java index 63c9180c..9f1fcc1a 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/Generator.java @@ -31,11 +31,13 @@ import de.haumacher.msgbuf.generator.ast.Flag; import de.haumacher.msgbuf.generator.ast.MapType; import de.haumacher.msgbuf.generator.ast.MessageDef; +import de.haumacher.msgbuf.generator.ast.NumberOption; import de.haumacher.msgbuf.generator.ast.Option; import de.haumacher.msgbuf.generator.ast.PrimitiveType; import de.haumacher.msgbuf.generator.ast.QName; import de.haumacher.msgbuf.generator.ast.StringOption; import de.haumacher.msgbuf.generator.ast.Type; +import de.haumacher.msgbuf.generator.common.MsgBufJsonProtocol; import de.haumacher.msgbuf.generator.common.Util; import de.haumacher.msgbuf.generator.dart.DartLibGenerator; import de.haumacher.msgbuf.generator.parser.ParseException; @@ -96,6 +98,7 @@ public class Generator { private List _includePaths = new ArrayList<>(); private ClassLoader _importClassLoader; private Set _loadedFiles = new HashSet<>(); + private Map _fileByPath = new HashMap<>(); private List _importedFiles = new ArrayList<>(); public void setOut(File out) { @@ -138,11 +141,20 @@ public DefinitionFile load(String fileName) throws IOException, ParseException { public DefinitionFile load(File file) throws ParseException, IOException, FileNotFoundException { - _loadedFiles.add(file.getCanonicalPath()); + String canonical = file.getCanonicalPath(); + DefinitionFile loaded = _fileByPath.get(canonical); + if (loaded != null) { + // The same file given twice, or given after being loaded as import of another file: + // Generate code for it, but do not enter its definitions again. + _importedFiles.remove(loaded); + return loaded; + } + _loadedFiles.add(canonical); DefinitionFile content; try (InputStream in = new FileInputStream(file)) { content = load(parse(in)); } + _fileByPath.put(canonical, content); _sourceNames.put(content, file.getName()); resolveImports(content, file); return content; @@ -176,6 +188,11 @@ public void generate(GeneratorPlugin plugin) { } List errors = new ArrayList<>(); + // Duplicate definitions and ambiguous names. + errors.addAll(_table.drainErrors(this::sourceDescription)); + if (!errors.isEmpty()) { + throw new GeneratorException(errors); + } for (DefinitionFile file : _files) { validateOpenWorld(file, errors); } @@ -200,6 +217,7 @@ public void generate(GeneratorPlugin plugin) { validateFormatReferences(file, plugin, errors); } } + validateHierarchyNames(plugin, errors); if (!errors.isEmpty()) { throw new GeneratorException(errors); } @@ -626,6 +644,210 @@ private static List generatedNames(Field field) { return Arrays.asList("suffix:" + CodeConvention.suffix(field), "constant:" + CodeConvention.constant(field)); } + /** + * Rejects messages of a hierarchy whose identifiers in the generated code clash. + * + *
    + *
  • The concrete specializations of an abstract message must have distinct type IDs in all + * generated formats (the JSON type ID, explicit binary type IDs and plug-in identifiers such as + * XML element names). The readers of the abstract message dispatch on these IDs (and the + * registry of an option OpenWorld hierarchy is keyed by them), so equal IDs + * produce duplicate case labels or ambiguous data.
  • + *
  • The concrete messages of a hierarchy must have distinct constants in its + * TypeKind enum, unless option NoTypeKind is given.
  • + *
  • A message must not have the name of a nested definition of one of its generalizations: + * In the generated class of the message, the name of the inherited nested class would shadow + * the name of the class itself.
  • + *
+ * + *

+ * All loaded files are considered, so that a clash of an extension with a message of another + * file of the hierarchy is found. A clash is only reported, if at least one of the messages is + * generated. + *

+ */ + private void validateHierarchyNames(GeneratorPlugin plugin, List errors) { + List messages = new ArrayList<>(); + for (DefinitionFile file : _files) { + for (Definition def : file.getDefinitions()) { + collectMessages(def, messages); + } + } + + Set reported = new HashSet<>(); + for (MessageDef message : messages) { + if (message.isAbstract()) { + validateTypeIds(message, plugin, reported, errors); + } + } + + for (MessageDef message : messages) { + if (message.getExtendedDef() == null && !message.getSpecializations().isEmpty()) { + validateTypeKinds(message, errors); + } + } + + for (MessageDef message : messages) { + if (isGenerated(message)) { + validateInheritedNames(message, errors); + } + } + } + + private static void collectMessages(Definition def, List result) { + if (def instanceof MessageDef) { + MessageDef message = (MessageDef) def; + result.add(message); + for (Definition inner : message.getDefinitions()) { + collectMessages(inner, result); + } + } + } + + private boolean isGenerated(Definition def) { + return !_importedFiles.contains(Util.definingFile(def)); + } + + private void validateTypeIds(MessageDef generalization, GeneratorPlugin plugin, Set reported, List errors) { + List specializations = new ArrayList<>(); + addConcreteSpecializations(generalization, specializations, new HashSet<>()); + List> ids = new ArrayList<>(); + for (MessageDef specialization : specializations) { + ids.add(typeIds(specialization, plugin)); + } + for (int n = 1; n < specializations.size(); n++) { + MessageDef message = specializations.get(n); + for (int m = 0; m < n; m++) { + MessageDef other = specializations.get(m); + if (!isGenerated(message) && !isGenerated(other)) { + continue; + } + List clashes = new ArrayList<>(); + Set annotations = new java.util.LinkedHashSet<>(); + boolean renameHelps = false; + for (Map.Entry entry : ids.get(n).entrySet()) { + if (!entry.getValue().equals(ids.get(m).get(entry.getKey()))) { + continue; + } + java.util.regex.Matcher matcher = TYPE_ID_KIND.matcher(entry.getKey()); + String kind = matcher.matches() ? matcher.group(1) : entry.getKey(); + if (matcher.matches()) { + annotations.add(matcher.group(2)); + } + clashes.add("the same " + kind + " '" + entry.getValue() + "'"); + renameHelps |= !entry.getKey().equals(BINARY_TYPE_ID); + } + if (clashes.isEmpty() || !reported.add(Util.protoName(other) + " " + Util.protoName(message))) { + continue; + } + MessageDef blamed = isGenerated(message) ? message : other; + errors.add(sourceDescription(Util.definingFile(blamed)) + ": In the hierarchy of '" + Util.protoName(generalization) + + "', " + describe(other) + " and " + describe(message) + " have " + + String.join(" and ", clashes) + ", so that the readers of '" + Util.protoName(generalization) + + "' cannot distinguish them. " + + (annotations.isEmpty() ? "Rename one of the messages." + : "Give one of the messages a distinct identifier with " + String.join(" or ", annotations) + + (renameHelps ? ", or rename it." : ".")) + ); + } + } + } + + /** + * Description of a type ID: the kind of identifier and the annotation that sets it. + */ + private static final java.util.regex.Pattern TYPE_ID_KIND = java.util.regex.Pattern.compile("(.*) \\((@\\w+)\\)"); + + private static final String BINARY_TYPE_ID = "binary type ID (@type_id)"; + + /** + * Adds the concrete specializations of the given message of all files in depth-first order. + */ + private static void addConcreteSpecializations(MessageDef def, List result, Set seen) { + for (MessageDef specialization : def.getSpecializations()) { + if (!seen.add(specialization)) { + continue; + } + if (!specialization.isAbstract()) { + result.add(specialization); + } + addConcreteSpecializations(specialization, result, seen); + } + } + + /** + * The identifiers of the given concrete message in polymorphic values of all generated formats, + * indexed by a description of the identifier and the annotation that sets it. + */ + private Map typeIds(MessageDef message, GeneratorPlugin plugin) { + DefinitionFile file = Util.definingFile(message); + Map options = file.getOptions(); + Map result = new java.util.LinkedHashMap<>(); + if (MessageGenerator.isJson(options) || generatesTypeScript(file)) { + result.put("type ID (@Name)", MsgBufJsonProtocol.typeId(message)); + } + if (MessageGenerator.isBinary(options)) { + Option typeId = message.getOptions().get("type_id"); + if (typeId instanceof NumberOption) { + result.put(BINARY_TYPE_ID, Integer.toString((int) ((NumberOption) typeId).getValue())); + } + } + plugin.addTypeIds(options, message, result); + return result; + } + + private String describe(Definition def) { + return "message '" + Util.protoName(def) + "' of '" + sourceDescription(Util.definingFile(def)) + "'"; + } + + /** + * Rejects clashing constants in the TypeKind enum generated for the given hierarchy + * root. + */ + private void validateTypeKinds(MessageDef root, List errors) { + DefinitionFile rootFile = Util.definingFile(root); + if (!isGenerated(root) || MessageGenerator.isTrue(rootFile.getOptions().get("NoTypeKind"), false)) { + return; + } + Map constants = new HashMap<>(); + for (MessageDef message : AbstractMessageGenerator.concreteSpecializations(root)) { + String constant = CodeConvention.typeKindConstant(message); + MessageDef clash = constants.putIfAbsent(constant, message); + if (clash != null) { + errors.add(sourceDescription(Util.definingFile(message)) + ": In the hierarchy of '" + Util.protoName(root) + + "', " + describe(clash) + " and " + describe(message) + " generate the same constant '" + constant + + "' in the enum '" + Util.toString(root) + "." + CodeConvention.TYPE_KIND_NAME + + "'. Rename one of the messages, or add 'option NoTypeKind;' to '" + sourceDescription(rootFile) + + "'" + (Util.definingFile(message) != rootFile || Util.definingFile(clash) != rootFile + ? " and all files extending its hierarchy" : "") + + "."); + } + } + } + + /** + * Rejects a message with the name of a nested definition of one of its generalizations. + */ + private void validateInheritedNames(MessageDef message, List errors) { + Set seen = new HashSet<>(); + seen.add(message); + for (MessageDef generalization = message.getExtendedDef(); generalization != null && seen.add(generalization); + generalization = generalization.getExtendedDef()) { + for (Definition member : generalization.getDefinitions()) { + if (member != message && member.getName().equals(message.getName())) { + errors.add(sourceDescription(Util.definingFile(message)) + ": Message '" + Util.protoName(message) + + "' extends message '" + Util.protoName(generalization) + "' of '" + + sourceDescription(Util.definingFile(generalization)) + "', which declares the nested " + + (member instanceof EnumDef ? "enum" : "message") + " '" + Util.protoName(member) + + "' with the same name. In the generated Java class of '" + Util.protoName(message) + + "', the name '" + message.getName() + "' would refer to the inherited nested type instead of the" + + " class itself. Rename one of them."); + return; + } + } + } + } + /** * Rejects references to definitions of other files that are generated without a serialization * format that the referencing code needs. @@ -802,6 +1024,7 @@ private void resolveImports(DefinitionFile file, File sourceFile) throws IOExcep if (resolved != null) { String canonical = resolved.getCanonicalPath(); if (_loadedFiles.contains(canonical)) { + addImport(file, _fileByPath.get(canonical)); continue; } _loadedFiles.add(canonical); @@ -809,6 +1032,8 @@ private void resolveImports(DefinitionFile file, File sourceFile) throws IOExcep try (InputStream in = new FileInputStream(resolved)) { imported = parse(in); } + _fileByPath.put(canonical, imported); + addImport(file, imported); _sourceNames.put(imported, resolved.getName()); _files.add(imported); _table.enter(imported); @@ -821,6 +1046,7 @@ private void resolveImports(DefinitionFile file, File sourceFile) throws IOExcep if (_importClassLoader != null) { String resourceKey = "classpath:" + importPath; if (_loadedFiles.contains(resourceKey)) { + addImport(file, _fileByPath.get(resourceKey)); continue; } InputStream classpathStream = _importClassLoader.getResourceAsStream(importPath); @@ -830,6 +1056,8 @@ private void resolveImports(DefinitionFile file, File sourceFile) throws IOExcep try (InputStream in = classpathStream) { imported = parse(in); } + _fileByPath.put(resourceKey, imported); + addImport(file, imported); _sourceNames.put(imported, new File(importPath).getName()); _files.add(imported); _table.enter(imported); @@ -844,10 +1072,17 @@ private void resolveImports(DefinitionFile file, File sourceFile) throws IOExcep } } + private void addImport(DefinitionFile file, DefinitionFile imported) { + if (imported != null && imported != file) { + _table.addImport(file, imported); + } + } + private void resolveImportsFromClasspath(DefinitionFile file) throws IOException, ParseException { for (String importPath : file.getImports()) { String resourceKey = "classpath:" + importPath; if (_loadedFiles.contains(resourceKey)) { + addImport(file, _fileByPath.get(resourceKey)); continue; } @@ -859,6 +1094,8 @@ private void resolveImportsFromClasspath(DefinitionFile file) throws IOException try (InputStream in = classpathStream) { imported = parse(in); } + _fileByPath.put(resourceKey, imported); + addImport(file, imported); _sourceNames.put(imported, new File(importPath).getName()); _files.add(imported); _table.enter(imported); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java index a96a328d..a96b1fed 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/GeneratorPlugin.java @@ -100,6 +100,27 @@ default void addFieldFormats(Map options, Field field, Set + * The generator rejects two concrete specializations of an abstract message with the same + * identifier, since the readers of the abstract message cannot distinguish them. + *

+ * + * @param options + * The options of the file defining the message. + * @param def + * The concrete message. + * @param typeIds + * The identifiers to add to, indexed by a description of the identifier that names the + * annotation that sets it, e.g. "XML element name (@XmlName)". + */ + default void addTypeIds(Map options, MessageDef def, Map typeIds) { + // No additional identifiers by default. + } + /** * {@link GeneratorPlugin} that does not generate any output. */ @@ -142,6 +163,12 @@ public void addFieldFormats(Map options, Field field, Set options, MessageDef def, Map typeIds) { + self.addTypeIds(options, def, typeIds); + next.addTypeIds(options, def, typeIds); + } @Override public FileGenerator messageImplContents(Map options, MessageDef def) { diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java index 4465f381..d4578e31 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/MessageGenerator.java @@ -1890,8 +1890,12 @@ private void binaryWrite() { continue; } boolean nullable = Util.isNullable(field); + // The default value of a bytes field is null, which cannot be written. + boolean nullBytes = !nullable && Util.isSingleBytes(field); if (nullable) { line("if (" + hasName(field) + "()" + ") {"); + } else if (nullBytes) { + line("if (" + getterCall(field) + " != null) {"); } { line("out.name(" + binaryConstant(field) + ");"); @@ -1912,7 +1916,7 @@ private void binaryWrite() { binaryWriteValue(field.getType(), getterCall(field)); } } - if (nullable) { + if (nullable || nullBytes) { line("}"); } } @@ -1924,10 +1928,24 @@ private void binaryWrite() { private void binaryWriteValue(Type type, String x) { if (type instanceof PrimitiveType) { - if (((PrimitiveType) type).getKind() == Kind.JSON) { - line("de.haumacher.msgbuf.json.JsonUtil.toJsonValue(" + x + ").writeTo(out);"); - } else { - line("out.value(" + x + ");"); + switch (((PrimitiveType) type).getKind()) { + case JSON: + line("de.haumacher.msgbuf.json.JsonUtil.toJsonValue(" + x + ").writeTo(out);"); + break; + case SINT_32: + case SINT_64: + // Zig-zag encoding, as read by mkBinaryReadValue() and announced by mkBinaryType(). + line("out.valueSigned(" + x + ");"); + break; + case FIXED_32: + case SFIXED_32: + case FIXED_64: + case SFIXED_64: + // Fixed-length encoding, as read by mkBinaryReadValue() and announced by mkBinaryType(). + line("out.valueFixed(" + x + ");"); + break; + default: + line("out.value(" + x + ");"); } } else if (type instanceof CustomType) { line(x + ".writeTo(out);"); diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java index 0b74a64c..77534f74 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/NameTable.java @@ -3,10 +3,14 @@ */ package de.haumacher.msgbuf.generator; +import java.util.ArrayList; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; import de.haumacher.msgbuf.generator.ast.Constant; import de.haumacher.msgbuf.generator.ast.Definition; @@ -15,36 +19,59 @@ import de.haumacher.msgbuf.generator.ast.Field; import de.haumacher.msgbuf.generator.ast.MessageDef; import de.haumacher.msgbuf.generator.ast.QName; +import de.haumacher.msgbuf.generator.common.Util; /** - * TODO + * Index of all definitions of the files processed together, resolving type names. + * + *

+ * A name is resolved in the context of the message it is used in, see + * {@link #resolve(DefinitionFile, MessageDef, QName)}. + *

*/ public class NameTable implements Definition.Visitor { - + private final Map _packageByName = new HashMap<>(); - private final Map _definitionByName = new HashMap<>(); - + + /** + * The files imported by a file (its import declarations), in declaration order. + */ + private final Map> _imports = new HashMap<>(); + + /** + * Errors to report, formatted with a function describing the source of a file. + */ + private final List, String>> _errors = new ArrayList<>(); + public void enter(DefinitionFile file) { Package pkg = mkPackage(file.getPackage()); - + for (Definition def : file.getDefinitions()) { pkg.enter(file, def); def.visit(this, null); } } - + + /** + * Records that the given file imports the other file. + */ + public void addImport(DefinitionFile file, DefinitionFile imported) { + List list = _imports.computeIfAbsent(file, x -> new ArrayList<>()); + if (!list.contains(imported)) { + list.add(imported); + } + } + @Override public Void visit(EnumDef self, Void arg) { - enterDef(self); for (Constant part : self.getConstants()) { part.setOwner(self); } return null; } - + @Override public Void visit(MessageDef self, Void arg) { - enterDef(self); for (Field part : self.getFields()) { part.setOwner(self); } @@ -55,19 +82,8 @@ public Void visit(MessageDef self, Void arg) { return null; } - private void enterDef(Definition def) { - if (def.getOuter() == null) { - _definitionByName.put(def.getName(), def); - } - } - private Package mkPackage(QName qName) { - String name; - if (qName == null) { - name = ""; - } else { - name = CodeConvention.packageName(qName); - } + String name = packageName(qName); Package result = _packageByName.get(name); if (result == null) { result = new Package(name); @@ -76,13 +92,17 @@ private Package mkPackage(QName qName) { return result; } + private static String packageName(QName qName) { + return qName == null ? "" : CodeConvention.packageName(qName); + } + class Package { - + private final String _name; - + private final Map _definitionsByName = new HashMap<>(); - /** + /** * Creates a {@link Package}. */ public Package(String name) { @@ -92,33 +112,56 @@ public Package(String name) { public String getName() { return _name; } - - /** - * TODO - * @param file + + /** + * Enters the given top-level definition of the given file. */ public void enter(DefinitionFile file, Definition def) { def.setFile(file); - Definition clash = _definitionsByName.put(def.getName(), def); + Definition clash = _definitionsByName.putIfAbsent(def.getName(), def); if (clash != null) { - error("Duplicate definition '" + def.getName() + "' in package '" + getName() + "'."); + String qName = (getName().isEmpty() ? "" : getName() + ".") + def.getName(); + DefinitionFile clashFile = clash.getFile(); + _errors.add(source -> source.apply(file) + ": Duplicate definition of '" + qName + "'" + + (clashFile == file + ? ". Rename or remove one of the definitions." + : ", it is also defined in '" + source.apply(clashFile) + + "'. Rename one of the definitions, or do not pass both files to the generator.")); } } } - /** - * TODO + /** + * Reports the errors found so far (duplicate definitions and ambiguous names) and forgets them. + * + * @param source + * Function describing the source of a file in error messages. + * @return The error messages. + */ + public List drainErrors(Function source) { + List result = _errors.stream().map(e -> e.apply(source)).collect(Collectors.toList()); + _errors.clear(); + return result; + } + + /** + * Reports a problem that does not stop the generation. */ public void error(String message) { System.err.println(message); } /** - * TODO + * Resolves the given name used in the given message and reports an error, if the name cannot + * be resolved. + * + * @see #resolve(DefinitionFile, MessageDef, QName) */ public Definition lookup(MessageDef context, QName name) { - Definition result = resolve(context, name); - if (result == null) { + DefinitionFile file = context == null ? null : Util.definingFile(context); + int errorCount = _errors.size(); + Definition result = resolve(file, context, name, true); + if (result == null && _errors.size() == errorCount) { error("Name cannot be resolved" + (context == null ? "" : " in '" + context.getName() + "'") + ": " + CodeConvention.qTypeName(name)); } return result; @@ -132,13 +175,53 @@ public Definition lookup(MessageDef context, QName name) { * @param name * The name to resolve. * @return The resolved definition, or null if the name cannot be resolved. + * + * @see #resolve(DefinitionFile, MessageDef, QName) */ public Definition resolve(MessageDef context, QName name) { - String baseName = name.getNames().get(0); + return resolve(context == null ? null : Util.definingFile(context), context, name); + } - Definition base = lookupBase(context, baseName); + /** + * Resolves the given name in the given context without reporting an error. + * + *

+ * The first part of the name is resolved as follows: + *

+ *
    + *
  1. A nested definition of the context message or one of its outer messages.
  2. + *
  3. A top-level definition of the package of the given file (in any of the files processed + * together).
  4. + *
  5. A top-level definition of a file imported by the given file, if it is unique among these + * files. If none of them defines the name, the files imported by these files, and so on.
  6. + *
  7. For compatibility, a top-level definition of any other file processed together, if it is + * unique.
  8. + *
+ *

+ * The remaining parts are resolved as nested definitions. If this fails, the name is resolved as + * a package-qualified name. + *

+ * + * @param file + * The file in which the name is used, null if unknown. + * @param context + * The message in which the name is used, null for top-level usage. + * @param name + * The name to resolve. + * @return The resolved definition, or null if the name cannot be resolved (or is + * ambiguous). + */ + public Definition resolve(DefinitionFile file, MessageDef context, QName name) { + return resolve(file, context, name, false); + } - if (base != null) { + private Definition resolve(DefinitionFile file, MessageDef context, QName name, boolean report) { + String baseName = name.getNames().get(0); + + boolean[] fromImports = { false }; + List candidates = lookupBase(file, context, baseName, fromImports); + if (candidates.size() == 1) { + Definition base = candidates.get(0); // Try resolving remaining parts as inner definitions boolean resolved = true; for (int n = 1; n < name.getNames().size(); n++) { @@ -175,9 +258,29 @@ public Definition resolve(MessageDef context, QName name) { } } + if (report && candidates.size() > 1) { + String usage = context == null ? "" : " in '" + Util.protoName(context) + "'"; + String pkgName = file == null ? null : packageName(file.getPackage()); + _errors.add(source -> (file == null ? "" : source.apply(file) + ": ") + "The name '" + + CodeConvention.qTypeName(name) + "'" + usage + " is ambiguous, it could refer to " + + candidates.stream().map(c -> "'" + Util.protoName(c) + "' of '" + source.apply(c.getFile()) + "'") + .collect(Collectors.joining(" and ")) + + (pkgName == null ? "" + : fromImports[0] + ? ", which are defined in files imported by '" + source.apply(file) + "', and " + + packageDescription(pkgName) + " does not define this name" + : ". Neither " + packageDescription(pkgName) + " nor the files imported by '" + source.apply(file) + + "' define this name, and the candidates are defined in files that are not imported, but" + + " generated together") + + ". Use a qualified name, e.g. '" + Util.protoName(candidates.get(0)) + "'."); + } return null; } + private static String packageDescription(String pkgName) { + return pkgName.isEmpty() ? "the default package" : "package '" + pkgName + "'"; + } + private Definition lookupInner(Definition base, String nextName) { if (base instanceof MessageDef) { Optional match = ((MessageDef) base).getDefinitions().stream().filter(d -> nextName.equals(d.getName())).findFirst(); @@ -191,15 +294,70 @@ private Definition lookupInner(Definition base, String nextName) { } } - private Definition lookupBase(MessageDef context, String baseName) { + /** + * The candidates for the first part of a name. + * + * @param fromImports + * Output: whether the result consists of definitions of imported files. + * @return A single definition, if the name is resolved, more than one, if the name is + * ambiguous. + */ + private List lookupBase(DefinitionFile file, MessageDef context, String baseName, boolean[] fromImports) { while (context != null) { Definition inner = lookupInner(context, baseName); if (inner != null) { - return inner; + return List.of(inner); } context = context.getOuter(); } - - return _definitionByName.get(baseName); + + if (file != null) { + Package pkg = _packageByName.get(packageName(file.getPackage())); + Definition local = pkg == null ? null : pkg._definitionsByName.get(baseName); + if (local != null) { + return List.of(local); + } + + // Definitions of the files imported directly, then of the files imported by these, and so on. + java.util.Set seen = new java.util.HashSet<>(); + seen.add(file); + List level = List.of(file); + while (!level.isEmpty()) { + List next = new ArrayList<>(); + for (DefinitionFile current : level) { + for (DefinitionFile imported : _imports.getOrDefault(current, List.of())) { + if (seen.add(imported)) { + next.add(imported); + } + } + } + List found = new ArrayList<>(); + for (DefinitionFile imported : next) { + for (Definition def : imported.getDefinitions()) { + if (def.getName().equals(baseName) && !found.contains(def)) { + found.add(def); + } + } + } + if (!found.isEmpty()) { + fromImports[0] = true; + found.sort(Comparator.comparing(Util::protoName)); + return found; + } + level = next; + } + } + + // For compatibility, a definition of a file that is not imported can be referenced by its + // simple name, if it is unique among all files processed together. + List global = new ArrayList<>(); + for (Package pkg : _packageByName.values()) { + Definition def = pkg._definitionsByName.get(baseName); + if (def != null) { + global.add(def); + } + } + global.sort(Comparator.comparing(Util::protoName)); + return global; } } diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/Util.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/Util.java index 2f0da893..bf302b36 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/Util.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/common/Util.java @@ -78,6 +78,22 @@ public static String toString(Definition def) { } } + /** + * The name of the given definition qualified with its package and outer messages, as written in + * the .proto file. + */ + public static String protoName(Definition def) { + List names = new ArrayList<>(); + for (Definition current = def; current != null; current = current.getOuter()) { + names.add(0, current.getName()); + } + QName pkg = definingFile(def).getPackage(); + if (pkg != null) { + names.addAll(0, pkg.getNames()); + } + return String.join(".", names); + } + public static String toString(Part part) { return toString(part.getOwner()) + "#" + part.getName(); } @@ -95,6 +111,19 @@ public static boolean isNullable(Field field) { return getFlag(field, "Nullable") || (!field.isRepeated() && isNullable(field.getType())); } + /** + * Whether the given field is a single (not repeated) bytes field. + * + *

+ * The default value of such field is null, even if the field is not nullable. + *

+ */ + public static boolean isSingleBytes(Field field) { + Type type = field.getType(); + return !field.isRepeated() && type instanceof PrimitiveType + && ((PrimitiveType) type).getKind() == PrimitiveType.Kind.BYTES; + } + public static boolean isNullable(Type type) { if (type instanceof PrimitiveType) { return ((PrimitiveType) type).getKind() == PrimitiveType.Kind.JSON; diff --git a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java index 17d6451f..8d1890a7 100644 --- a/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java +++ b/de.haumacher.msgbuf.generator/src/main/java/de/haumacher/msgbuf/generator/plugins/XmlStreamingPlugin.java @@ -75,6 +75,13 @@ static boolean xmlSerialized(Field field) { return !field.isTransient() && !field.isDerived(); } + @Override + public void addTypeIds(Map options, MessageDef def, Map typeIds) { + if (!noXml(options)) { + typeIds.put("XML element name (@XmlName)", xmlTypeName(def, noXmlNames(options))); + } + } + @Override public void addInterfaces(Map options, MessageDef def, List generalizations) { if (noXml(options)) { @@ -180,7 +187,19 @@ protected void generate() { continue; } if (field.getType().kind() == Type.TypeKind.PRIMITIVE_TYPE || isEnum(field.getType())) { + // A missing value is omitted (a missing JSON value is written as JSON null). + boolean omitMissing = Util.isNullable(field) && !isJson(field); + // The default value of a bytes field is null, even if it is not nullable. + boolean omitNull = !Util.isNullable(field) && Util.isSingleBytes(field); + if (omitMissing) { + line("if (" + CodeConvention.hasName(field) + "()) {"); + } else if (omitNull) { + line("if (" + CodeConvention.getterName(field) + "() != null) {"); + } line("out.writeAttribute(" + xmlFieldNameConstant(field) + ", " + asString(field, CodeConvention.getterName(field) + "()") + ");"); + if (omitMissing || omitNull) { + line("}"); + } } } } @@ -513,15 +532,20 @@ protected void generate() { private void readPrimitiveXmlElement(Field field) { line("case " + xmlFieldNameConstant(field) + ": {"); { - line(setterName(field) + "(" + fromString(field, "in.getElementText()") + ");"); + if (field.isRepeated()) { + // The list parser evaluates its input twice. + line("String text = in.getElementText();"); + line(setterName(field) + "(" + fromString(field, "text") + ");"); + } else { + line(setterName(field) + "(" + fromString(field, "in.getElementText()") + ");"); + } line("break;"); } line("}"); } String xmlTypeNameRef(MessageDef def) { - // A nested specialization is not in scope by its simple name in the code of its generalization. - String implRef = def.getFile() == null ? qImplName(def) : implName(def); + String implRef = simpleNameInScopeOfGeneralizations(def) ? implName(def) : qImplName(def); return implRef + "." + xmlTypeNameConstant(def); } }; @@ -571,6 +595,10 @@ String readerMethod(MessageDef def) { } String xmlTypeName(MessageDef def) { + return xmlTypeName(def, _noXmlNames); + } + + private static String xmlTypeName(MessageDef def, boolean noXmlNames) { Optional
& 'quoted', comma é") + .setVBytes(SOME_BYTES) + .setVJson(json) + .setVColor(Color.GREEN); + + Values xml = checkValues(values); + assertEquals(UINT_ABOVE_2_31, xml.getVUint32()); + assertEquals(0xFFFFFFFF, xml.getVFixed32()); + assertTrue(Arrays.equals(SOME_BYTES, xml.getVBytes())); + assertEquals(Double.doubleToLongBits(-0.0), Double.doubleToLongBits(xml.getVDouble())); + + String written = toXml(values); + // Unsigned decimal, as expected by the reader. + assertTrue(written, written.contains("v-uint-32=\"3000000000\"")); + assertTrue(written, written.contains("v-fixed-32=\"4294967295\"")); + // Base64 + assertTrue(written, written.contains("v-bytes=\"AAH/f4Aq\"")); + } + + public void testValuesEmptyBytes() throws Exception { + Values xml = checkValues(Values.create().setVBytes(new byte[0])); + assertNotNull(xml.getVBytes()); + assertEquals(0, xml.getVBytes().length); + } + + public void testValuesSignedUint32Accepted() throws Exception { + // Signed decimal is still accepted for unsigned 32 bit values. + Values values = Values.readValues(reader("")); + assertEquals(-1, values.getVUint32()); + assertEquals(-2, values.getVFixed32()); + } + + public void testValuesElements() throws Exception { + Values values = Values.readValues(reader( + "4294967295AAH/f4AqRED")); + assertEquals(-1, values.getVUint32()); + assertTrue(Arrays.equals(SOME_BYTES, values.getVBytes())); + assertEquals(Color.RED, values.getVColor()); + } + + public void testListsEmpty() throws Exception { + Lists xml = checkLists(Lists.create()); + assertTrue(xml.getLInt32().isEmpty()); + assertTrue(xml.getLString().isEmpty()); + assertTrue(xml.getLBytes().isEmpty()); + } + + public void testListsEdge() throws Exception { + Lists lists = Lists.create() + .setLBool(Arrays.asList(true, false)) + .setLInt32(Arrays.asList(Integer.MIN_VALUE, -1, 0, Integer.MAX_VALUE)) + .setLSint32(Arrays.asList(-7, 7)) + .setLUint32(Arrays.asList(UINT_ABOVE_2_31, 0, -1)) + .setLFixed32(Arrays.asList(0xFFFFFFFF, 1)) + .setLSfixed32(Arrays.asList(-1)) + .setLInt64(Arrays.asList(Long.MIN_VALUE, Long.MAX_VALUE)) + .setLSint64(Arrays.asList(-3L)) + .setLUint64(Arrays.asList(-1L, 0L)) + .setLFixed64(Arrays.asList(Long.MAX_VALUE)) + .setLSfixed64(Arrays.asList(-1L, 5L)) + .setLFloat(Arrays.asList(-1.5f, 0.25f)) + .setLDouble(Arrays.asList(1e300, -0.0)) + .setLString(Arrays.asList("a", "", "d e")) + .setLBytes(Arrays.asList(SOME_BYTES, new byte[0], new byte[] { 7 })) + .setLColor(Arrays.asList(Color.GREEN, Color.RED)); + + Lists xml = checkLists(lists); + assertEquals(Arrays.asList(UINT_ABOVE_2_31, 0, -1), xml.getLUint32()); + assertEquals(3, xml.getLBytes().size()); + assertTrue(Arrays.equals(SOME_BYTES, xml.getLBytes().get(0))); + assertEquals(0, xml.getLBytes().get(1).length); + + String written = toXml(lists); + assertTrue(written, written.contains("l-uint-32=\"3000000000, 0, 4294967295\"")); + } + + public void testListsElements() throws Exception { + Lists lists = Lists.readLists(reader( + "1, 2,3AAH/f4Aq, Bw==")); + assertEquals(Arrays.asList(1, 2, 3), lists.getLInt32()); + assertEquals(Collections.emptyList(), lists.getLUint32()); + assertEquals(2, lists.getLBytes().size()); + assertTrue(Arrays.equals(new byte[] { 7 }, lists.getLBytes().get(1))); + } + + public void testNullablesUnset() throws Exception { + Nullables xml = checkNullables(Nullables.create()); + assertFalse(xml.hasNInt32()); + assertFalse(xml.hasNUint32()); + assertFalse(xml.hasNBytes()); + assertFalse(xml.hasNString()); + assertFalse(xml.hasNColor()); + assertFalse(xml.hasNJson()); + } + + public void testNullablesSet() throws Exception { + List json = new ArrayList<>(); + json.add("x"); + json.add(Collections.singletonMap("k", "v")); + + Nullables nullables = Nullables.create() + .setNBool(false) + .setNInt32(0) + .setNSint32(-1) + .setNUint32(UINT_ABOVE_2_31) + .setNFixed32(-1) + .setNSfixed32(Integer.MIN_VALUE) + .setNInt64(0L) + .setNSint64(-1L) + .setNUint64(-1L) + .setNFixed64(1L) + .setNSfixed64(Long.MIN_VALUE) + .setNFloat(0.0f) + .setNDouble(Double.MAX_VALUE) + .setNString("") + .setNBytes(new byte[0]) + .setNJson(json) + .setNColor(Color.RED) + .setNlInt32(new ArrayList<>()) + .setNlUint32(Arrays.asList(UINT_ABOVE_2_31)) + .setNlString(Arrays.asList("s")) + .setNlBytes(Arrays.asList(SOME_BYTES)); + + Nullables xml = checkNullables(nullables); + assertTrue(xml.hasNInt32()); + assertEquals(Integer.valueOf(UINT_ABOVE_2_31), xml.getNUint32()); + assertTrue(xml.hasNString()); + assertEquals("", xml.getNString()); + assertTrue(xml.hasNBytes()); + assertEquals(0, xml.getNBytes().length); + assertTrue(xml.hasNlInt32()); + assertTrue(xml.getNlInt32().isEmpty()); + assertTrue(Arrays.equals(SOME_BYTES, xml.getNlBytes().get(0))); + } + + /** + * Checks round-trips in all formats and returns the value read back from XML. + */ + private Values checkValues(Values values) throws Exception { + String expected = values.toString(); + assertEquals(expected, Values.readValues(new JsonReader(new StringR(expected))).toString()); + + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + values.writeTo(new OctetDataWriter(buffer)); + assertEquals(expected, Values.readValues(new OctetDataReader(new ByteArrayInputStream(buffer.toByteArray()))).toString()); + + String xml = toXml(values); + Values result = Values.readValues(reader(xml)); + assertEquals(xml, expected, result.toString()); + assertEquals(xml, toXml(result)); + return result; + } + + private Lists checkLists(Lists lists) throws Exception { + String expected = lists.toString(); + assertEquals(expected, Lists.readLists(new JsonReader(new StringR(expected))).toString()); + + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + lists.writeTo(new OctetDataWriter(buffer)); + assertEquals(expected, Lists.readLists(new OctetDataReader(new ByteArrayInputStream(buffer.toByteArray()))).toString()); + + String xml = toXml(lists); + Lists result = Lists.readLists(reader(xml)); + assertEquals(xml, expected, result.toString()); + assertEquals(xml, toXml(result)); + return result; + } + + private Nullables checkNullables(Nullables nullables) throws Exception { + String expected = nullables.toString(); + assertEquals(expected, Nullables.readNullables(new JsonReader(new StringR(expected))).toString()); + + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + nullables.writeTo(new OctetDataWriter(buffer)); + assertEquals(expected, Nullables.readNullables(new OctetDataReader(new ByteArrayInputStream(buffer.toByteArray()))).toString()); + + String xml = toXml(nullables); + Nullables result = Nullables.readNullables(reader(xml)); + assertEquals(xml, expected, result.toString()); + assertEquals(xml, toXml(result)); + return result; + } + + private static String toXml(XmlSerializable value) throws XMLStreamException { + StringWriter buffer = new StringWriter(); + value.writeTo(XMLOutputFactory.newDefaultFactory().createXMLStreamWriter(buffer)); + return buffer.toString(); + } + + private static XMLStreamReader reader(String xml) throws XMLStreamException, IOException { + return XMLInputFactory.newFactory().createXMLStreamReader(new StringReader(xml)); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Color.java b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Color.java new file mode 100644 index 00000000..c944062f --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Color.java @@ -0,0 +1,64 @@ +package test.xmlprimitives.data; + +public enum Color implements de.haumacher.msgbuf.data.ProtocolEnum { + + RED("RED"), + + GREEN("GREEN"), + + ; + + private final String _protocolName; + + private Color(String protocolName) { + _protocolName = protocolName; + } + + /** + * The protocol name of a {@link Color} constant. + * + * @see #valueOfProtocol(String) + */ + @Override + public String protocolName() { + return _protocolName; + } + + /** Looks up a {@link Color} constant by it's protocol name. */ + public static Color valueOfProtocol(String protocolName) { + if (protocolName == null) { return null; } + switch (protocolName) { + case "RED": return RED; + case "GREEN": return GREEN; + } + return RED; + } + + /** Writes this instance to the given output. */ + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + out.value(protocolName()); + } + + /** Reads a new instance from the given reader. */ + public static Color readColor(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + return valueOfProtocol(in.nextString()); + } + + /** Writes this instance to the given binary output. */ + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + switch (this) { + case RED: out.value(1); break; + case GREEN: out.value(2); break; + default: out.value(0); + } + } + + /** Reads a new instance from the given binary reader. */ + public static Color readColor(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + switch (in.nextInt()) { + case 1: return RED; + case 2: return GREEN; + default: return RED; + } + } +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Lists.java b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Lists.java new file mode 100644 index 00000000..df08fc23 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Lists.java @@ -0,0 +1,413 @@ +package test.xmlprimitives.data; + +/** + * Every primitive type as repeated field. + */ +public interface Lists extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.xmlprimitives.data.Lists} instance. + */ + static test.xmlprimitives.data.Lists create() { + return new test.xmlprimitives.data.impl.Lists_Impl(); + } + + /** Identifier for the {@link test.xmlprimitives.data.Lists} type in JSON format. */ + String LISTS__TYPE = "Lists"; + + /** @see #isLBool() */ + String L_BOOL__PROP = "lBool"; + + /** @see #getLInt32() */ + String L_INT_32__PROP = "lInt32"; + + /** @see #getLSint32() */ + String L_SINT_32__PROP = "lSint32"; + + /** @see #getLUint32() */ + String L_UINT_32__PROP = "lUint32"; + + /** @see #getLFixed32() */ + String L_FIXED_32__PROP = "lFixed32"; + + /** @see #getLSfixed32() */ + String L_SFIXED_32__PROP = "lSfixed32"; + + /** @see #getLInt64() */ + String L_INT_64__PROP = "lInt64"; + + /** @see #getLSint64() */ + String L_SINT_64__PROP = "lSint64"; + + /** @see #getLUint64() */ + String L_UINT_64__PROP = "lUint64"; + + /** @see #getLFixed64() */ + String L_FIXED_64__PROP = "lFixed64"; + + /** @see #getLSfixed64() */ + String L_SFIXED_64__PROP = "lSfixed64"; + + /** @see #getLFloat() */ + String L_FLOAT__PROP = "lFloat"; + + /** @see #getLDouble() */ + String L_DOUBLE__PROP = "lDouble"; + + /** @see #getLString() */ + String L_STRING__PROP = "lString"; + + /** @see #getLBytes() */ + String L_BYTES__PROP = "lBytes"; + + /** @see #getLColor() */ + String L_COLOR__PROP = "lColor"; + + /** Identifier for the property {@link #isLBool()} in binary format. */ + static final int L_BOOL__ID = 1; + + /** Identifier for the property {@link #getLInt32()} in binary format. */ + static final int L_INT_32__ID = 2; + + /** Identifier for the property {@link #getLSint32()} in binary format. */ + static final int L_SINT_32__ID = 3; + + /** Identifier for the property {@link #getLUint32()} in binary format. */ + static final int L_UINT_32__ID = 4; + + /** Identifier for the property {@link #getLFixed32()} in binary format. */ + static final int L_FIXED_32__ID = 5; + + /** Identifier for the property {@link #getLSfixed32()} in binary format. */ + static final int L_SFIXED_32__ID = 6; + + /** Identifier for the property {@link #getLInt64()} in binary format. */ + static final int L_INT_64__ID = 7; + + /** Identifier for the property {@link #getLSint64()} in binary format. */ + static final int L_SINT_64__ID = 8; + + /** Identifier for the property {@link #getLUint64()} in binary format. */ + static final int L_UINT_64__ID = 9; + + /** Identifier for the property {@link #getLFixed64()} in binary format. */ + static final int L_FIXED_64__ID = 10; + + /** Identifier for the property {@link #getLSfixed64()} in binary format. */ + static final int L_SFIXED_64__ID = 11; + + /** Identifier for the property {@link #getLFloat()} in binary format. */ + static final int L_FLOAT__ID = 12; + + /** Identifier for the property {@link #getLDouble()} in binary format. */ + static final int L_DOUBLE__ID = 13; + + /** Identifier for the property {@link #getLString()} in binary format. */ + static final int L_STRING__ID = 14; + + /** Identifier for the property {@link #getLBytes()} in binary format. */ + static final int L_BYTES__ID = 15; + + /** Identifier for the property {@link #getLColor()} in binary format. */ + static final int L_COLOR__ID = 16; + + java.util.List isLBool(); + + /** + * @see #isLBool() + */ + test.xmlprimitives.data.Lists setLBool(java.util.List value); + + /** + * Adds a value to the {@link #isLBool()} list. + */ + test.xmlprimitives.data.Lists addLBool(boolean value); + + /** + * Removes a value from the {@link #isLBool()} list. + */ + void removeLBool(boolean value); + + java.util.List getLInt32(); + + /** + * @see #getLInt32() + */ + test.xmlprimitives.data.Lists setLInt32(java.util.List value); + + /** + * Adds a value to the {@link #getLInt32()} list. + */ + test.xmlprimitives.data.Lists addLInt32(int value); + + /** + * Removes a value from the {@link #getLInt32()} list. + */ + void removeLInt32(int value); + + java.util.List getLSint32(); + + /** + * @see #getLSint32() + */ + test.xmlprimitives.data.Lists setLSint32(java.util.List value); + + /** + * Adds a value to the {@link #getLSint32()} list. + */ + test.xmlprimitives.data.Lists addLSint32(int value); + + /** + * Removes a value from the {@link #getLSint32()} list. + */ + void removeLSint32(int value); + + java.util.List getLUint32(); + + /** + * @see #getLUint32() + */ + test.xmlprimitives.data.Lists setLUint32(java.util.List value); + + /** + * Adds a value to the {@link #getLUint32()} list. + */ + test.xmlprimitives.data.Lists addLUint32(int value); + + /** + * Removes a value from the {@link #getLUint32()} list. + */ + void removeLUint32(int value); + + java.util.List getLFixed32(); + + /** + * @see #getLFixed32() + */ + test.xmlprimitives.data.Lists setLFixed32(java.util.List value); + + /** + * Adds a value to the {@link #getLFixed32()} list. + */ + test.xmlprimitives.data.Lists addLFixed32(int value); + + /** + * Removes a value from the {@link #getLFixed32()} list. + */ + void removeLFixed32(int value); + + java.util.List getLSfixed32(); + + /** + * @see #getLSfixed32() + */ + test.xmlprimitives.data.Lists setLSfixed32(java.util.List value); + + /** + * Adds a value to the {@link #getLSfixed32()} list. + */ + test.xmlprimitives.data.Lists addLSfixed32(int value); + + /** + * Removes a value from the {@link #getLSfixed32()} list. + */ + void removeLSfixed32(int value); + + java.util.List getLInt64(); + + /** + * @see #getLInt64() + */ + test.xmlprimitives.data.Lists setLInt64(java.util.List value); + + /** + * Adds a value to the {@link #getLInt64()} list. + */ + test.xmlprimitives.data.Lists addLInt64(long value); + + /** + * Removes a value from the {@link #getLInt64()} list. + */ + void removeLInt64(long value); + + java.util.List getLSint64(); + + /** + * @see #getLSint64() + */ + test.xmlprimitives.data.Lists setLSint64(java.util.List value); + + /** + * Adds a value to the {@link #getLSint64()} list. + */ + test.xmlprimitives.data.Lists addLSint64(long value); + + /** + * Removes a value from the {@link #getLSint64()} list. + */ + void removeLSint64(long value); + + java.util.List getLUint64(); + + /** + * @see #getLUint64() + */ + test.xmlprimitives.data.Lists setLUint64(java.util.List value); + + /** + * Adds a value to the {@link #getLUint64()} list. + */ + test.xmlprimitives.data.Lists addLUint64(long value); + + /** + * Removes a value from the {@link #getLUint64()} list. + */ + void removeLUint64(long value); + + java.util.List getLFixed64(); + + /** + * @see #getLFixed64() + */ + test.xmlprimitives.data.Lists setLFixed64(java.util.List value); + + /** + * Adds a value to the {@link #getLFixed64()} list. + */ + test.xmlprimitives.data.Lists addLFixed64(long value); + + /** + * Removes a value from the {@link #getLFixed64()} list. + */ + void removeLFixed64(long value); + + java.util.List getLSfixed64(); + + /** + * @see #getLSfixed64() + */ + test.xmlprimitives.data.Lists setLSfixed64(java.util.List value); + + /** + * Adds a value to the {@link #getLSfixed64()} list. + */ + test.xmlprimitives.data.Lists addLSfixed64(long value); + + /** + * Removes a value from the {@link #getLSfixed64()} list. + */ + void removeLSfixed64(long value); + + java.util.List getLFloat(); + + /** + * @see #getLFloat() + */ + test.xmlprimitives.data.Lists setLFloat(java.util.List value); + + /** + * Adds a value to the {@link #getLFloat()} list. + */ + test.xmlprimitives.data.Lists addLFloat(float value); + + /** + * Removes a value from the {@link #getLFloat()} list. + */ + void removeLFloat(float value); + + java.util.List getLDouble(); + + /** + * @see #getLDouble() + */ + test.xmlprimitives.data.Lists setLDouble(java.util.List value); + + /** + * Adds a value to the {@link #getLDouble()} list. + */ + test.xmlprimitives.data.Lists addLDouble(double value); + + /** + * Removes a value from the {@link #getLDouble()} list. + */ + void removeLDouble(double value); + + java.util.List getLString(); + + /** + * @see #getLString() + */ + test.xmlprimitives.data.Lists setLString(java.util.List value); + + /** + * Adds a value to the {@link #getLString()} list. + */ + test.xmlprimitives.data.Lists addLString(String value); + + /** + * Removes a value from the {@link #getLString()} list. + */ + void removeLString(String value); + + java.util.List getLBytes(); + + /** + * @see #getLBytes() + */ + test.xmlprimitives.data.Lists setLBytes(java.util.List value); + + /** + * Adds a value to the {@link #getLBytes()} list. + */ + test.xmlprimitives.data.Lists addLByte(byte[] value); + + /** + * Removes a value from the {@link #getLBytes()} list. + */ + void removeLByte(byte[] value); + + java.util.List getLColor(); + + /** + * @see #getLColor() + */ + test.xmlprimitives.data.Lists setLColor(java.util.List value); + + /** + * Adds a value to the {@link #getLColor()} list. + */ + test.xmlprimitives.data.Lists addLColor(test.xmlprimitives.data.Color value); + + /** + * Removes a value from the {@link #getLColor()} list. + */ + void removeLColor(test.xmlprimitives.data.Color value); + + @Override + public test.xmlprimitives.data.Lists registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.xmlprimitives.data.Lists unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.xmlprimitives.data.Lists readLists(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.xmlprimitives.data.impl.Lists_Impl result = new test.xmlprimitives.data.impl.Lists_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.xmlprimitives.data.Lists readLists(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.xmlprimitives.data.Lists result = test.xmlprimitives.data.impl.Lists_Impl.readLists_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Lists} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Lists readLists(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.xmlprimitives.data.impl.Lists_Impl.readLists_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Nullables.java b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Nullables.java new file mode 100644 index 00000000..b9988329 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Nullables.java @@ -0,0 +1,463 @@ +package test.xmlprimitives.data; + +/** + * Every primitive type as nullable field. + */ +public interface Nullables extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.xmlprimitives.data.Nullables} instance. + */ + static test.xmlprimitives.data.Nullables create() { + return new test.xmlprimitives.data.impl.Nullables_Impl(); + } + + /** Identifier for the {@link test.xmlprimitives.data.Nullables} type in JSON format. */ + String NULLABLES__TYPE = "Nullables"; + + /** @see #getNBool() */ + String N_BOOL__PROP = "nBool"; + + /** @see #getNInt32() */ + String N_INT_32__PROP = "nInt32"; + + /** @see #getNSint32() */ + String N_SINT_32__PROP = "nSint32"; + + /** @see #getNUint32() */ + String N_UINT_32__PROP = "nUint32"; + + /** @see #getNFixed32() */ + String N_FIXED_32__PROP = "nFixed32"; + + /** @see #getNSfixed32() */ + String N_SFIXED_32__PROP = "nSfixed32"; + + /** @see #getNInt64() */ + String N_INT_64__PROP = "nInt64"; + + /** @see #getNSint64() */ + String N_SINT_64__PROP = "nSint64"; + + /** @see #getNUint64() */ + String N_UINT_64__PROP = "nUint64"; + + /** @see #getNFixed64() */ + String N_FIXED_64__PROP = "nFixed64"; + + /** @see #getNSfixed64() */ + String N_SFIXED_64__PROP = "nSfixed64"; + + /** @see #getNFloat() */ + String N_FLOAT__PROP = "nFloat"; + + /** @see #getNDouble() */ + String N_DOUBLE__PROP = "nDouble"; + + /** @see #getNString() */ + String N_STRING__PROP = "nString"; + + /** @see #getNBytes() */ + String N_BYTES__PROP = "nBytes"; + + /** @see #getNJson() */ + String N_JSON__PROP = "nJson"; + + /** @see #getNColor() */ + String N_COLOR__PROP = "nColor"; + + /** @see #getNlInt32() */ + String NL_INT_32__PROP = "nlInt32"; + + /** @see #getNlUint32() */ + String NL_UINT_32__PROP = "nlUint32"; + + /** @see #getNlString() */ + String NL_STRING__PROP = "nlString"; + + /** @see #getNlBytes() */ + String NL_BYTES__PROP = "nlBytes"; + + /** Identifier for the property {@link #getNBool()} in binary format. */ + static final int N_BOOL__ID = 1; + + /** Identifier for the property {@link #getNInt32()} in binary format. */ + static final int N_INT_32__ID = 2; + + /** Identifier for the property {@link #getNSint32()} in binary format. */ + static final int N_SINT_32__ID = 3; + + /** Identifier for the property {@link #getNUint32()} in binary format. */ + static final int N_UINT_32__ID = 4; + + /** Identifier for the property {@link #getNFixed32()} in binary format. */ + static final int N_FIXED_32__ID = 5; + + /** Identifier for the property {@link #getNSfixed32()} in binary format. */ + static final int N_SFIXED_32__ID = 6; + + /** Identifier for the property {@link #getNInt64()} in binary format. */ + static final int N_INT_64__ID = 7; + + /** Identifier for the property {@link #getNSint64()} in binary format. */ + static final int N_SINT_64__ID = 8; + + /** Identifier for the property {@link #getNUint64()} in binary format. */ + static final int N_UINT_64__ID = 9; + + /** Identifier for the property {@link #getNFixed64()} in binary format. */ + static final int N_FIXED_64__ID = 10; + + /** Identifier for the property {@link #getNSfixed64()} in binary format. */ + static final int N_SFIXED_64__ID = 11; + + /** Identifier for the property {@link #getNFloat()} in binary format. */ + static final int N_FLOAT__ID = 12; + + /** Identifier for the property {@link #getNDouble()} in binary format. */ + static final int N_DOUBLE__ID = 13; + + /** Identifier for the property {@link #getNString()} in binary format. */ + static final int N_STRING__ID = 14; + + /** Identifier for the property {@link #getNBytes()} in binary format. */ + static final int N_BYTES__ID = 15; + + /** Identifier for the property {@link #getNJson()} in binary format. */ + static final int N_JSON__ID = 16; + + /** Identifier for the property {@link #getNColor()} in binary format. */ + static final int N_COLOR__ID = 17; + + /** Identifier for the property {@link #getNlInt32()} in binary format. */ + static final int NL_INT_32__ID = 18; + + /** Identifier for the property {@link #getNlUint32()} in binary format. */ + static final int NL_UINT_32__ID = 19; + + /** Identifier for the property {@link #getNlString()} in binary format. */ + static final int NL_STRING__ID = 20; + + /** Identifier for the property {@link #getNlBytes()} in binary format. */ + static final int NL_BYTES__ID = 21; + + Boolean getNBool(); + + /** + * @see #getNBool() + */ + test.xmlprimitives.data.Nullables setNBool(Boolean value); + + /** + * Checks, whether {@link #getNBool()} has a value. + */ + boolean hasNBool(); + + Integer getNInt32(); + + /** + * @see #getNInt32() + */ + test.xmlprimitives.data.Nullables setNInt32(Integer value); + + /** + * Checks, whether {@link #getNInt32()} has a value. + */ + boolean hasNInt32(); + + Integer getNSint32(); + + /** + * @see #getNSint32() + */ + test.xmlprimitives.data.Nullables setNSint32(Integer value); + + /** + * Checks, whether {@link #getNSint32()} has a value. + */ + boolean hasNSint32(); + + Integer getNUint32(); + + /** + * @see #getNUint32() + */ + test.xmlprimitives.data.Nullables setNUint32(Integer value); + + /** + * Checks, whether {@link #getNUint32()} has a value. + */ + boolean hasNUint32(); + + Integer getNFixed32(); + + /** + * @see #getNFixed32() + */ + test.xmlprimitives.data.Nullables setNFixed32(Integer value); + + /** + * Checks, whether {@link #getNFixed32()} has a value. + */ + boolean hasNFixed32(); + + Integer getNSfixed32(); + + /** + * @see #getNSfixed32() + */ + test.xmlprimitives.data.Nullables setNSfixed32(Integer value); + + /** + * Checks, whether {@link #getNSfixed32()} has a value. + */ + boolean hasNSfixed32(); + + Long getNInt64(); + + /** + * @see #getNInt64() + */ + test.xmlprimitives.data.Nullables setNInt64(Long value); + + /** + * Checks, whether {@link #getNInt64()} has a value. + */ + boolean hasNInt64(); + + Long getNSint64(); + + /** + * @see #getNSint64() + */ + test.xmlprimitives.data.Nullables setNSint64(Long value); + + /** + * Checks, whether {@link #getNSint64()} has a value. + */ + boolean hasNSint64(); + + Long getNUint64(); + + /** + * @see #getNUint64() + */ + test.xmlprimitives.data.Nullables setNUint64(Long value); + + /** + * Checks, whether {@link #getNUint64()} has a value. + */ + boolean hasNUint64(); + + Long getNFixed64(); + + /** + * @see #getNFixed64() + */ + test.xmlprimitives.data.Nullables setNFixed64(Long value); + + /** + * Checks, whether {@link #getNFixed64()} has a value. + */ + boolean hasNFixed64(); + + Long getNSfixed64(); + + /** + * @see #getNSfixed64() + */ + test.xmlprimitives.data.Nullables setNSfixed64(Long value); + + /** + * Checks, whether {@link #getNSfixed64()} has a value. + */ + boolean hasNSfixed64(); + + Float getNFloat(); + + /** + * @see #getNFloat() + */ + test.xmlprimitives.data.Nullables setNFloat(Float value); + + /** + * Checks, whether {@link #getNFloat()} has a value. + */ + boolean hasNFloat(); + + Double getNDouble(); + + /** + * @see #getNDouble() + */ + test.xmlprimitives.data.Nullables setNDouble(Double value); + + /** + * Checks, whether {@link #getNDouble()} has a value. + */ + boolean hasNDouble(); + + String getNString(); + + /** + * @see #getNString() + */ + test.xmlprimitives.data.Nullables setNString(String value); + + /** + * Checks, whether {@link #getNString()} has a value. + */ + boolean hasNString(); + + byte[] getNBytes(); + + /** + * @see #getNBytes() + */ + test.xmlprimitives.data.Nullables setNBytes(byte[] value); + + /** + * Checks, whether {@link #getNBytes()} has a value. + */ + boolean hasNBytes(); + + Object getNJson(); + + /** + * @see #getNJson() + */ + test.xmlprimitives.data.Nullables setNJson(Object value); + + /** + * Checks, whether {@link #getNJson()} has a value. + */ + boolean hasNJson(); + + test.xmlprimitives.data.Color getNColor(); + + /** + * @see #getNColor() + */ + test.xmlprimitives.data.Nullables setNColor(test.xmlprimitives.data.Color value); + + /** + * Checks, whether {@link #getNColor()} has a value. + */ + boolean hasNColor(); + + java.util.List getNlInt32(); + + /** + * @see #getNlInt32() + */ + test.xmlprimitives.data.Nullables setNlInt32(java.util.List value); + + /** + * Adds a value to the {@link #getNlInt32()} list. + */ + test.xmlprimitives.data.Nullables addNlInt32(int value); + + /** + * Removes a value from the {@link #getNlInt32()} list. + */ + void removeNlInt32(int value); + + /** + * Checks, whether {@link #getNlInt32()} has a value. + */ + boolean hasNlInt32(); + + java.util.List getNlUint32(); + + /** + * @see #getNlUint32() + */ + test.xmlprimitives.data.Nullables setNlUint32(java.util.List value); + + /** + * Adds a value to the {@link #getNlUint32()} list. + */ + test.xmlprimitives.data.Nullables addNlUint32(int value); + + /** + * Removes a value from the {@link #getNlUint32()} list. + */ + void removeNlUint32(int value); + + /** + * Checks, whether {@link #getNlUint32()} has a value. + */ + boolean hasNlUint32(); + + java.util.List getNlString(); + + /** + * @see #getNlString() + */ + test.xmlprimitives.data.Nullables setNlString(java.util.List value); + + /** + * Adds a value to the {@link #getNlString()} list. + */ + test.xmlprimitives.data.Nullables addNlString(String value); + + /** + * Removes a value from the {@link #getNlString()} list. + */ + void removeNlString(String value); + + /** + * Checks, whether {@link #getNlString()} has a value. + */ + boolean hasNlString(); + + java.util.List getNlBytes(); + + /** + * @see #getNlBytes() + */ + test.xmlprimitives.data.Nullables setNlBytes(java.util.List value); + + /** + * Adds a value to the {@link #getNlBytes()} list. + */ + test.xmlprimitives.data.Nullables addNlByte(byte[] value); + + /** + * Removes a value from the {@link #getNlBytes()} list. + */ + void removeNlByte(byte[] value); + + /** + * Checks, whether {@link #getNlBytes()} has a value. + */ + boolean hasNlBytes(); + + @Override + public test.xmlprimitives.data.Nullables registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.xmlprimitives.data.Nullables unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.xmlprimitives.data.Nullables readNullables(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.xmlprimitives.data.impl.Nullables_Impl result = new test.xmlprimitives.data.impl.Nullables_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.xmlprimitives.data.Nullables readNullables(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.xmlprimitives.data.Nullables result = test.xmlprimitives.data.impl.Nullables_Impl.readNullables_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Nullables} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Nullables readNullables(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.xmlprimitives.data.impl.Nullables_Impl.readNullables_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Values.java b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Values.java new file mode 100644 index 00000000..a3364888 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/Values.java @@ -0,0 +1,271 @@ +package test.xmlprimitives.data; + +/** + * Every primitive type as singular field. + */ +public interface Values extends de.haumacher.msgbuf.data.DataObject, de.haumacher.msgbuf.binary.BinaryDataObject, de.haumacher.msgbuf.observer.Observable, de.haumacher.msgbuf.xml.XmlSerializable { + + /** + * Creates a {@link test.xmlprimitives.data.Values} instance. + */ + static test.xmlprimitives.data.Values create() { + return new test.xmlprimitives.data.impl.Values_Impl(); + } + + /** Identifier for the {@link test.xmlprimitives.data.Values} type in JSON format. */ + String VALUES__TYPE = "Values"; + + /** @see #isVBool() */ + String V_BOOL__PROP = "vBool"; + + /** @see #getVInt32() */ + String V_INT_32__PROP = "vInt32"; + + /** @see #getVSint32() */ + String V_SINT_32__PROP = "vSint32"; + + /** @see #getVUint32() */ + String V_UINT_32__PROP = "vUint32"; + + /** @see #getVFixed32() */ + String V_FIXED_32__PROP = "vFixed32"; + + /** @see #getVSfixed32() */ + String V_SFIXED_32__PROP = "vSfixed32"; + + /** @see #getVInt64() */ + String V_INT_64__PROP = "vInt64"; + + /** @see #getVSint64() */ + String V_SINT_64__PROP = "vSint64"; + + /** @see #getVUint64() */ + String V_UINT_64__PROP = "vUint64"; + + /** @see #getVFixed64() */ + String V_FIXED_64__PROP = "vFixed64"; + + /** @see #getVSfixed64() */ + String V_SFIXED_64__PROP = "vSfixed64"; + + /** @see #getVFloat() */ + String V_FLOAT__PROP = "vFloat"; + + /** @see #getVDouble() */ + String V_DOUBLE__PROP = "vDouble"; + + /** @see #getVString() */ + String V_STRING__PROP = "vString"; + + /** @see #getVBytes() */ + String V_BYTES__PROP = "vBytes"; + + /** @see #getVJson() */ + String V_JSON__PROP = "vJson"; + + /** @see #getVColor() */ + String V_COLOR__PROP = "vColor"; + + /** Identifier for the property {@link #isVBool()} in binary format. */ + static final int V_BOOL__ID = 1; + + /** Identifier for the property {@link #getVInt32()} in binary format. */ + static final int V_INT_32__ID = 2; + + /** Identifier for the property {@link #getVSint32()} in binary format. */ + static final int V_SINT_32__ID = 3; + + /** Identifier for the property {@link #getVUint32()} in binary format. */ + static final int V_UINT_32__ID = 4; + + /** Identifier for the property {@link #getVFixed32()} in binary format. */ + static final int V_FIXED_32__ID = 5; + + /** Identifier for the property {@link #getVSfixed32()} in binary format. */ + static final int V_SFIXED_32__ID = 6; + + /** Identifier for the property {@link #getVInt64()} in binary format. */ + static final int V_INT_64__ID = 7; + + /** Identifier for the property {@link #getVSint64()} in binary format. */ + static final int V_SINT_64__ID = 8; + + /** Identifier for the property {@link #getVUint64()} in binary format. */ + static final int V_UINT_64__ID = 9; + + /** Identifier for the property {@link #getVFixed64()} in binary format. */ + static final int V_FIXED_64__ID = 10; + + /** Identifier for the property {@link #getVSfixed64()} in binary format. */ + static final int V_SFIXED_64__ID = 11; + + /** Identifier for the property {@link #getVFloat()} in binary format. */ + static final int V_FLOAT__ID = 12; + + /** Identifier for the property {@link #getVDouble()} in binary format. */ + static final int V_DOUBLE__ID = 13; + + /** Identifier for the property {@link #getVString()} in binary format. */ + static final int V_STRING__ID = 14; + + /** Identifier for the property {@link #getVBytes()} in binary format. */ + static final int V_BYTES__ID = 15; + + /** Identifier for the property {@link #getVJson()} in binary format. */ + static final int V_JSON__ID = 16; + + /** Identifier for the property {@link #getVColor()} in binary format. */ + static final int V_COLOR__ID = 17; + + boolean isVBool(); + + /** + * @see #isVBool() + */ + test.xmlprimitives.data.Values setVBool(boolean value); + + int getVInt32(); + + /** + * @see #getVInt32() + */ + test.xmlprimitives.data.Values setVInt32(int value); + + int getVSint32(); + + /** + * @see #getVSint32() + */ + test.xmlprimitives.data.Values setVSint32(int value); + + int getVUint32(); + + /** + * @see #getVUint32() + */ + test.xmlprimitives.data.Values setVUint32(int value); + + int getVFixed32(); + + /** + * @see #getVFixed32() + */ + test.xmlprimitives.data.Values setVFixed32(int value); + + int getVSfixed32(); + + /** + * @see #getVSfixed32() + */ + test.xmlprimitives.data.Values setVSfixed32(int value); + + long getVInt64(); + + /** + * @see #getVInt64() + */ + test.xmlprimitives.data.Values setVInt64(long value); + + long getVSint64(); + + /** + * @see #getVSint64() + */ + test.xmlprimitives.data.Values setVSint64(long value); + + long getVUint64(); + + /** + * @see #getVUint64() + */ + test.xmlprimitives.data.Values setVUint64(long value); + + long getVFixed64(); + + /** + * @see #getVFixed64() + */ + test.xmlprimitives.data.Values setVFixed64(long value); + + long getVSfixed64(); + + /** + * @see #getVSfixed64() + */ + test.xmlprimitives.data.Values setVSfixed64(long value); + + float getVFloat(); + + /** + * @see #getVFloat() + */ + test.xmlprimitives.data.Values setVFloat(float value); + + double getVDouble(); + + /** + * @see #getVDouble() + */ + test.xmlprimitives.data.Values setVDouble(double value); + + String getVString(); + + /** + * @see #getVString() + */ + test.xmlprimitives.data.Values setVString(String value); + + byte[] getVBytes(); + + /** + * @see #getVBytes() + */ + test.xmlprimitives.data.Values setVBytes(byte[] value); + + Object getVJson(); + + /** + * @see #getVJson() + */ + test.xmlprimitives.data.Values setVJson(Object value); + + /** + * Checks, whether {@link #getVJson()} has a value. + */ + boolean hasVJson(); + + test.xmlprimitives.data.Color getVColor(); + + /** + * @see #getVColor() + */ + test.xmlprimitives.data.Values setVColor(test.xmlprimitives.data.Color value); + + @Override + public test.xmlprimitives.data.Values registerListener(de.haumacher.msgbuf.observer.Listener l); + + @Override + public test.xmlprimitives.data.Values unregisterListener(de.haumacher.msgbuf.observer.Listener l); + + /** Reads a new instance from the given reader. */ + static test.xmlprimitives.data.Values readValues(de.haumacher.msgbuf.json.JsonReader in) throws java.io.IOException { + test.xmlprimitives.data.impl.Values_Impl result = new test.xmlprimitives.data.impl.Values_Impl(); + result.readContent(in); + return result; + } + + /** Reads a new instance from the given reader. */ + static test.xmlprimitives.data.Values readValues(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + in.beginObject(); + test.xmlprimitives.data.Values result = test.xmlprimitives.data.impl.Values_Impl.readValues_Content(in); + in.endObject(); + return result; + } + + /** Creates a new {@link Values} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Values readValues(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + in.nextTag(); + return test.xmlprimitives.data.impl.Values_Impl.readValues_XmlContent(in); + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/impl/Lists_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/impl/Lists_Impl.java new file mode 100644 index 00000000..d21ad88b --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/impl/Lists_Impl.java @@ -0,0 +1,1800 @@ +package test.xmlprimitives.data.impl; + +/** + * Implementation of {@link test.xmlprimitives.data.Lists}. + */ +public class Lists_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.xmlprimitives.data.Lists { + + private final java.util.List _lBool = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, Boolean element) { + _listener.beforeAdd(Lists_Impl.this, L_BOOL__PROP, index, element); + } + + @Override + protected void afterRemove(int index, Boolean element) { + _listener.afterRemove(Lists_Impl.this, L_BOOL__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_BOOL__PROP); + } + }; + + private final java.util.List _lInt32 = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, Integer element) { + _listener.beforeAdd(Lists_Impl.this, L_INT_32__PROP, index, element); + } + + @Override + protected void afterRemove(int index, Integer element) { + _listener.afterRemove(Lists_Impl.this, L_INT_32__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_INT_32__PROP); + } + }; + + private final java.util.List _lSint32 = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, Integer element) { + _listener.beforeAdd(Lists_Impl.this, L_SINT_32__PROP, index, element); + } + + @Override + protected void afterRemove(int index, Integer element) { + _listener.afterRemove(Lists_Impl.this, L_SINT_32__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_SINT_32__PROP); + } + }; + + private final java.util.List _lUint32 = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, Integer element) { + _listener.beforeAdd(Lists_Impl.this, L_UINT_32__PROP, index, element); + } + + @Override + protected void afterRemove(int index, Integer element) { + _listener.afterRemove(Lists_Impl.this, L_UINT_32__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_UINT_32__PROP); + } + }; + + private final java.util.List _lFixed32 = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, Integer element) { + _listener.beforeAdd(Lists_Impl.this, L_FIXED_32__PROP, index, element); + } + + @Override + protected void afterRemove(int index, Integer element) { + _listener.afterRemove(Lists_Impl.this, L_FIXED_32__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_FIXED_32__PROP); + } + }; + + private final java.util.List _lSfixed32 = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, Integer element) { + _listener.beforeAdd(Lists_Impl.this, L_SFIXED_32__PROP, index, element); + } + + @Override + protected void afterRemove(int index, Integer element) { + _listener.afterRemove(Lists_Impl.this, L_SFIXED_32__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_SFIXED_32__PROP); + } + }; + + private final java.util.List _lInt64 = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, Long element) { + _listener.beforeAdd(Lists_Impl.this, L_INT_64__PROP, index, element); + } + + @Override + protected void afterRemove(int index, Long element) { + _listener.afterRemove(Lists_Impl.this, L_INT_64__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_INT_64__PROP); + } + }; + + private final java.util.List _lSint64 = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, Long element) { + _listener.beforeAdd(Lists_Impl.this, L_SINT_64__PROP, index, element); + } + + @Override + protected void afterRemove(int index, Long element) { + _listener.afterRemove(Lists_Impl.this, L_SINT_64__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_SINT_64__PROP); + } + }; + + private final java.util.List _lUint64 = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, Long element) { + _listener.beforeAdd(Lists_Impl.this, L_UINT_64__PROP, index, element); + } + + @Override + protected void afterRemove(int index, Long element) { + _listener.afterRemove(Lists_Impl.this, L_UINT_64__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_UINT_64__PROP); + } + }; + + private final java.util.List _lFixed64 = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, Long element) { + _listener.beforeAdd(Lists_Impl.this, L_FIXED_64__PROP, index, element); + } + + @Override + protected void afterRemove(int index, Long element) { + _listener.afterRemove(Lists_Impl.this, L_FIXED_64__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_FIXED_64__PROP); + } + }; + + private final java.util.List _lSfixed64 = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, Long element) { + _listener.beforeAdd(Lists_Impl.this, L_SFIXED_64__PROP, index, element); + } + + @Override + protected void afterRemove(int index, Long element) { + _listener.afterRemove(Lists_Impl.this, L_SFIXED_64__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_SFIXED_64__PROP); + } + }; + + private final java.util.List _lFloat = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, Float element) { + _listener.beforeAdd(Lists_Impl.this, L_FLOAT__PROP, index, element); + } + + @Override + protected void afterRemove(int index, Float element) { + _listener.afterRemove(Lists_Impl.this, L_FLOAT__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_FLOAT__PROP); + } + }; + + private final java.util.List _lDouble = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, Double element) { + _listener.beforeAdd(Lists_Impl.this, L_DOUBLE__PROP, index, element); + } + + @Override + protected void afterRemove(int index, Double element) { + _listener.afterRemove(Lists_Impl.this, L_DOUBLE__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_DOUBLE__PROP); + } + }; + + private final java.util.List _lString = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, String element) { + _listener.beforeAdd(Lists_Impl.this, L_STRING__PROP, index, element); + } + + @Override + protected void afterRemove(int index, String element) { + _listener.afterRemove(Lists_Impl.this, L_STRING__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_STRING__PROP); + } + }; + + private final java.util.List _lBytes = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, byte[] element) { + _listener.beforeAdd(Lists_Impl.this, L_BYTES__PROP, index, element); + } + + @Override + protected void afterRemove(int index, byte[] element) { + _listener.afterRemove(Lists_Impl.this, L_BYTES__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_BYTES__PROP); + } + }; + + private final java.util.List _lColor = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, test.xmlprimitives.data.Color element) { + _listener.beforeAdd(Lists_Impl.this, L_COLOR__PROP, index, element); + } + + @Override + protected void afterRemove(int index, test.xmlprimitives.data.Color element) { + _listener.afterRemove(Lists_Impl.this, L_COLOR__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Lists_Impl.this, L_COLOR__PROP); + } + }; + + /** + * Creates a {@link Lists_Impl} instance. + * + * @see test.xmlprimitives.data.Lists#create() + */ + public Lists_Impl() { + super(); + } + + @Override + public final java.util.List isLBool() { + return _lBool; + } + + @Override + public test.xmlprimitives.data.Lists setLBool(java.util.List value) { + internalSetLBool(value); + return this; + } + + /** Internal setter for {@link #isLBool()} without chain call utility. */ + protected final void internalSetLBool(java.util.List value) { + _lBool.clear(); + _lBool.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLBool(boolean value) { + internalAddLBool(value); + return this; + } + + /** Implementation of {@link #addLBool(boolean)} without chain call utility. */ + protected final void internalAddLBool(boolean value) { + _lBool.add(value); + } + + @Override + public final void removeLBool(boolean value) { + _lBool.remove(value); + } + + @Override + public final java.util.List getLInt32() { + return _lInt32; + } + + @Override + public test.xmlprimitives.data.Lists setLInt32(java.util.List value) { + internalSetLInt32(value); + return this; + } + + /** Internal setter for {@link #getLInt32()} without chain call utility. */ + protected final void internalSetLInt32(java.util.List value) { + _lInt32.clear(); + _lInt32.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLInt32(int value) { + internalAddLInt32(value); + return this; + } + + /** Implementation of {@link #addLInt32(int)} without chain call utility. */ + protected final void internalAddLInt32(int value) { + _lInt32.add(value); + } + + @Override + public final void removeLInt32(int value) { + _lInt32.remove(value); + } + + @Override + public final java.util.List getLSint32() { + return _lSint32; + } + + @Override + public test.xmlprimitives.data.Lists setLSint32(java.util.List value) { + internalSetLSint32(value); + return this; + } + + /** Internal setter for {@link #getLSint32()} without chain call utility. */ + protected final void internalSetLSint32(java.util.List value) { + _lSint32.clear(); + _lSint32.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLSint32(int value) { + internalAddLSint32(value); + return this; + } + + /** Implementation of {@link #addLSint32(int)} without chain call utility. */ + protected final void internalAddLSint32(int value) { + _lSint32.add(value); + } + + @Override + public final void removeLSint32(int value) { + _lSint32.remove(value); + } + + @Override + public final java.util.List getLUint32() { + return _lUint32; + } + + @Override + public test.xmlprimitives.data.Lists setLUint32(java.util.List value) { + internalSetLUint32(value); + return this; + } + + /** Internal setter for {@link #getLUint32()} without chain call utility. */ + protected final void internalSetLUint32(java.util.List value) { + _lUint32.clear(); + _lUint32.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLUint32(int value) { + internalAddLUint32(value); + return this; + } + + /** Implementation of {@link #addLUint32(int)} without chain call utility. */ + protected final void internalAddLUint32(int value) { + _lUint32.add(value); + } + + @Override + public final void removeLUint32(int value) { + _lUint32.remove(value); + } + + @Override + public final java.util.List getLFixed32() { + return _lFixed32; + } + + @Override + public test.xmlprimitives.data.Lists setLFixed32(java.util.List value) { + internalSetLFixed32(value); + return this; + } + + /** Internal setter for {@link #getLFixed32()} without chain call utility. */ + protected final void internalSetLFixed32(java.util.List value) { + _lFixed32.clear(); + _lFixed32.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLFixed32(int value) { + internalAddLFixed32(value); + return this; + } + + /** Implementation of {@link #addLFixed32(int)} without chain call utility. */ + protected final void internalAddLFixed32(int value) { + _lFixed32.add(value); + } + + @Override + public final void removeLFixed32(int value) { + _lFixed32.remove(value); + } + + @Override + public final java.util.List getLSfixed32() { + return _lSfixed32; + } + + @Override + public test.xmlprimitives.data.Lists setLSfixed32(java.util.List value) { + internalSetLSfixed32(value); + return this; + } + + /** Internal setter for {@link #getLSfixed32()} without chain call utility. */ + protected final void internalSetLSfixed32(java.util.List value) { + _lSfixed32.clear(); + _lSfixed32.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLSfixed32(int value) { + internalAddLSfixed32(value); + return this; + } + + /** Implementation of {@link #addLSfixed32(int)} without chain call utility. */ + protected final void internalAddLSfixed32(int value) { + _lSfixed32.add(value); + } + + @Override + public final void removeLSfixed32(int value) { + _lSfixed32.remove(value); + } + + @Override + public final java.util.List getLInt64() { + return _lInt64; + } + + @Override + public test.xmlprimitives.data.Lists setLInt64(java.util.List value) { + internalSetLInt64(value); + return this; + } + + /** Internal setter for {@link #getLInt64()} without chain call utility. */ + protected final void internalSetLInt64(java.util.List value) { + _lInt64.clear(); + _lInt64.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLInt64(long value) { + internalAddLInt64(value); + return this; + } + + /** Implementation of {@link #addLInt64(long)} without chain call utility. */ + protected final void internalAddLInt64(long value) { + _lInt64.add(value); + } + + @Override + public final void removeLInt64(long value) { + _lInt64.remove(value); + } + + @Override + public final java.util.List getLSint64() { + return _lSint64; + } + + @Override + public test.xmlprimitives.data.Lists setLSint64(java.util.List value) { + internalSetLSint64(value); + return this; + } + + /** Internal setter for {@link #getLSint64()} without chain call utility. */ + protected final void internalSetLSint64(java.util.List value) { + _lSint64.clear(); + _lSint64.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLSint64(long value) { + internalAddLSint64(value); + return this; + } + + /** Implementation of {@link #addLSint64(long)} without chain call utility. */ + protected final void internalAddLSint64(long value) { + _lSint64.add(value); + } + + @Override + public final void removeLSint64(long value) { + _lSint64.remove(value); + } + + @Override + public final java.util.List getLUint64() { + return _lUint64; + } + + @Override + public test.xmlprimitives.data.Lists setLUint64(java.util.List value) { + internalSetLUint64(value); + return this; + } + + /** Internal setter for {@link #getLUint64()} without chain call utility. */ + protected final void internalSetLUint64(java.util.List value) { + _lUint64.clear(); + _lUint64.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLUint64(long value) { + internalAddLUint64(value); + return this; + } + + /** Implementation of {@link #addLUint64(long)} without chain call utility. */ + protected final void internalAddLUint64(long value) { + _lUint64.add(value); + } + + @Override + public final void removeLUint64(long value) { + _lUint64.remove(value); + } + + @Override + public final java.util.List getLFixed64() { + return _lFixed64; + } + + @Override + public test.xmlprimitives.data.Lists setLFixed64(java.util.List value) { + internalSetLFixed64(value); + return this; + } + + /** Internal setter for {@link #getLFixed64()} without chain call utility. */ + protected final void internalSetLFixed64(java.util.List value) { + _lFixed64.clear(); + _lFixed64.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLFixed64(long value) { + internalAddLFixed64(value); + return this; + } + + /** Implementation of {@link #addLFixed64(long)} without chain call utility. */ + protected final void internalAddLFixed64(long value) { + _lFixed64.add(value); + } + + @Override + public final void removeLFixed64(long value) { + _lFixed64.remove(value); + } + + @Override + public final java.util.List getLSfixed64() { + return _lSfixed64; + } + + @Override + public test.xmlprimitives.data.Lists setLSfixed64(java.util.List value) { + internalSetLSfixed64(value); + return this; + } + + /** Internal setter for {@link #getLSfixed64()} without chain call utility. */ + protected final void internalSetLSfixed64(java.util.List value) { + _lSfixed64.clear(); + _lSfixed64.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLSfixed64(long value) { + internalAddLSfixed64(value); + return this; + } + + /** Implementation of {@link #addLSfixed64(long)} without chain call utility. */ + protected final void internalAddLSfixed64(long value) { + _lSfixed64.add(value); + } + + @Override + public final void removeLSfixed64(long value) { + _lSfixed64.remove(value); + } + + @Override + public final java.util.List getLFloat() { + return _lFloat; + } + + @Override + public test.xmlprimitives.data.Lists setLFloat(java.util.List value) { + internalSetLFloat(value); + return this; + } + + /** Internal setter for {@link #getLFloat()} without chain call utility. */ + protected final void internalSetLFloat(java.util.List value) { + _lFloat.clear(); + _lFloat.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLFloat(float value) { + internalAddLFloat(value); + return this; + } + + /** Implementation of {@link #addLFloat(float)} without chain call utility. */ + protected final void internalAddLFloat(float value) { + _lFloat.add(value); + } + + @Override + public final void removeLFloat(float value) { + _lFloat.remove(value); + } + + @Override + public final java.util.List getLDouble() { + return _lDouble; + } + + @Override + public test.xmlprimitives.data.Lists setLDouble(java.util.List value) { + internalSetLDouble(value); + return this; + } + + /** Internal setter for {@link #getLDouble()} without chain call utility. */ + protected final void internalSetLDouble(java.util.List value) { + _lDouble.clear(); + _lDouble.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLDouble(double value) { + internalAddLDouble(value); + return this; + } + + /** Implementation of {@link #addLDouble(double)} without chain call utility. */ + protected final void internalAddLDouble(double value) { + _lDouble.add(value); + } + + @Override + public final void removeLDouble(double value) { + _lDouble.remove(value); + } + + @Override + public final java.util.List getLString() { + return _lString; + } + + @Override + public test.xmlprimitives.data.Lists setLString(java.util.List value) { + internalSetLString(value); + return this; + } + + /** Internal setter for {@link #getLString()} without chain call utility. */ + protected final void internalSetLString(java.util.List value) { + _lString.clear(); + _lString.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLString(String value) { + internalAddLString(value); + return this; + } + + /** Implementation of {@link #addLString(String)} without chain call utility. */ + protected final void internalAddLString(String value) { + _lString.add(value); + } + + @Override + public final void removeLString(String value) { + _lString.remove(value); + } + + @Override + public final java.util.List getLBytes() { + return _lBytes; + } + + @Override + public test.xmlprimitives.data.Lists setLBytes(java.util.List value) { + internalSetLBytes(value); + return this; + } + + /** Internal setter for {@link #getLBytes()} without chain call utility. */ + protected final void internalSetLBytes(java.util.List value) { + _lBytes.clear(); + _lBytes.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLByte(byte[] value) { + internalAddLByte(value); + return this; + } + + /** Implementation of {@link #addLByte(byte[])} without chain call utility. */ + protected final void internalAddLByte(byte[] value) { + _lBytes.add(value); + } + + @Override + public final void removeLByte(byte[] value) { + _lBytes.remove(value); + } + + @Override + public final java.util.List getLColor() { + return _lColor; + } + + @Override + public test.xmlprimitives.data.Lists setLColor(java.util.List value) { + internalSetLColor(value); + return this; + } + + /** Internal setter for {@link #getLColor()} without chain call utility. */ + protected final void internalSetLColor(java.util.List value) { + if (value == null) throw new IllegalArgumentException("Property 'lColor' cannot be null."); + _lColor.clear(); + _lColor.addAll(value); + } + + @Override + public test.xmlprimitives.data.Lists addLColor(test.xmlprimitives.data.Color value) { + internalAddLColor(value); + return this; + } + + /** Implementation of {@link #addLColor(test.xmlprimitives.data.Color)} without chain call utility. */ + protected final void internalAddLColor(test.xmlprimitives.data.Color value) { + _lColor.add(value); + } + + @Override + public final void removeLColor(test.xmlprimitives.data.Color value) { + _lColor.remove(value); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.xmlprimitives.data.Lists registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.xmlprimitives.data.Lists unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return LISTS__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + L_BOOL__PROP, + L_INT_32__PROP, + L_SINT_32__PROP, + L_UINT_32__PROP, + L_FIXED_32__PROP, + L_SFIXED_32__PROP, + L_INT_64__PROP, + L_SINT_64__PROP, + L_UINT_64__PROP, + L_FIXED_64__PROP, + L_SFIXED_64__PROP, + L_FLOAT__PROP, + L_DOUBLE__PROP, + L_STRING__PROP, + L_BYTES__PROP, + L_COLOR__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case L_BOOL__PROP: return isLBool(); + case L_INT_32__PROP: return getLInt32(); + case L_SINT_32__PROP: return getLSint32(); + case L_UINT_32__PROP: return getLUint32(); + case L_FIXED_32__PROP: return getLFixed32(); + case L_SFIXED_32__PROP: return getLSfixed32(); + case L_INT_64__PROP: return getLInt64(); + case L_SINT_64__PROP: return getLSint64(); + case L_UINT_64__PROP: return getLUint64(); + case L_FIXED_64__PROP: return getLFixed64(); + case L_SFIXED_64__PROP: return getLSfixed64(); + case L_FLOAT__PROP: return getLFloat(); + case L_DOUBLE__PROP: return getLDouble(); + case L_STRING__PROP: return getLString(); + case L_BYTES__PROP: return getLBytes(); + case L_COLOR__PROP: return getLColor(); + default: return test.xmlprimitives.data.Lists.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case L_BOOL__PROP: internalSetLBool(de.haumacher.msgbuf.util.Conversions.asList(Boolean.class, value)); break; + case L_INT_32__PROP: internalSetLInt32(de.haumacher.msgbuf.util.Conversions.asList(Integer.class, value)); break; + case L_SINT_32__PROP: internalSetLSint32(de.haumacher.msgbuf.util.Conversions.asList(Integer.class, value)); break; + case L_UINT_32__PROP: internalSetLUint32(de.haumacher.msgbuf.util.Conversions.asList(Integer.class, value)); break; + case L_FIXED_32__PROP: internalSetLFixed32(de.haumacher.msgbuf.util.Conversions.asList(Integer.class, value)); break; + case L_SFIXED_32__PROP: internalSetLSfixed32(de.haumacher.msgbuf.util.Conversions.asList(Integer.class, value)); break; + case L_INT_64__PROP: internalSetLInt64(de.haumacher.msgbuf.util.Conversions.asList(Long.class, value)); break; + case L_SINT_64__PROP: internalSetLSint64(de.haumacher.msgbuf.util.Conversions.asList(Long.class, value)); break; + case L_UINT_64__PROP: internalSetLUint64(de.haumacher.msgbuf.util.Conversions.asList(Long.class, value)); break; + case L_FIXED_64__PROP: internalSetLFixed64(de.haumacher.msgbuf.util.Conversions.asList(Long.class, value)); break; + case L_SFIXED_64__PROP: internalSetLSfixed64(de.haumacher.msgbuf.util.Conversions.asList(Long.class, value)); break; + case L_FLOAT__PROP: internalSetLFloat(de.haumacher.msgbuf.util.Conversions.asList(Float.class, value)); break; + case L_DOUBLE__PROP: internalSetLDouble(de.haumacher.msgbuf.util.Conversions.asList(Double.class, value)); break; + case L_STRING__PROP: internalSetLString(de.haumacher.msgbuf.util.Conversions.asList(String.class, value)); break; + case L_BYTES__PROP: internalSetLBytes(de.haumacher.msgbuf.util.Conversions.asList(byte[].class, value)); break; + case L_COLOR__PROP: internalSetLColor(de.haumacher.msgbuf.util.Conversions.asList(test.xmlprimitives.data.Color.class, value)); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(L_BOOL__PROP); + out.beginArray(); + for (boolean x : isLBool()) { + out.value(x); + } + out.endArray(); + out.name(L_INT_32__PROP); + out.beginArray(); + for (int x : getLInt32()) { + out.value(x); + } + out.endArray(); + out.name(L_SINT_32__PROP); + out.beginArray(); + for (int x : getLSint32()) { + out.value(x); + } + out.endArray(); + out.name(L_UINT_32__PROP); + out.beginArray(); + for (int x : getLUint32()) { + out.value(x); + } + out.endArray(); + out.name(L_FIXED_32__PROP); + out.beginArray(); + for (int x : getLFixed32()) { + out.value(x); + } + out.endArray(); + out.name(L_SFIXED_32__PROP); + out.beginArray(); + for (int x : getLSfixed32()) { + out.value(x); + } + out.endArray(); + out.name(L_INT_64__PROP); + out.beginArray(); + for (long x : getLInt64()) { + out.value(x); + } + out.endArray(); + out.name(L_SINT_64__PROP); + out.beginArray(); + for (long x : getLSint64()) { + out.value(x); + } + out.endArray(); + out.name(L_UINT_64__PROP); + out.beginArray(); + for (long x : getLUint64()) { + out.value(x); + } + out.endArray(); + out.name(L_FIXED_64__PROP); + out.beginArray(); + for (long x : getLFixed64()) { + out.value(x); + } + out.endArray(); + out.name(L_SFIXED_64__PROP); + out.beginArray(); + for (long x : getLSfixed64()) { + out.value(x); + } + out.endArray(); + out.name(L_FLOAT__PROP); + out.beginArray(); + for (float x : getLFloat()) { + out.value(x); + } + out.endArray(); + out.name(L_DOUBLE__PROP); + out.beginArray(); + for (double x : getLDouble()) { + out.value(x); + } + out.endArray(); + out.name(L_STRING__PROP); + out.beginArray(); + for (String x : getLString()) { + out.value(x); + } + out.endArray(); + out.name(L_BYTES__PROP); + out.beginArray(); + for (byte[] x : getLBytes()) { + de.haumacher.msgbuf.json.JsonUtil.writeBinaryOptional(out, x); + } + out.endArray(); + out.name(L_COLOR__PROP); + out.beginArray(); + for (test.xmlprimitives.data.Color x : getLColor()) { + x.writeTo(out); + } + out.endArray(); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case L_BOOL__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(in.nextBoolean()); + } + in.endArray(); + setLBool(newValue); + } + break; + case L_INT_32__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(in.nextInt()); + } + in.endArray(); + setLInt32(newValue); + } + break; + case L_SINT_32__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(in.nextInt()); + } + in.endArray(); + setLSint32(newValue); + } + break; + case L_UINT_32__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(in.nextInt()); + } + in.endArray(); + setLUint32(newValue); + } + break; + case L_FIXED_32__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(in.nextInt()); + } + in.endArray(); + setLFixed32(newValue); + } + break; + case L_SFIXED_32__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(in.nextInt()); + } + in.endArray(); + setLSfixed32(newValue); + } + break; + case L_INT_64__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(in.nextLong()); + } + in.endArray(); + setLInt64(newValue); + } + break; + case L_SINT_64__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(in.nextLong()); + } + in.endArray(); + setLSint64(newValue); + } + break; + case L_UINT_64__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(in.nextLong()); + } + in.endArray(); + setLUint64(newValue); + } + break; + case L_FIXED_64__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(in.nextLong()); + } + in.endArray(); + setLFixed64(newValue); + } + break; + case L_SFIXED_64__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(in.nextLong()); + } + in.endArray(); + setLSfixed64(newValue); + } + break; + case L_FLOAT__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add((float) in.nextDouble()); + } + in.endArray(); + setLFloat(newValue); + } + break; + case L_DOUBLE__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(in.nextDouble()); + } + in.endArray(); + setLDouble(newValue); + } + break; + case L_STRING__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); + } + in.endArray(); + setLString(newValue); + } + break; + case L_BYTES__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(de.haumacher.msgbuf.json.JsonUtil.nextBinaryOptional(in)); + } + in.endArray(); + setLBytes(newValue); + } + break; + case L_COLOR__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(test.xmlprimitives.data.Color.readColor(in)); + } + in.endArray(); + setLColor(newValue); + } + break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(L_BOOL__ID); + { + java.util.List values = isLBool(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.INT, values.size()); + for (boolean x : values) { + out.value(x); + } + out.endArray(); + } + out.name(L_INT_32__ID); + { + java.util.List values = getLInt32(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.INT, values.size()); + for (int x : values) { + out.value(x); + } + out.endArray(); + } + out.name(L_SINT_32__ID); + { + java.util.List values = getLSint32(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.SINT, values.size()); + for (int x : values) { + out.valueSigned(x); + } + out.endArray(); + } + out.name(L_UINT_32__ID); + { + java.util.List values = getLUint32(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.INT, values.size()); + for (int x : values) { + out.value(x); + } + out.endArray(); + } + out.name(L_FIXED_32__ID); + { + java.util.List values = getLFixed32(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.FINT, values.size()); + for (int x : values) { + out.valueFixed(x); + } + out.endArray(); + } + out.name(L_SFIXED_32__ID); + { + java.util.List values = getLSfixed32(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.FINT, values.size()); + for (int x : values) { + out.valueFixed(x); + } + out.endArray(); + } + out.name(L_INT_64__ID); + { + java.util.List values = getLInt64(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.LONG, values.size()); + for (long x : values) { + out.value(x); + } + out.endArray(); + } + out.name(L_SINT_64__ID); + { + java.util.List values = getLSint64(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.SLONG, values.size()); + for (long x : values) { + out.valueSigned(x); + } + out.endArray(); + } + out.name(L_UINT_64__ID); + { + java.util.List values = getLUint64(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.LONG, values.size()); + for (long x : values) { + out.value(x); + } + out.endArray(); + } + out.name(L_FIXED_64__ID); + { + java.util.List values = getLFixed64(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.FLONG, values.size()); + for (long x : values) { + out.valueFixed(x); + } + out.endArray(); + } + out.name(L_SFIXED_64__ID); + { + java.util.List values = getLSfixed64(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.FLONG, values.size()); + for (long x : values) { + out.valueFixed(x); + } + out.endArray(); + } + out.name(L_FLOAT__ID); + { + java.util.List values = getLFloat(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.FLOAT, values.size()); + for (float x : values) { + out.value(x); + } + out.endArray(); + } + out.name(L_DOUBLE__ID); + { + java.util.List values = getLDouble(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.DOUBLE, values.size()); + for (double x : values) { + out.value(x); + } + out.endArray(); + } + out.name(L_STRING__ID); + { + java.util.List values = getLString(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.STRING, values.size()); + for (String x : values) { + out.value(x); + } + out.endArray(); + } + out.name(L_BYTES__ID); + { + java.util.List values = getLBytes(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.BINARY, values.size()); + for (byte[] x : values) { + out.value(x); + } + out.endArray(); + } + out.name(L_COLOR__ID); + { + java.util.List values = getLColor(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.INT, values.size()); + for (test.xmlprimitives.data.Color x : values) { + x.writeTo(out); + } + out.endArray(); + } + } + + /** Helper for creating an object of type {@link test.xmlprimitives.data.Lists} from a polymorphic composition. */ + public static test.xmlprimitives.data.Lists readLists_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.xmlprimitives.data.impl.Lists_Impl result = new Lists_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case L_BOOL__ID: { + in.beginArray(); + while (in.hasNext()) { + addLBool(in.nextBoolean()); + } + in.endArray(); + } + break; + case L_INT_32__ID: { + in.beginArray(); + while (in.hasNext()) { + addLInt32(in.nextInt()); + } + in.endArray(); + } + break; + case L_SINT_32__ID: { + in.beginArray(); + while (in.hasNext()) { + addLSint32(in.nextIntSigned()); + } + in.endArray(); + } + break; + case L_UINT_32__ID: { + in.beginArray(); + while (in.hasNext()) { + addLUint32(in.nextInt()); + } + in.endArray(); + } + break; + case L_FIXED_32__ID: { + in.beginArray(); + while (in.hasNext()) { + addLFixed32(in.nextIntFixed()); + } + in.endArray(); + } + break; + case L_SFIXED_32__ID: { + in.beginArray(); + while (in.hasNext()) { + addLSfixed32(in.nextIntFixed()); + } + in.endArray(); + } + break; + case L_INT_64__ID: { + in.beginArray(); + while (in.hasNext()) { + addLInt64(in.nextLong()); + } + in.endArray(); + } + break; + case L_SINT_64__ID: { + in.beginArray(); + while (in.hasNext()) { + addLSint64(in.nextLongSigned()); + } + in.endArray(); + } + break; + case L_UINT_64__ID: { + in.beginArray(); + while (in.hasNext()) { + addLUint64(in.nextLong()); + } + in.endArray(); + } + break; + case L_FIXED_64__ID: { + in.beginArray(); + while (in.hasNext()) { + addLFixed64(in.nextLongFixed()); + } + in.endArray(); + } + break; + case L_SFIXED_64__ID: { + in.beginArray(); + while (in.hasNext()) { + addLSfixed64(in.nextLongFixed()); + } + in.endArray(); + } + break; + case L_FLOAT__ID: { + in.beginArray(); + while (in.hasNext()) { + addLFloat(in.nextFloat()); + } + in.endArray(); + } + break; + case L_DOUBLE__ID: { + in.beginArray(); + while (in.hasNext()) { + addLDouble(in.nextDouble()); + } + in.endArray(); + } + break; + case L_STRING__ID: { + in.beginArray(); + while (in.hasNext()) { + addLString(in.nextString()); + } + in.endArray(); + } + break; + case L_BYTES__ID: { + in.beginArray(); + while (in.hasNext()) { + addLByte(in.nextBinary()); + } + in.endArray(); + } + break; + case L_COLOR__ID: { + in.beginArray(); + while (in.hasNext()) { + addLColor(test.xmlprimitives.data.Color.readColor(in)); + } + in.endArray(); + } + break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.xmlprimitives.data.Lists} type. */ + public static final String LISTS__XML_ELEMENT = "lists"; + + /** XML attribute or element name of a {@link #isLBool} property. */ + private static final String L_BOOL__XML_ATTR = "l-bool"; + + /** XML attribute or element name of a {@link #getLInt32} property. */ + private static final String L_INT_32__XML_ATTR = "l-int-32"; + + /** XML attribute or element name of a {@link #getLSint32} property. */ + private static final String L_SINT_32__XML_ATTR = "l-sint-32"; + + /** XML attribute or element name of a {@link #getLUint32} property. */ + private static final String L_UINT_32__XML_ATTR = "l-uint-32"; + + /** XML attribute or element name of a {@link #getLFixed32} property. */ + private static final String L_FIXED_32__XML_ATTR = "l-fixed-32"; + + /** XML attribute or element name of a {@link #getLSfixed32} property. */ + private static final String L_SFIXED_32__XML_ATTR = "l-sfixed-32"; + + /** XML attribute or element name of a {@link #getLInt64} property. */ + private static final String L_INT_64__XML_ATTR = "l-int-64"; + + /** XML attribute or element name of a {@link #getLSint64} property. */ + private static final String L_SINT_64__XML_ATTR = "l-sint-64"; + + /** XML attribute or element name of a {@link #getLUint64} property. */ + private static final String L_UINT_64__XML_ATTR = "l-uint-64"; + + /** XML attribute or element name of a {@link #getLFixed64} property. */ + private static final String L_FIXED_64__XML_ATTR = "l-fixed-64"; + + /** XML attribute or element name of a {@link #getLSfixed64} property. */ + private static final String L_SFIXED_64__XML_ATTR = "l-sfixed-64"; + + /** XML attribute or element name of a {@link #getLFloat} property. */ + private static final String L_FLOAT__XML_ATTR = "l-float"; + + /** XML attribute or element name of a {@link #getLDouble} property. */ + private static final String L_DOUBLE__XML_ATTR = "l-double"; + + /** XML attribute or element name of a {@link #getLString} property. */ + private static final String L_STRING__XML_ATTR = "l-string"; + + /** XML attribute or element name of a {@link #getLBytes} property. */ + private static final String L_BYTES__XML_ATTR = "l-bytes"; + + /** XML attribute or element name of a {@link #getLColor} property. */ + private static final String L_COLOR__XML_ATTR = "l-color"; + + @Override + public String getXmlTagName() { + return LISTS__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(L_BOOL__XML_ATTR, isLBool().stream().map(x -> Boolean.toString(x)).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(L_INT_32__XML_ATTR, getLInt32().stream().map(x -> Integer.toString(x)).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(L_SINT_32__XML_ATTR, getLSint32().stream().map(x -> Integer.toString(x)).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(L_UINT_32__XML_ATTR, getLUint32().stream().map(x -> Long.toString(Integer.toUnsignedLong(x))).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(L_FIXED_32__XML_ATTR, getLFixed32().stream().map(x -> Long.toString(Integer.toUnsignedLong(x))).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(L_SFIXED_32__XML_ATTR, getLSfixed32().stream().map(x -> Integer.toString(x)).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(L_INT_64__XML_ATTR, getLInt64().stream().map(x -> Long.toString(x)).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(L_SINT_64__XML_ATTR, getLSint64().stream().map(x -> Long.toString(x)).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(L_UINT_64__XML_ATTR, getLUint64().stream().map(x -> Long.toString(x)).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(L_FIXED_64__XML_ATTR, getLFixed64().stream().map(x -> Long.toString(x)).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(L_SFIXED_64__XML_ATTR, getLSfixed64().stream().map(x -> Long.toString(x)).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(L_FLOAT__XML_ATTR, getLFloat().stream().map(x -> Float.toString(x)).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(L_DOUBLE__XML_ATTR, getLDouble().stream().map(x -> Double.toString(x)).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(L_STRING__XML_ATTR, getLString().stream().map(x -> x).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(L_BYTES__XML_ATTR, getLBytes().stream().map(x -> java.util.Base64.getEncoder().encodeToString(x)).collect(java.util.stream.Collectors.joining(", "))); + out.writeAttribute(L_COLOR__XML_ATTR, getLColor().stream().map(x -> x.protocolName()).collect(java.util.stream.Collectors.joining(", "))); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.xmlprimitives.data.Lists} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Lists_Impl readLists_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Lists_Impl result = new Lists_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case L_BOOL__XML_ATTR: { + setLBool(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> Boolean.parseBoolean(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_INT_32__XML_ATTR: { + setLInt32(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> Integer.parseInt(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_SINT_32__XML_ATTR: { + setLSint32(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> Integer.parseInt(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_UINT_32__XML_ATTR: { + setLUint32(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> (int) Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_FIXED_32__XML_ATTR: { + setLFixed32(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> (int) Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_SFIXED_32__XML_ATTR: { + setLSfixed32(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> Integer.parseInt(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_INT_64__XML_ATTR: { + setLInt64(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_SINT_64__XML_ATTR: { + setLSint64(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_UINT_64__XML_ATTR: { + setLUint64(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_FIXED_64__XML_ATTR: { + setLFixed64(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_SFIXED_64__XML_ATTR: { + setLSfixed64(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_FLOAT__XML_ATTR: { + setLFloat(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> Float.parseFloat(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_DOUBLE__XML_ATTR: { + setLDouble(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> Double.parseDouble(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_STRING__XML_ATTR: { + setLString(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> x).collect(java.util.stream.Collectors.toList())); + break; + } + case L_BYTES__XML_ATTR: { + setLBytes(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> java.util.Base64.getDecoder().decode(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_COLOR__XML_ATTR: { + setLColor(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> test.xmlprimitives.data.Color.valueOfProtocol(x)).collect(java.util.stream.Collectors.toList())); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case L_BOOL__XML_ATTR: { + String text = in.getElementText(); + setLBool(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> Boolean.parseBoolean(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_INT_32__XML_ATTR: { + String text = in.getElementText(); + setLInt32(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> Integer.parseInt(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_SINT_32__XML_ATTR: { + String text = in.getElementText(); + setLSint32(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> Integer.parseInt(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_UINT_32__XML_ATTR: { + String text = in.getElementText(); + setLUint32(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> (int) Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_FIXED_32__XML_ATTR: { + String text = in.getElementText(); + setLFixed32(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> (int) Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_SFIXED_32__XML_ATTR: { + String text = in.getElementText(); + setLSfixed32(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> Integer.parseInt(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_INT_64__XML_ATTR: { + String text = in.getElementText(); + setLInt64(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_SINT_64__XML_ATTR: { + String text = in.getElementText(); + setLSint64(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_UINT_64__XML_ATTR: { + String text = in.getElementText(); + setLUint64(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_FIXED_64__XML_ATTR: { + String text = in.getElementText(); + setLFixed64(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_SFIXED_64__XML_ATTR: { + String text = in.getElementText(); + setLSfixed64(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_FLOAT__XML_ATTR: { + String text = in.getElementText(); + setLFloat(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> Float.parseFloat(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_DOUBLE__XML_ATTR: { + String text = in.getElementText(); + setLDouble(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> Double.parseDouble(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_STRING__XML_ATTR: { + String text = in.getElementText(); + setLString(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> x).collect(java.util.stream.Collectors.toList())); + break; + } + case L_BYTES__XML_ATTR: { + String text = in.getElementText(); + setLBytes(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> java.util.Base64.getDecoder().decode(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case L_COLOR__XML_ATTR: { + String text = in.getElementText(); + setLColor(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> test.xmlprimitives.data.Color.valueOfProtocol(x)).collect(java.util.stream.Collectors.toList())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/impl/Nullables_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/impl/Nullables_Impl.java new file mode 100644 index 00000000..271534b5 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/impl/Nullables_Impl.java @@ -0,0 +1,1549 @@ +package test.xmlprimitives.data.impl; + +/** + * Implementation of {@link test.xmlprimitives.data.Nullables}. + */ +public class Nullables_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.xmlprimitives.data.Nullables { + + private Boolean _nBool = null; + + private Integer _nInt32 = null; + + private Integer _nSint32 = null; + + private Integer _nUint32 = null; + + private Integer _nFixed32 = null; + + private Integer _nSfixed32 = null; + + private Long _nInt64 = null; + + private Long _nSint64 = null; + + private Long _nUint64 = null; + + private Long _nFixed64 = null; + + private Long _nSfixed64 = null; + + private Float _nFloat = null; + + private Double _nDouble = null; + + private String _nString = null; + + private byte[] _nBytes = null; + + private Object _nJson = null; + + private test.xmlprimitives.data.Color _nColor = null; + + private java.util.List _nlInt32 = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, Integer element) { + _listener.beforeAdd(Nullables_Impl.this, NL_INT_32__PROP, index, element); + } + + @Override + protected void afterRemove(int index, Integer element) { + _listener.afterRemove(Nullables_Impl.this, NL_INT_32__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Nullables_Impl.this, NL_INT_32__PROP); + } + }; + + private java.util.List _nlUint32 = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, Integer element) { + _listener.beforeAdd(Nullables_Impl.this, NL_UINT_32__PROP, index, element); + } + + @Override + protected void afterRemove(int index, Integer element) { + _listener.afterRemove(Nullables_Impl.this, NL_UINT_32__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Nullables_Impl.this, NL_UINT_32__PROP); + } + }; + + private java.util.List _nlString = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, String element) { + _listener.beforeAdd(Nullables_Impl.this, NL_STRING__PROP, index, element); + } + + @Override + protected void afterRemove(int index, String element) { + _listener.afterRemove(Nullables_Impl.this, NL_STRING__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Nullables_Impl.this, NL_STRING__PROP); + } + }; + + private java.util.List _nlBytes = new de.haumacher.msgbuf.util.ReferenceList() { + @Override + protected void beforeAdd(int index, byte[] element) { + _listener.beforeAdd(Nullables_Impl.this, NL_BYTES__PROP, index, element); + } + + @Override + protected void afterRemove(int index, byte[] element) { + _listener.afterRemove(Nullables_Impl.this, NL_BYTES__PROP, index, element); + } + + @Override + protected void afterChanged() { + _listener.afterChanged(Nullables_Impl.this, NL_BYTES__PROP); + } + }; + + /** + * Creates a {@link Nullables_Impl} instance. + * + * @see test.xmlprimitives.data.Nullables#create() + */ + public Nullables_Impl() { + super(); + } + + @Override + public final Boolean getNBool() { + return _nBool; + } + + @Override + public test.xmlprimitives.data.Nullables setNBool(Boolean value) { + internalSetNBool(value); + return this; + } + + /** Internal setter for {@link #getNBool()} without chain call utility. */ + protected final void internalSetNBool(Boolean value) { + _listener.beforeSet(this, N_BOOL__PROP, value); + _nBool = value; + _listener.afterChanged(this, N_BOOL__PROP); + } + + @Override + public final boolean hasNBool() { + return _nBool != null; + } + + @Override + public final Integer getNInt32() { + return _nInt32; + } + + @Override + public test.xmlprimitives.data.Nullables setNInt32(Integer value) { + internalSetNInt32(value); + return this; + } + + /** Internal setter for {@link #getNInt32()} without chain call utility. */ + protected final void internalSetNInt32(Integer value) { + _listener.beforeSet(this, N_INT_32__PROP, value); + _nInt32 = value; + _listener.afterChanged(this, N_INT_32__PROP); + } + + @Override + public final boolean hasNInt32() { + return _nInt32 != null; + } + + @Override + public final Integer getNSint32() { + return _nSint32; + } + + @Override + public test.xmlprimitives.data.Nullables setNSint32(Integer value) { + internalSetNSint32(value); + return this; + } + + /** Internal setter for {@link #getNSint32()} without chain call utility. */ + protected final void internalSetNSint32(Integer value) { + _listener.beforeSet(this, N_SINT_32__PROP, value); + _nSint32 = value; + _listener.afterChanged(this, N_SINT_32__PROP); + } + + @Override + public final boolean hasNSint32() { + return _nSint32 != null; + } + + @Override + public final Integer getNUint32() { + return _nUint32; + } + + @Override + public test.xmlprimitives.data.Nullables setNUint32(Integer value) { + internalSetNUint32(value); + return this; + } + + /** Internal setter for {@link #getNUint32()} without chain call utility. */ + protected final void internalSetNUint32(Integer value) { + _listener.beforeSet(this, N_UINT_32__PROP, value); + _nUint32 = value; + _listener.afterChanged(this, N_UINT_32__PROP); + } + + @Override + public final boolean hasNUint32() { + return _nUint32 != null; + } + + @Override + public final Integer getNFixed32() { + return _nFixed32; + } + + @Override + public test.xmlprimitives.data.Nullables setNFixed32(Integer value) { + internalSetNFixed32(value); + return this; + } + + /** Internal setter for {@link #getNFixed32()} without chain call utility. */ + protected final void internalSetNFixed32(Integer value) { + _listener.beforeSet(this, N_FIXED_32__PROP, value); + _nFixed32 = value; + _listener.afterChanged(this, N_FIXED_32__PROP); + } + + @Override + public final boolean hasNFixed32() { + return _nFixed32 != null; + } + + @Override + public final Integer getNSfixed32() { + return _nSfixed32; + } + + @Override + public test.xmlprimitives.data.Nullables setNSfixed32(Integer value) { + internalSetNSfixed32(value); + return this; + } + + /** Internal setter for {@link #getNSfixed32()} without chain call utility. */ + protected final void internalSetNSfixed32(Integer value) { + _listener.beforeSet(this, N_SFIXED_32__PROP, value); + _nSfixed32 = value; + _listener.afterChanged(this, N_SFIXED_32__PROP); + } + + @Override + public final boolean hasNSfixed32() { + return _nSfixed32 != null; + } + + @Override + public final Long getNInt64() { + return _nInt64; + } + + @Override + public test.xmlprimitives.data.Nullables setNInt64(Long value) { + internalSetNInt64(value); + return this; + } + + /** Internal setter for {@link #getNInt64()} without chain call utility. */ + protected final void internalSetNInt64(Long value) { + _listener.beforeSet(this, N_INT_64__PROP, value); + _nInt64 = value; + _listener.afterChanged(this, N_INT_64__PROP); + } + + @Override + public final boolean hasNInt64() { + return _nInt64 != null; + } + + @Override + public final Long getNSint64() { + return _nSint64; + } + + @Override + public test.xmlprimitives.data.Nullables setNSint64(Long value) { + internalSetNSint64(value); + return this; + } + + /** Internal setter for {@link #getNSint64()} without chain call utility. */ + protected final void internalSetNSint64(Long value) { + _listener.beforeSet(this, N_SINT_64__PROP, value); + _nSint64 = value; + _listener.afterChanged(this, N_SINT_64__PROP); + } + + @Override + public final boolean hasNSint64() { + return _nSint64 != null; + } + + @Override + public final Long getNUint64() { + return _nUint64; + } + + @Override + public test.xmlprimitives.data.Nullables setNUint64(Long value) { + internalSetNUint64(value); + return this; + } + + /** Internal setter for {@link #getNUint64()} without chain call utility. */ + protected final void internalSetNUint64(Long value) { + _listener.beforeSet(this, N_UINT_64__PROP, value); + _nUint64 = value; + _listener.afterChanged(this, N_UINT_64__PROP); + } + + @Override + public final boolean hasNUint64() { + return _nUint64 != null; + } + + @Override + public final Long getNFixed64() { + return _nFixed64; + } + + @Override + public test.xmlprimitives.data.Nullables setNFixed64(Long value) { + internalSetNFixed64(value); + return this; + } + + /** Internal setter for {@link #getNFixed64()} without chain call utility. */ + protected final void internalSetNFixed64(Long value) { + _listener.beforeSet(this, N_FIXED_64__PROP, value); + _nFixed64 = value; + _listener.afterChanged(this, N_FIXED_64__PROP); + } + + @Override + public final boolean hasNFixed64() { + return _nFixed64 != null; + } + + @Override + public final Long getNSfixed64() { + return _nSfixed64; + } + + @Override + public test.xmlprimitives.data.Nullables setNSfixed64(Long value) { + internalSetNSfixed64(value); + return this; + } + + /** Internal setter for {@link #getNSfixed64()} without chain call utility. */ + protected final void internalSetNSfixed64(Long value) { + _listener.beforeSet(this, N_SFIXED_64__PROP, value); + _nSfixed64 = value; + _listener.afterChanged(this, N_SFIXED_64__PROP); + } + + @Override + public final boolean hasNSfixed64() { + return _nSfixed64 != null; + } + + @Override + public final Float getNFloat() { + return _nFloat; + } + + @Override + public test.xmlprimitives.data.Nullables setNFloat(Float value) { + internalSetNFloat(value); + return this; + } + + /** Internal setter for {@link #getNFloat()} without chain call utility. */ + protected final void internalSetNFloat(Float value) { + _listener.beforeSet(this, N_FLOAT__PROP, value); + _nFloat = value; + _listener.afterChanged(this, N_FLOAT__PROP); + } + + @Override + public final boolean hasNFloat() { + return _nFloat != null; + } + + @Override + public final Double getNDouble() { + return _nDouble; + } + + @Override + public test.xmlprimitives.data.Nullables setNDouble(Double value) { + internalSetNDouble(value); + return this; + } + + /** Internal setter for {@link #getNDouble()} without chain call utility. */ + protected final void internalSetNDouble(Double value) { + _listener.beforeSet(this, N_DOUBLE__PROP, value); + _nDouble = value; + _listener.afterChanged(this, N_DOUBLE__PROP); + } + + @Override + public final boolean hasNDouble() { + return _nDouble != null; + } + + @Override + public final String getNString() { + return _nString; + } + + @Override + public test.xmlprimitives.data.Nullables setNString(String value) { + internalSetNString(value); + return this; + } + + /** Internal setter for {@link #getNString()} without chain call utility. */ + protected final void internalSetNString(String value) { + _listener.beforeSet(this, N_STRING__PROP, value); + _nString = value; + _listener.afterChanged(this, N_STRING__PROP); + } + + @Override + public final boolean hasNString() { + return _nString != null; + } + + @Override + public final byte[] getNBytes() { + return _nBytes; + } + + @Override + public test.xmlprimitives.data.Nullables setNBytes(byte[] value) { + internalSetNBytes(value); + return this; + } + + /** Internal setter for {@link #getNBytes()} without chain call utility. */ + protected final void internalSetNBytes(byte[] value) { + _listener.beforeSet(this, N_BYTES__PROP, value); + _nBytes = value; + _listener.afterChanged(this, N_BYTES__PROP); + } + + @Override + public final boolean hasNBytes() { + return _nBytes != null; + } + + @Override + public final Object getNJson() { + return _nJson; + } + + @Override + public test.xmlprimitives.data.Nullables setNJson(Object value) { + internalSetNJson(value); + return this; + } + + /** Internal setter for {@link #getNJson()} without chain call utility. */ + protected final void internalSetNJson(Object value) { + _listener.beforeSet(this, N_JSON__PROP, value); + _nJson = value; + _listener.afterChanged(this, N_JSON__PROP); + } + + @Override + public final boolean hasNJson() { + return _nJson != null; + } + + @Override + public final test.xmlprimitives.data.Color getNColor() { + return _nColor; + } + + @Override + public test.xmlprimitives.data.Nullables setNColor(test.xmlprimitives.data.Color value) { + internalSetNColor(value); + return this; + } + + /** Internal setter for {@link #getNColor()} without chain call utility. */ + protected final void internalSetNColor(test.xmlprimitives.data.Color value) { + _listener.beforeSet(this, N_COLOR__PROP, value); + _nColor = value; + _listener.afterChanged(this, N_COLOR__PROP); + } + + @Override + public final boolean hasNColor() { + return _nColor != null; + } + + @Override + public final java.util.List getNlInt32() { + return _nlInt32; + } + + @Override + public test.xmlprimitives.data.Nullables setNlInt32(java.util.List value) { + internalSetNlInt32(value); + return this; + } + + /** Internal setter for {@link #getNlInt32()} without chain call utility. */ + protected final void internalSetNlInt32(java.util.List value) { + if (_nlInt32 == null) _nlInt32 = new java.util.ArrayList<>(); + _nlInt32.clear(); + _nlInt32.addAll(value); + } + + @Override + public test.xmlprimitives.data.Nullables addNlInt32(int value) { + internalAddNlInt32(value); + return this; + } + + /** Implementation of {@link #addNlInt32(int)} without chain call utility. */ + protected final void internalAddNlInt32(int value) { + if (_nlInt32 == null) _nlInt32 = new java.util.ArrayList<>(); + _nlInt32.add(value); + } + + @Override + public final void removeNlInt32(int value) { + if (_nlInt32 == null) _nlInt32 = new java.util.ArrayList<>(); + _nlInt32.remove(value); + } + + @Override + public final boolean hasNlInt32() { + return _nlInt32 != null; + } + + @Override + public final java.util.List getNlUint32() { + return _nlUint32; + } + + @Override + public test.xmlprimitives.data.Nullables setNlUint32(java.util.List value) { + internalSetNlUint32(value); + return this; + } + + /** Internal setter for {@link #getNlUint32()} without chain call utility. */ + protected final void internalSetNlUint32(java.util.List value) { + if (_nlUint32 == null) _nlUint32 = new java.util.ArrayList<>(); + _nlUint32.clear(); + _nlUint32.addAll(value); + } + + @Override + public test.xmlprimitives.data.Nullables addNlUint32(int value) { + internalAddNlUint32(value); + return this; + } + + /** Implementation of {@link #addNlUint32(int)} without chain call utility. */ + protected final void internalAddNlUint32(int value) { + if (_nlUint32 == null) _nlUint32 = new java.util.ArrayList<>(); + _nlUint32.add(value); + } + + @Override + public final void removeNlUint32(int value) { + if (_nlUint32 == null) _nlUint32 = new java.util.ArrayList<>(); + _nlUint32.remove(value); + } + + @Override + public final boolean hasNlUint32() { + return _nlUint32 != null; + } + + @Override + public final java.util.List getNlString() { + return _nlString; + } + + @Override + public test.xmlprimitives.data.Nullables setNlString(java.util.List value) { + internalSetNlString(value); + return this; + } + + /** Internal setter for {@link #getNlString()} without chain call utility. */ + protected final void internalSetNlString(java.util.List value) { + if (_nlString == null) _nlString = new java.util.ArrayList<>(); + _nlString.clear(); + _nlString.addAll(value); + } + + @Override + public test.xmlprimitives.data.Nullables addNlString(String value) { + internalAddNlString(value); + return this; + } + + /** Implementation of {@link #addNlString(String)} without chain call utility. */ + protected final void internalAddNlString(String value) { + if (_nlString == null) _nlString = new java.util.ArrayList<>(); + _nlString.add(value); + } + + @Override + public final void removeNlString(String value) { + if (_nlString == null) _nlString = new java.util.ArrayList<>(); + _nlString.remove(value); + } + + @Override + public final boolean hasNlString() { + return _nlString != null; + } + + @Override + public final java.util.List getNlBytes() { + return _nlBytes; + } + + @Override + public test.xmlprimitives.data.Nullables setNlBytes(java.util.List value) { + internalSetNlBytes(value); + return this; + } + + /** Internal setter for {@link #getNlBytes()} without chain call utility. */ + protected final void internalSetNlBytes(java.util.List value) { + if (_nlBytes == null) _nlBytes = new java.util.ArrayList<>(); + _nlBytes.clear(); + _nlBytes.addAll(value); + } + + @Override + public test.xmlprimitives.data.Nullables addNlByte(byte[] value) { + internalAddNlByte(value); + return this; + } + + /** Implementation of {@link #addNlByte(byte[])} without chain call utility. */ + protected final void internalAddNlByte(byte[] value) { + if (_nlBytes == null) _nlBytes = new java.util.ArrayList<>(); + _nlBytes.add(value); + } + + @Override + public final void removeNlByte(byte[] value) { + if (_nlBytes == null) _nlBytes = new java.util.ArrayList<>(); + _nlBytes.remove(value); + } + + @Override + public final boolean hasNlBytes() { + return _nlBytes != null; + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.xmlprimitives.data.Nullables registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.xmlprimitives.data.Nullables unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return NULLABLES__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + N_BOOL__PROP, + N_INT_32__PROP, + N_SINT_32__PROP, + N_UINT_32__PROP, + N_FIXED_32__PROP, + N_SFIXED_32__PROP, + N_INT_64__PROP, + N_SINT_64__PROP, + N_UINT_64__PROP, + N_FIXED_64__PROP, + N_SFIXED_64__PROP, + N_FLOAT__PROP, + N_DOUBLE__PROP, + N_STRING__PROP, + N_BYTES__PROP, + N_JSON__PROP, + N_COLOR__PROP, + NL_INT_32__PROP, + NL_UINT_32__PROP, + NL_STRING__PROP, + NL_BYTES__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case N_BOOL__PROP: return getNBool(); + case N_INT_32__PROP: return getNInt32(); + case N_SINT_32__PROP: return getNSint32(); + case N_UINT_32__PROP: return getNUint32(); + case N_FIXED_32__PROP: return getNFixed32(); + case N_SFIXED_32__PROP: return getNSfixed32(); + case N_INT_64__PROP: return getNInt64(); + case N_SINT_64__PROP: return getNSint64(); + case N_UINT_64__PROP: return getNUint64(); + case N_FIXED_64__PROP: return getNFixed64(); + case N_SFIXED_64__PROP: return getNSfixed64(); + case N_FLOAT__PROP: return getNFloat(); + case N_DOUBLE__PROP: return getNDouble(); + case N_STRING__PROP: return getNString(); + case N_BYTES__PROP: return getNBytes(); + case N_JSON__PROP: return getNJson(); + case N_COLOR__PROP: return getNColor(); + case NL_INT_32__PROP: return getNlInt32(); + case NL_UINT_32__PROP: return getNlUint32(); + case NL_STRING__PROP: return getNlString(); + case NL_BYTES__PROP: return getNlBytes(); + default: return test.xmlprimitives.data.Nullables.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case N_BOOL__PROP: internalSetNBool((Boolean) value); break; + case N_INT_32__PROP: internalSetNInt32((Integer) value); break; + case N_SINT_32__PROP: internalSetNSint32((Integer) value); break; + case N_UINT_32__PROP: internalSetNUint32((Integer) value); break; + case N_FIXED_32__PROP: internalSetNFixed32((Integer) value); break; + case N_SFIXED_32__PROP: internalSetNSfixed32((Integer) value); break; + case N_INT_64__PROP: internalSetNInt64((Long) value); break; + case N_SINT_64__PROP: internalSetNSint64((Long) value); break; + case N_UINT_64__PROP: internalSetNUint64((Long) value); break; + case N_FIXED_64__PROP: internalSetNFixed64((Long) value); break; + case N_SFIXED_64__PROP: internalSetNSfixed64((Long) value); break; + case N_FLOAT__PROP: internalSetNFloat((Float) value); break; + case N_DOUBLE__PROP: internalSetNDouble((Double) value); break; + case N_STRING__PROP: internalSetNString((String) value); break; + case N_BYTES__PROP: internalSetNBytes((byte[]) value); break; + case N_JSON__PROP: internalSetNJson((Object) value); break; + case N_COLOR__PROP: internalSetNColor((test.xmlprimitives.data.Color) value); break; + case NL_INT_32__PROP: internalSetNlInt32(de.haumacher.msgbuf.util.Conversions.asList(Integer.class, value)); break; + case NL_UINT_32__PROP: internalSetNlUint32(de.haumacher.msgbuf.util.Conversions.asList(Integer.class, value)); break; + case NL_STRING__PROP: internalSetNlString(de.haumacher.msgbuf.util.Conversions.asList(String.class, value)); break; + case NL_BYTES__PROP: internalSetNlBytes(de.haumacher.msgbuf.util.Conversions.asList(byte[].class, value)); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + if (hasNBool()) { + out.name(N_BOOL__PROP); + out.value(getNBool()); + } + if (hasNInt32()) { + out.name(N_INT_32__PROP); + out.value(getNInt32()); + } + if (hasNSint32()) { + out.name(N_SINT_32__PROP); + out.value(getNSint32()); + } + if (hasNUint32()) { + out.name(N_UINT_32__PROP); + out.value(getNUint32()); + } + if (hasNFixed32()) { + out.name(N_FIXED_32__PROP); + out.value(getNFixed32()); + } + if (hasNSfixed32()) { + out.name(N_SFIXED_32__PROP); + out.value(getNSfixed32()); + } + if (hasNInt64()) { + out.name(N_INT_64__PROP); + out.value(getNInt64()); + } + if (hasNSint64()) { + out.name(N_SINT_64__PROP); + out.value(getNSint64()); + } + if (hasNUint64()) { + out.name(N_UINT_64__PROP); + out.value(getNUint64()); + } + if (hasNFixed64()) { + out.name(N_FIXED_64__PROP); + out.value(getNFixed64()); + } + if (hasNSfixed64()) { + out.name(N_SFIXED_64__PROP); + out.value(getNSfixed64()); + } + if (hasNFloat()) { + out.name(N_FLOAT__PROP); + out.value(getNFloat()); + } + if (hasNDouble()) { + out.name(N_DOUBLE__PROP); + out.value(getNDouble()); + } + if (hasNString()) { + out.name(N_STRING__PROP); + out.value(getNString()); + } + if (hasNBytes()) { + out.name(N_BYTES__PROP); + de.haumacher.msgbuf.json.JsonUtil.writeBinaryOptional(out, getNBytes()); + } + if (hasNJson()) { + out.name(N_JSON__PROP); + de.haumacher.msgbuf.json.JsonUtil.writeJsonValue(out, getNJson()); + } + if (hasNColor()) { + out.name(N_COLOR__PROP); + getNColor().writeTo(out); + } + if (hasNlInt32()) { + out.name(NL_INT_32__PROP); + out.beginArray(); + for (int x : getNlInt32()) { + out.value(x); + } + out.endArray(); + } + if (hasNlUint32()) { + out.name(NL_UINT_32__PROP); + out.beginArray(); + for (int x : getNlUint32()) { + out.value(x); + } + out.endArray(); + } + if (hasNlString()) { + out.name(NL_STRING__PROP); + out.beginArray(); + for (String x : getNlString()) { + out.value(x); + } + out.endArray(); + } + if (hasNlBytes()) { + out.name(NL_BYTES__PROP); + out.beginArray(); + for (byte[] x : getNlBytes()) { + de.haumacher.msgbuf.json.JsonUtil.writeBinaryOptional(out, x); + } + out.endArray(); + } + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case N_BOOL__PROP: setNBool(in.nextBoolean()); break; + case N_INT_32__PROP: setNInt32(in.nextInt()); break; + case N_SINT_32__PROP: setNSint32(in.nextInt()); break; + case N_UINT_32__PROP: setNUint32(in.nextInt()); break; + case N_FIXED_32__PROP: setNFixed32(in.nextInt()); break; + case N_SFIXED_32__PROP: setNSfixed32(in.nextInt()); break; + case N_INT_64__PROP: setNInt64(in.nextLong()); break; + case N_SINT_64__PROP: setNSint64(in.nextLong()); break; + case N_UINT_64__PROP: setNUint64(in.nextLong()); break; + case N_FIXED_64__PROP: setNFixed64(in.nextLong()); break; + case N_SFIXED_64__PROP: setNSfixed64(in.nextLong()); break; + case N_FLOAT__PROP: setNFloat((float) in.nextDouble()); break; + case N_DOUBLE__PROP: setNDouble(in.nextDouble()); break; + case N_STRING__PROP: setNString(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case N_BYTES__PROP: setNBytes(de.haumacher.msgbuf.json.JsonUtil.nextBinaryOptional(in)); break; + case N_JSON__PROP: setNJson(de.haumacher.msgbuf.json.JsonUtil.nextJsonValue(in)); break; + case N_COLOR__PROP: setNColor(test.xmlprimitives.data.Color.readColor(in)); break; + case NL_INT_32__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(in.nextInt()); + } + in.endArray(); + setNlInt32(newValue); + } + break; + case NL_UINT_32__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(in.nextInt()); + } + in.endArray(); + setNlUint32(newValue); + } + break; + case NL_STRING__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); + } + in.endArray(); + setNlString(newValue); + } + break; + case NL_BYTES__PROP: { + java.util.List newValue = new java.util.ArrayList<>(); + in.beginArray(); + while (in.hasNext()) { + newValue.add(de.haumacher.msgbuf.json.JsonUtil.nextBinaryOptional(in)); + } + in.endArray(); + setNlBytes(newValue); + } + break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + if (hasNBool()) { + out.name(N_BOOL__ID); + out.value(getNBool()); + } + if (hasNInt32()) { + out.name(N_INT_32__ID); + out.value(getNInt32()); + } + if (hasNSint32()) { + out.name(N_SINT_32__ID); + out.valueSigned(getNSint32()); + } + if (hasNUint32()) { + out.name(N_UINT_32__ID); + out.value(getNUint32()); + } + if (hasNFixed32()) { + out.name(N_FIXED_32__ID); + out.valueFixed(getNFixed32()); + } + if (hasNSfixed32()) { + out.name(N_SFIXED_32__ID); + out.valueFixed(getNSfixed32()); + } + if (hasNInt64()) { + out.name(N_INT_64__ID); + out.value(getNInt64()); + } + if (hasNSint64()) { + out.name(N_SINT_64__ID); + out.valueSigned(getNSint64()); + } + if (hasNUint64()) { + out.name(N_UINT_64__ID); + out.value(getNUint64()); + } + if (hasNFixed64()) { + out.name(N_FIXED_64__ID); + out.valueFixed(getNFixed64()); + } + if (hasNSfixed64()) { + out.name(N_SFIXED_64__ID); + out.valueFixed(getNSfixed64()); + } + if (hasNFloat()) { + out.name(N_FLOAT__ID); + out.value(getNFloat()); + } + if (hasNDouble()) { + out.name(N_DOUBLE__ID); + out.value(getNDouble()); + } + if (hasNString()) { + out.name(N_STRING__ID); + out.value(getNString()); + } + if (hasNBytes()) { + out.name(N_BYTES__ID); + out.value(getNBytes()); + } + if (hasNJson()) { + out.name(N_JSON__ID); + de.haumacher.msgbuf.json.JsonUtil.toJsonValue(getNJson()).writeTo(out); + } + if (hasNColor()) { + out.name(N_COLOR__ID); + getNColor().writeTo(out); + } + if (hasNlInt32()) { + out.name(NL_INT_32__ID); + { + java.util.List values = getNlInt32(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.INT, values.size()); + for (int x : values) { + out.value(x); + } + out.endArray(); + } + } + if (hasNlUint32()) { + out.name(NL_UINT_32__ID); + { + java.util.List values = getNlUint32(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.INT, values.size()); + for (int x : values) { + out.value(x); + } + out.endArray(); + } + } + if (hasNlString()) { + out.name(NL_STRING__ID); + { + java.util.List values = getNlString(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.STRING, values.size()); + for (String x : values) { + out.value(x); + } + out.endArray(); + } + } + if (hasNlBytes()) { + out.name(NL_BYTES__ID); + { + java.util.List values = getNlBytes(); + out.beginArray(de.haumacher.msgbuf.binary.DataType.BINARY, values.size()); + for (byte[] x : values) { + out.value(x); + } + out.endArray(); + } + } + } + + /** Helper for creating an object of type {@link test.xmlprimitives.data.Nullables} from a polymorphic composition. */ + public static test.xmlprimitives.data.Nullables readNullables_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.xmlprimitives.data.impl.Nullables_Impl result = new Nullables_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case N_BOOL__ID: setNBool(in.nextBoolean()); break; + case N_INT_32__ID: setNInt32(in.nextInt()); break; + case N_SINT_32__ID: setNSint32(in.nextIntSigned()); break; + case N_UINT_32__ID: setNUint32(in.nextInt()); break; + case N_FIXED_32__ID: setNFixed32(in.nextIntFixed()); break; + case N_SFIXED_32__ID: setNSfixed32(in.nextIntFixed()); break; + case N_INT_64__ID: setNInt64(in.nextLong()); break; + case N_SINT_64__ID: setNSint64(in.nextLongSigned()); break; + case N_UINT_64__ID: setNUint64(in.nextLong()); break; + case N_FIXED_64__ID: setNFixed64(in.nextLongFixed()); break; + case N_SFIXED_64__ID: setNSfixed64(in.nextLongFixed()); break; + case N_FLOAT__ID: setNFloat(in.nextFloat()); break; + case N_DOUBLE__ID: setNDouble(in.nextDouble()); break; + case N_STRING__ID: setNString(in.nextString()); break; + case N_BYTES__ID: setNBytes(in.nextBinary()); break; + case N_JSON__ID: setNJson(de.haumacher.msgbuf.json.JsonUtil.fromJsonValue(de.haumacher.msgbuf.json.value.JsonValue.readJsonValue(in))); break; + case N_COLOR__ID: setNColor(test.xmlprimitives.data.Color.readColor(in)); break; + case NL_INT_32__ID: { + in.beginArray(); + while (in.hasNext()) { + addNlInt32(in.nextInt()); + } + in.endArray(); + } + break; + case NL_UINT_32__ID: { + in.beginArray(); + while (in.hasNext()) { + addNlUint32(in.nextInt()); + } + in.endArray(); + } + break; + case NL_STRING__ID: { + in.beginArray(); + while (in.hasNext()) { + addNlString(in.nextString()); + } + in.endArray(); + } + break; + case NL_BYTES__ID: { + in.beginArray(); + while (in.hasNext()) { + addNlByte(in.nextBinary()); + } + in.endArray(); + } + break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.xmlprimitives.data.Nullables} type. */ + public static final String NULLABLES__XML_ELEMENT = "nullables"; + + /** XML attribute or element name of a {@link #getNBool} property. */ + private static final String N_BOOL__XML_ATTR = "n-bool"; + + /** XML attribute or element name of a {@link #getNInt32} property. */ + private static final String N_INT_32__XML_ATTR = "n-int-32"; + + /** XML attribute or element name of a {@link #getNSint32} property. */ + private static final String N_SINT_32__XML_ATTR = "n-sint-32"; + + /** XML attribute or element name of a {@link #getNUint32} property. */ + private static final String N_UINT_32__XML_ATTR = "n-uint-32"; + + /** XML attribute or element name of a {@link #getNFixed32} property. */ + private static final String N_FIXED_32__XML_ATTR = "n-fixed-32"; + + /** XML attribute or element name of a {@link #getNSfixed32} property. */ + private static final String N_SFIXED_32__XML_ATTR = "n-sfixed-32"; + + /** XML attribute or element name of a {@link #getNInt64} property. */ + private static final String N_INT_64__XML_ATTR = "n-int-64"; + + /** XML attribute or element name of a {@link #getNSint64} property. */ + private static final String N_SINT_64__XML_ATTR = "n-sint-64"; + + /** XML attribute or element name of a {@link #getNUint64} property. */ + private static final String N_UINT_64__XML_ATTR = "n-uint-64"; + + /** XML attribute or element name of a {@link #getNFixed64} property. */ + private static final String N_FIXED_64__XML_ATTR = "n-fixed-64"; + + /** XML attribute or element name of a {@link #getNSfixed64} property. */ + private static final String N_SFIXED_64__XML_ATTR = "n-sfixed-64"; + + /** XML attribute or element name of a {@link #getNFloat} property. */ + private static final String N_FLOAT__XML_ATTR = "n-float"; + + /** XML attribute or element name of a {@link #getNDouble} property. */ + private static final String N_DOUBLE__XML_ATTR = "n-double"; + + /** XML attribute or element name of a {@link #getNString} property. */ + private static final String N_STRING__XML_ATTR = "n-string"; + + /** XML attribute or element name of a {@link #getNBytes} property. */ + private static final String N_BYTES__XML_ATTR = "n-bytes"; + + /** XML attribute or element name of a {@link #getNJson} property. */ + private static final String N_JSON__XML_ATTR = "n-json"; + + /** XML attribute or element name of a {@link #getNColor} property. */ + private static final String N_COLOR__XML_ATTR = "n-color"; + + /** XML attribute or element name of a {@link #getNlInt32} property. */ + private static final String NL_INT_32__XML_ATTR = "nl-int-32"; + + /** XML attribute or element name of a {@link #getNlUint32} property. */ + private static final String NL_UINT_32__XML_ATTR = "nl-uint-32"; + + /** XML attribute or element name of a {@link #getNlString} property. */ + private static final String NL_STRING__XML_ATTR = "nl-string"; + + /** XML attribute or element name of a {@link #getNlBytes} property. */ + private static final String NL_BYTES__XML_ATTR = "nl-bytes"; + + @Override + public String getXmlTagName() { + return NULLABLES__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + if (hasNBool()) { + out.writeAttribute(N_BOOL__XML_ATTR, Boolean.toString(getNBool())); + } + if (hasNInt32()) { + out.writeAttribute(N_INT_32__XML_ATTR, Integer.toString(getNInt32())); + } + if (hasNSint32()) { + out.writeAttribute(N_SINT_32__XML_ATTR, Integer.toString(getNSint32())); + } + if (hasNUint32()) { + out.writeAttribute(N_UINT_32__XML_ATTR, Long.toString(Integer.toUnsignedLong(getNUint32()))); + } + if (hasNFixed32()) { + out.writeAttribute(N_FIXED_32__XML_ATTR, Long.toString(Integer.toUnsignedLong(getNFixed32()))); + } + if (hasNSfixed32()) { + out.writeAttribute(N_SFIXED_32__XML_ATTR, Integer.toString(getNSfixed32())); + } + if (hasNInt64()) { + out.writeAttribute(N_INT_64__XML_ATTR, Long.toString(getNInt64())); + } + if (hasNSint64()) { + out.writeAttribute(N_SINT_64__XML_ATTR, Long.toString(getNSint64())); + } + if (hasNUint64()) { + out.writeAttribute(N_UINT_64__XML_ATTR, Long.toString(getNUint64())); + } + if (hasNFixed64()) { + out.writeAttribute(N_FIXED_64__XML_ATTR, Long.toString(getNFixed64())); + } + if (hasNSfixed64()) { + out.writeAttribute(N_SFIXED_64__XML_ATTR, Long.toString(getNSfixed64())); + } + if (hasNFloat()) { + out.writeAttribute(N_FLOAT__XML_ATTR, Float.toString(getNFloat())); + } + if (hasNDouble()) { + out.writeAttribute(N_DOUBLE__XML_ATTR, Double.toString(getNDouble())); + } + if (hasNString()) { + out.writeAttribute(N_STRING__XML_ATTR, getNString()); + } + if (hasNBytes()) { + out.writeAttribute(N_BYTES__XML_ATTR, java.util.Base64.getEncoder().encodeToString(getNBytes())); + } + out.writeAttribute(N_JSON__XML_ATTR, de.haumacher.msgbuf.json.JsonUtil.jsonStringValue(getNJson())); + if (hasNColor()) { + out.writeAttribute(N_COLOR__XML_ATTR, getNColor().protocolName()); + } + if (hasNlInt32()) { + out.writeAttribute(NL_INT_32__XML_ATTR, getNlInt32().stream().map(x -> Integer.toString(x)).collect(java.util.stream.Collectors.joining(", "))); + } + if (hasNlUint32()) { + out.writeAttribute(NL_UINT_32__XML_ATTR, getNlUint32().stream().map(x -> Long.toString(Integer.toUnsignedLong(x))).collect(java.util.stream.Collectors.joining(", "))); + } + if (hasNlString()) { + out.writeAttribute(NL_STRING__XML_ATTR, getNlString().stream().map(x -> x).collect(java.util.stream.Collectors.joining(", "))); + } + if (hasNlBytes()) { + out.writeAttribute(NL_BYTES__XML_ATTR, getNlBytes().stream().map(x -> java.util.Base64.getEncoder().encodeToString(x)).collect(java.util.stream.Collectors.joining(", "))); + } + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.xmlprimitives.data.Nullables} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Nullables_Impl readNullables_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Nullables_Impl result = new Nullables_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case N_BOOL__XML_ATTR: { + setNBool(Boolean.parseBoolean(value)); + break; + } + case N_INT_32__XML_ATTR: { + setNInt32(Integer.parseInt(value)); + break; + } + case N_SINT_32__XML_ATTR: { + setNSint32(Integer.parseInt(value)); + break; + } + case N_UINT_32__XML_ATTR: { + setNUint32((int) Long.parseLong(value)); + break; + } + case N_FIXED_32__XML_ATTR: { + setNFixed32((int) Long.parseLong(value)); + break; + } + case N_SFIXED_32__XML_ATTR: { + setNSfixed32(Integer.parseInt(value)); + break; + } + case N_INT_64__XML_ATTR: { + setNInt64(Long.parseLong(value)); + break; + } + case N_SINT_64__XML_ATTR: { + setNSint64(Long.parseLong(value)); + break; + } + case N_UINT_64__XML_ATTR: { + setNUint64(Long.parseLong(value)); + break; + } + case N_FIXED_64__XML_ATTR: { + setNFixed64(Long.parseLong(value)); + break; + } + case N_SFIXED_64__XML_ATTR: { + setNSfixed64(Long.parseLong(value)); + break; + } + case N_FLOAT__XML_ATTR: { + setNFloat(Float.parseFloat(value)); + break; + } + case N_DOUBLE__XML_ATTR: { + setNDouble(Double.parseDouble(value)); + break; + } + case N_STRING__XML_ATTR: { + setNString(value); + break; + } + case N_BYTES__XML_ATTR: { + setNBytes(java.util.Base64.getDecoder().decode(value)); + break; + } + case N_JSON__XML_ATTR: { + setNJson(de.haumacher.msgbuf.json.JsonUtil.parseJsonValue(value)); + break; + } + case N_COLOR__XML_ATTR: { + setNColor(test.xmlprimitives.data.Color.valueOfProtocol(value)); + break; + } + case NL_INT_32__XML_ATTR: { + setNlInt32(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> Integer.parseInt(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case NL_UINT_32__XML_ATTR: { + setNlUint32(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> (int) Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case NL_STRING__XML_ATTR: { + setNlString(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> x).collect(java.util.stream.Collectors.toList())); + break; + } + case NL_BYTES__XML_ATTR: { + setNlBytes(java.util.Arrays.stream(value.isEmpty() ? new String[0] : value.split("\\s*,\\s*")).map(x -> java.util.Base64.getDecoder().decode(x)).collect(java.util.stream.Collectors.toList())); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case N_BOOL__XML_ATTR: { + setNBool(Boolean.parseBoolean(in.getElementText())); + break; + } + case N_INT_32__XML_ATTR: { + setNInt32(Integer.parseInt(in.getElementText())); + break; + } + case N_SINT_32__XML_ATTR: { + setNSint32(Integer.parseInt(in.getElementText())); + break; + } + case N_UINT_32__XML_ATTR: { + setNUint32((int) Long.parseLong(in.getElementText())); + break; + } + case N_FIXED_32__XML_ATTR: { + setNFixed32((int) Long.parseLong(in.getElementText())); + break; + } + case N_SFIXED_32__XML_ATTR: { + setNSfixed32(Integer.parseInt(in.getElementText())); + break; + } + case N_INT_64__XML_ATTR: { + setNInt64(Long.parseLong(in.getElementText())); + break; + } + case N_SINT_64__XML_ATTR: { + setNSint64(Long.parseLong(in.getElementText())); + break; + } + case N_UINT_64__XML_ATTR: { + setNUint64(Long.parseLong(in.getElementText())); + break; + } + case N_FIXED_64__XML_ATTR: { + setNFixed64(Long.parseLong(in.getElementText())); + break; + } + case N_SFIXED_64__XML_ATTR: { + setNSfixed64(Long.parseLong(in.getElementText())); + break; + } + case N_FLOAT__XML_ATTR: { + setNFloat(Float.parseFloat(in.getElementText())); + break; + } + case N_DOUBLE__XML_ATTR: { + setNDouble(Double.parseDouble(in.getElementText())); + break; + } + case N_STRING__XML_ATTR: { + setNString(in.getElementText()); + break; + } + case N_BYTES__XML_ATTR: { + setNBytes(java.util.Base64.getDecoder().decode(in.getElementText())); + break; + } + case N_JSON__XML_ATTR: { + setNJson(de.haumacher.msgbuf.json.JsonUtil.parseJsonValue(in.getElementText())); + break; + } + case N_COLOR__XML_ATTR: { + setNColor(test.xmlprimitives.data.Color.valueOfProtocol(in.getElementText())); + break; + } + case NL_INT_32__XML_ATTR: { + String text = in.getElementText(); + setNlInt32(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> Integer.parseInt(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case NL_UINT_32__XML_ATTR: { + String text = in.getElementText(); + setNlUint32(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> (int) Long.parseLong(x)).collect(java.util.stream.Collectors.toList())); + break; + } + case NL_STRING__XML_ATTR: { + String text = in.getElementText(); + setNlString(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> x).collect(java.util.stream.Collectors.toList())); + break; + } + case NL_BYTES__XML_ATTR: { + String text = in.getElementText(); + setNlBytes(java.util.Arrays.stream(text.isEmpty() ? new String[0] : text.split("\\s*,\\s*")).map(x -> java.util.Base64.getDecoder().decode(x)).collect(java.util.stream.Collectors.toList())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/impl/Values_Impl.java b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/impl/Values_Impl.java new file mode 100644 index 00000000..833d3f9d --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/data/impl/Values_Impl.java @@ -0,0 +1,926 @@ +package test.xmlprimitives.data.impl; + +/** + * Implementation of {@link test.xmlprimitives.data.Values}. + */ +public class Values_Impl extends de.haumacher.msgbuf.data.AbstractDataObject implements test.xmlprimitives.data.Values { + + private boolean _vBool = false; + + private int _vInt32 = 0; + + private int _vSint32 = 0; + + private int _vUint32 = 0; + + private int _vFixed32 = 0; + + private int _vSfixed32 = 0; + + private long _vInt64 = 0L; + + private long _vSint64 = 0L; + + private long _vUint64 = 0L; + + private long _vFixed64 = 0L; + + private long _vSfixed64 = 0L; + + private float _vFloat = 0.0f; + + private double _vDouble = 0.0d; + + private String _vString = ""; + + private byte[] _vBytes = null; + + private Object _vJson = null; + + private test.xmlprimitives.data.Color _vColor = test.xmlprimitives.data.Color.RED; + + /** + * Creates a {@link Values_Impl} instance. + * + * @see test.xmlprimitives.data.Values#create() + */ + public Values_Impl() { + super(); + } + + @Override + public final boolean isVBool() { + return _vBool; + } + + @Override + public test.xmlprimitives.data.Values setVBool(boolean value) { + internalSetVBool(value); + return this; + } + + /** Internal setter for {@link #isVBool()} without chain call utility. */ + protected final void internalSetVBool(boolean value) { + _listener.beforeSet(this, V_BOOL__PROP, value); + _vBool = value; + _listener.afterChanged(this, V_BOOL__PROP); + } + + @Override + public final int getVInt32() { + return _vInt32; + } + + @Override + public test.xmlprimitives.data.Values setVInt32(int value) { + internalSetVInt32(value); + return this; + } + + /** Internal setter for {@link #getVInt32()} without chain call utility. */ + protected final void internalSetVInt32(int value) { + _listener.beforeSet(this, V_INT_32__PROP, value); + _vInt32 = value; + _listener.afterChanged(this, V_INT_32__PROP); + } + + @Override + public final int getVSint32() { + return _vSint32; + } + + @Override + public test.xmlprimitives.data.Values setVSint32(int value) { + internalSetVSint32(value); + return this; + } + + /** Internal setter for {@link #getVSint32()} without chain call utility. */ + protected final void internalSetVSint32(int value) { + _listener.beforeSet(this, V_SINT_32__PROP, value); + _vSint32 = value; + _listener.afterChanged(this, V_SINT_32__PROP); + } + + @Override + public final int getVUint32() { + return _vUint32; + } + + @Override + public test.xmlprimitives.data.Values setVUint32(int value) { + internalSetVUint32(value); + return this; + } + + /** Internal setter for {@link #getVUint32()} without chain call utility. */ + protected final void internalSetVUint32(int value) { + _listener.beforeSet(this, V_UINT_32__PROP, value); + _vUint32 = value; + _listener.afterChanged(this, V_UINT_32__PROP); + } + + @Override + public final int getVFixed32() { + return _vFixed32; + } + + @Override + public test.xmlprimitives.data.Values setVFixed32(int value) { + internalSetVFixed32(value); + return this; + } + + /** Internal setter for {@link #getVFixed32()} without chain call utility. */ + protected final void internalSetVFixed32(int value) { + _listener.beforeSet(this, V_FIXED_32__PROP, value); + _vFixed32 = value; + _listener.afterChanged(this, V_FIXED_32__PROP); + } + + @Override + public final int getVSfixed32() { + return _vSfixed32; + } + + @Override + public test.xmlprimitives.data.Values setVSfixed32(int value) { + internalSetVSfixed32(value); + return this; + } + + /** Internal setter for {@link #getVSfixed32()} without chain call utility. */ + protected final void internalSetVSfixed32(int value) { + _listener.beforeSet(this, V_SFIXED_32__PROP, value); + _vSfixed32 = value; + _listener.afterChanged(this, V_SFIXED_32__PROP); + } + + @Override + public final long getVInt64() { + return _vInt64; + } + + @Override + public test.xmlprimitives.data.Values setVInt64(long value) { + internalSetVInt64(value); + return this; + } + + /** Internal setter for {@link #getVInt64()} without chain call utility. */ + protected final void internalSetVInt64(long value) { + _listener.beforeSet(this, V_INT_64__PROP, value); + _vInt64 = value; + _listener.afterChanged(this, V_INT_64__PROP); + } + + @Override + public final long getVSint64() { + return _vSint64; + } + + @Override + public test.xmlprimitives.data.Values setVSint64(long value) { + internalSetVSint64(value); + return this; + } + + /** Internal setter for {@link #getVSint64()} without chain call utility. */ + protected final void internalSetVSint64(long value) { + _listener.beforeSet(this, V_SINT_64__PROP, value); + _vSint64 = value; + _listener.afterChanged(this, V_SINT_64__PROP); + } + + @Override + public final long getVUint64() { + return _vUint64; + } + + @Override + public test.xmlprimitives.data.Values setVUint64(long value) { + internalSetVUint64(value); + return this; + } + + /** Internal setter for {@link #getVUint64()} without chain call utility. */ + protected final void internalSetVUint64(long value) { + _listener.beforeSet(this, V_UINT_64__PROP, value); + _vUint64 = value; + _listener.afterChanged(this, V_UINT_64__PROP); + } + + @Override + public final long getVFixed64() { + return _vFixed64; + } + + @Override + public test.xmlprimitives.data.Values setVFixed64(long value) { + internalSetVFixed64(value); + return this; + } + + /** Internal setter for {@link #getVFixed64()} without chain call utility. */ + protected final void internalSetVFixed64(long value) { + _listener.beforeSet(this, V_FIXED_64__PROP, value); + _vFixed64 = value; + _listener.afterChanged(this, V_FIXED_64__PROP); + } + + @Override + public final long getVSfixed64() { + return _vSfixed64; + } + + @Override + public test.xmlprimitives.data.Values setVSfixed64(long value) { + internalSetVSfixed64(value); + return this; + } + + /** Internal setter for {@link #getVSfixed64()} without chain call utility. */ + protected final void internalSetVSfixed64(long value) { + _listener.beforeSet(this, V_SFIXED_64__PROP, value); + _vSfixed64 = value; + _listener.afterChanged(this, V_SFIXED_64__PROP); + } + + @Override + public final float getVFloat() { + return _vFloat; + } + + @Override + public test.xmlprimitives.data.Values setVFloat(float value) { + internalSetVFloat(value); + return this; + } + + /** Internal setter for {@link #getVFloat()} without chain call utility. */ + protected final void internalSetVFloat(float value) { + _listener.beforeSet(this, V_FLOAT__PROP, value); + _vFloat = value; + _listener.afterChanged(this, V_FLOAT__PROP); + } + + @Override + public final double getVDouble() { + return _vDouble; + } + + @Override + public test.xmlprimitives.data.Values setVDouble(double value) { + internalSetVDouble(value); + return this; + } + + /** Internal setter for {@link #getVDouble()} without chain call utility. */ + protected final void internalSetVDouble(double value) { + _listener.beforeSet(this, V_DOUBLE__PROP, value); + _vDouble = value; + _listener.afterChanged(this, V_DOUBLE__PROP); + } + + @Override + public final String getVString() { + return _vString; + } + + @Override + public test.xmlprimitives.data.Values setVString(String value) { + internalSetVString(value); + return this; + } + + /** Internal setter for {@link #getVString()} without chain call utility. */ + protected final void internalSetVString(String value) { + _listener.beforeSet(this, V_STRING__PROP, value); + _vString = value; + _listener.afterChanged(this, V_STRING__PROP); + } + + @Override + public final byte[] getVBytes() { + return _vBytes; + } + + @Override + public test.xmlprimitives.data.Values setVBytes(byte[] value) { + internalSetVBytes(value); + return this; + } + + /** Internal setter for {@link #getVBytes()} without chain call utility. */ + protected final void internalSetVBytes(byte[] value) { + _listener.beforeSet(this, V_BYTES__PROP, value); + _vBytes = value; + _listener.afterChanged(this, V_BYTES__PROP); + } + + @Override + public final Object getVJson() { + return _vJson; + } + + @Override + public test.xmlprimitives.data.Values setVJson(Object value) { + internalSetVJson(value); + return this; + } + + /** Internal setter for {@link #getVJson()} without chain call utility. */ + protected final void internalSetVJson(Object value) { + _listener.beforeSet(this, V_JSON__PROP, value); + _vJson = value; + _listener.afterChanged(this, V_JSON__PROP); + } + + @Override + public final boolean hasVJson() { + return _vJson != null; + } + + @Override + public final test.xmlprimitives.data.Color getVColor() { + return _vColor; + } + + @Override + public test.xmlprimitives.data.Values setVColor(test.xmlprimitives.data.Color value) { + internalSetVColor(value); + return this; + } + + /** Internal setter for {@link #getVColor()} without chain call utility. */ + protected final void internalSetVColor(test.xmlprimitives.data.Color value) { + if (value == null) throw new IllegalArgumentException("Property 'vColor' cannot be null."); + _listener.beforeSet(this, V_COLOR__PROP, value); + _vColor = value; + _listener.afterChanged(this, V_COLOR__PROP); + } + + protected de.haumacher.msgbuf.observer.Listener _listener = de.haumacher.msgbuf.observer.Listener.NONE; + + @Override + public test.xmlprimitives.data.Values registerListener(de.haumacher.msgbuf.observer.Listener l) { + internalRegisterListener(l); + return this; + } + + protected final void internalRegisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.register(_listener, l); + } + + @Override + public test.xmlprimitives.data.Values unregisterListener(de.haumacher.msgbuf.observer.Listener l) { + internalUnregisterListener(l); + return this; + } + + protected final void internalUnregisterListener(de.haumacher.msgbuf.observer.Listener l) { + _listener = de.haumacher.msgbuf.observer.Listener.unregister(_listener, l); + } + + @Override + public String jsonType() { + return VALUES__TYPE; + } + + static final java.util.List PROPERTIES; + static { + java.util.List local = java.util.Arrays.asList( + V_BOOL__PROP, + V_INT_32__PROP, + V_SINT_32__PROP, + V_UINT_32__PROP, + V_FIXED_32__PROP, + V_SFIXED_32__PROP, + V_INT_64__PROP, + V_SINT_64__PROP, + V_UINT_64__PROP, + V_FIXED_64__PROP, + V_SFIXED_64__PROP, + V_FLOAT__PROP, + V_DOUBLE__PROP, + V_STRING__PROP, + V_BYTES__PROP, + V_JSON__PROP, + V_COLOR__PROP); + PROPERTIES = java.util.Collections.unmodifiableList(local); + } + + static final java.util.Set TRANSIENT_PROPERTIES; + static { + java.util.HashSet tmp = new java.util.HashSet<>(); + tmp.addAll(java.util.Arrays.asList( + )); + TRANSIENT_PROPERTIES = java.util.Collections.unmodifiableSet(tmp); + } + + @Override + public java.util.List properties() { + return PROPERTIES; + } + + @Override + public java.util.Set transientProperties() { + return TRANSIENT_PROPERTIES; + } + + @Override + public Object get(String field) { + switch (field) { + case V_BOOL__PROP: return isVBool(); + case V_INT_32__PROP: return getVInt32(); + case V_SINT_32__PROP: return getVSint32(); + case V_UINT_32__PROP: return getVUint32(); + case V_FIXED_32__PROP: return getVFixed32(); + case V_SFIXED_32__PROP: return getVSfixed32(); + case V_INT_64__PROP: return getVInt64(); + case V_SINT_64__PROP: return getVSint64(); + case V_UINT_64__PROP: return getVUint64(); + case V_FIXED_64__PROP: return getVFixed64(); + case V_SFIXED_64__PROP: return getVSfixed64(); + case V_FLOAT__PROP: return getVFloat(); + case V_DOUBLE__PROP: return getVDouble(); + case V_STRING__PROP: return getVString(); + case V_BYTES__PROP: return getVBytes(); + case V_JSON__PROP: return getVJson(); + case V_COLOR__PROP: return getVColor(); + default: return test.xmlprimitives.data.Values.super.get(field); + } + } + + @Override + public void set(String field, Object value) { + switch (field) { + case V_BOOL__PROP: internalSetVBool((boolean) value); break; + case V_INT_32__PROP: internalSetVInt32((int) value); break; + case V_SINT_32__PROP: internalSetVSint32((int) value); break; + case V_UINT_32__PROP: internalSetVUint32((int) value); break; + case V_FIXED_32__PROP: internalSetVFixed32((int) value); break; + case V_SFIXED_32__PROP: internalSetVSfixed32((int) value); break; + case V_INT_64__PROP: internalSetVInt64((long) value); break; + case V_SINT_64__PROP: internalSetVSint64((long) value); break; + case V_UINT_64__PROP: internalSetVUint64((long) value); break; + case V_FIXED_64__PROP: internalSetVFixed64((long) value); break; + case V_SFIXED_64__PROP: internalSetVSfixed64((long) value); break; + case V_FLOAT__PROP: internalSetVFloat((float) value); break; + case V_DOUBLE__PROP: internalSetVDouble((double) value); break; + case V_STRING__PROP: internalSetVString((String) value); break; + case V_BYTES__PROP: internalSetVBytes((byte[]) value); break; + case V_JSON__PROP: internalSetVJson((Object) value); break; + case V_COLOR__PROP: internalSetVColor((test.xmlprimitives.data.Color) value); break; + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + writeContent(out); + } + + @Override + protected void writeFields(de.haumacher.msgbuf.json.JsonWriter out) throws java.io.IOException { + super.writeFields(out); + out.name(V_BOOL__PROP); + out.value(isVBool()); + out.name(V_INT_32__PROP); + out.value(getVInt32()); + out.name(V_SINT_32__PROP); + out.value(getVSint32()); + out.name(V_UINT_32__PROP); + out.value(getVUint32()); + out.name(V_FIXED_32__PROP); + out.value(getVFixed32()); + out.name(V_SFIXED_32__PROP); + out.value(getVSfixed32()); + out.name(V_INT_64__PROP); + out.value(getVInt64()); + out.name(V_SINT_64__PROP); + out.value(getVSint64()); + out.name(V_UINT_64__PROP); + out.value(getVUint64()); + out.name(V_FIXED_64__PROP); + out.value(getVFixed64()); + out.name(V_SFIXED_64__PROP); + out.value(getVSfixed64()); + out.name(V_FLOAT__PROP); + out.value(getVFloat()); + out.name(V_DOUBLE__PROP); + out.value(getVDouble()); + out.name(V_STRING__PROP); + out.value(getVString()); + out.name(V_BYTES__PROP); + de.haumacher.msgbuf.json.JsonUtil.writeBinaryOptional(out, getVBytes()); + if (hasVJson()) { + out.name(V_JSON__PROP); + de.haumacher.msgbuf.json.JsonUtil.writeJsonValue(out, getVJson()); + } + out.name(V_COLOR__PROP); + getVColor().writeTo(out); + } + + @Override + protected void readField(de.haumacher.msgbuf.json.JsonReader in, String field) throws java.io.IOException { + switch (field) { + case V_BOOL__PROP: setVBool(in.nextBoolean()); break; + case V_INT_32__PROP: setVInt32(in.nextInt()); break; + case V_SINT_32__PROP: setVSint32(in.nextInt()); break; + case V_UINT_32__PROP: setVUint32(in.nextInt()); break; + case V_FIXED_32__PROP: setVFixed32(in.nextInt()); break; + case V_SFIXED_32__PROP: setVSfixed32(in.nextInt()); break; + case V_INT_64__PROP: setVInt64(in.nextLong()); break; + case V_SINT_64__PROP: setVSint64(in.nextLong()); break; + case V_UINT_64__PROP: setVUint64(in.nextLong()); break; + case V_FIXED_64__PROP: setVFixed64(in.nextLong()); break; + case V_SFIXED_64__PROP: setVSfixed64(in.nextLong()); break; + case V_FLOAT__PROP: setVFloat((float) in.nextDouble()); break; + case V_DOUBLE__PROP: setVDouble(in.nextDouble()); break; + case V_STRING__PROP: setVString(de.haumacher.msgbuf.json.JsonUtil.nextStringOptional(in)); break; + case V_BYTES__PROP: setVBytes(de.haumacher.msgbuf.json.JsonUtil.nextBinaryOptional(in)); break; + case V_JSON__PROP: setVJson(de.haumacher.msgbuf.json.JsonUtil.nextJsonValue(in)); break; + case V_COLOR__PROP: setVColor(test.xmlprimitives.data.Color.readColor(in)); break; + default: super.readField(in, field); + } + } + + @Override + public final void writeTo(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.beginObject(); + writeFields(out); + out.endObject(); + } + + /** + * Serializes all fields of this instance to the given binary output. + * + * @param out + * The binary output to write to. + * @throws java.io.IOException If writing fails. + */ + protected void writeFields(de.haumacher.msgbuf.binary.DataWriter out) throws java.io.IOException { + out.name(V_BOOL__ID); + out.value(isVBool()); + out.name(V_INT_32__ID); + out.value(getVInt32()); + out.name(V_SINT_32__ID); + out.valueSigned(getVSint32()); + out.name(V_UINT_32__ID); + out.value(getVUint32()); + out.name(V_FIXED_32__ID); + out.valueFixed(getVFixed32()); + out.name(V_SFIXED_32__ID); + out.valueFixed(getVSfixed32()); + out.name(V_INT_64__ID); + out.value(getVInt64()); + out.name(V_SINT_64__ID); + out.valueSigned(getVSint64()); + out.name(V_UINT_64__ID); + out.value(getVUint64()); + out.name(V_FIXED_64__ID); + out.valueFixed(getVFixed64()); + out.name(V_SFIXED_64__ID); + out.valueFixed(getVSfixed64()); + out.name(V_FLOAT__ID); + out.value(getVFloat()); + out.name(V_DOUBLE__ID); + out.value(getVDouble()); + out.name(V_STRING__ID); + out.value(getVString()); + if (getVBytes() != null) { + out.name(V_BYTES__ID); + out.value(getVBytes()); + } + if (hasVJson()) { + out.name(V_JSON__ID); + de.haumacher.msgbuf.json.JsonUtil.toJsonValue(getVJson()).writeTo(out); + } + out.name(V_COLOR__ID); + getVColor().writeTo(out); + } + + /** Helper for creating an object of type {@link test.xmlprimitives.data.Values} from a polymorphic composition. */ + public static test.xmlprimitives.data.Values readValues_Content(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + test.xmlprimitives.data.impl.Values_Impl result = new Values_Impl(); + result.readContent(in); + return result; + } + + /** Helper for reading all fields of this instance. */ + protected final void readContent(de.haumacher.msgbuf.binary.DataReader in) throws java.io.IOException { + while (in.hasNext()) { + int field = in.nextName(); + readField(in, field); + } + } + + /** Consumes the value for the field with the given ID and assigns its value. */ + protected void readField(de.haumacher.msgbuf.binary.DataReader in, int field) throws java.io.IOException { + switch (field) { + case V_BOOL__ID: setVBool(in.nextBoolean()); break; + case V_INT_32__ID: setVInt32(in.nextInt()); break; + case V_SINT_32__ID: setVSint32(in.nextIntSigned()); break; + case V_UINT_32__ID: setVUint32(in.nextInt()); break; + case V_FIXED_32__ID: setVFixed32(in.nextIntFixed()); break; + case V_SFIXED_32__ID: setVSfixed32(in.nextIntFixed()); break; + case V_INT_64__ID: setVInt64(in.nextLong()); break; + case V_SINT_64__ID: setVSint64(in.nextLongSigned()); break; + case V_UINT_64__ID: setVUint64(in.nextLong()); break; + case V_FIXED_64__ID: setVFixed64(in.nextLongFixed()); break; + case V_SFIXED_64__ID: setVSfixed64(in.nextLongFixed()); break; + case V_FLOAT__ID: setVFloat(in.nextFloat()); break; + case V_DOUBLE__ID: setVDouble(in.nextDouble()); break; + case V_STRING__ID: setVString(in.nextString()); break; + case V_BYTES__ID: setVBytes(in.nextBinary()); break; + case V_JSON__ID: setVJson(de.haumacher.msgbuf.json.JsonUtil.fromJsonValue(de.haumacher.msgbuf.json.value.JsonValue.readJsonValue(in))); break; + case V_COLOR__ID: setVColor(test.xmlprimitives.data.Color.readColor(in)); break; + default: in.skipValue(); + } + } + + /** XML element name representing a {@link test.xmlprimitives.data.Values} type. */ + public static final String VALUES__XML_ELEMENT = "values"; + + /** XML attribute or element name of a {@link #isVBool} property. */ + private static final String V_BOOL__XML_ATTR = "v-bool"; + + /** XML attribute or element name of a {@link #getVInt32} property. */ + private static final String V_INT_32__XML_ATTR = "v-int-32"; + + /** XML attribute or element name of a {@link #getVSint32} property. */ + private static final String V_SINT_32__XML_ATTR = "v-sint-32"; + + /** XML attribute or element name of a {@link #getVUint32} property. */ + private static final String V_UINT_32__XML_ATTR = "v-uint-32"; + + /** XML attribute or element name of a {@link #getVFixed32} property. */ + private static final String V_FIXED_32__XML_ATTR = "v-fixed-32"; + + /** XML attribute or element name of a {@link #getVSfixed32} property. */ + private static final String V_SFIXED_32__XML_ATTR = "v-sfixed-32"; + + /** XML attribute or element name of a {@link #getVInt64} property. */ + private static final String V_INT_64__XML_ATTR = "v-int-64"; + + /** XML attribute or element name of a {@link #getVSint64} property. */ + private static final String V_SINT_64__XML_ATTR = "v-sint-64"; + + /** XML attribute or element name of a {@link #getVUint64} property. */ + private static final String V_UINT_64__XML_ATTR = "v-uint-64"; + + /** XML attribute or element name of a {@link #getVFixed64} property. */ + private static final String V_FIXED_64__XML_ATTR = "v-fixed-64"; + + /** XML attribute or element name of a {@link #getVSfixed64} property. */ + private static final String V_SFIXED_64__XML_ATTR = "v-sfixed-64"; + + /** XML attribute or element name of a {@link #getVFloat} property. */ + private static final String V_FLOAT__XML_ATTR = "v-float"; + + /** XML attribute or element name of a {@link #getVDouble} property. */ + private static final String V_DOUBLE__XML_ATTR = "v-double"; + + /** XML attribute or element name of a {@link #getVString} property. */ + private static final String V_STRING__XML_ATTR = "v-string"; + + /** XML attribute or element name of a {@link #getVBytes} property. */ + private static final String V_BYTES__XML_ATTR = "v-bytes"; + + /** XML attribute or element name of a {@link #getVJson} property. */ + private static final String V_JSON__XML_ATTR = "v-json"; + + /** XML attribute or element name of a {@link #getVColor} property. */ + private static final String V_COLOR__XML_ATTR = "v-color"; + + @Override + public String getXmlTagName() { + return VALUES__XML_ELEMENT; + } + + @Override + public final void writeContent(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + writeAttributes(out); + writeElements(out); + } + + /** Serializes all fields that are written as XML attributes. */ + protected void writeAttributes(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + out.writeAttribute(V_BOOL__XML_ATTR, Boolean.toString(isVBool())); + out.writeAttribute(V_INT_32__XML_ATTR, Integer.toString(getVInt32())); + out.writeAttribute(V_SINT_32__XML_ATTR, Integer.toString(getVSint32())); + out.writeAttribute(V_UINT_32__XML_ATTR, Long.toString(Integer.toUnsignedLong(getVUint32()))); + out.writeAttribute(V_FIXED_32__XML_ATTR, Long.toString(Integer.toUnsignedLong(getVFixed32()))); + out.writeAttribute(V_SFIXED_32__XML_ATTR, Integer.toString(getVSfixed32())); + out.writeAttribute(V_INT_64__XML_ATTR, Long.toString(getVInt64())); + out.writeAttribute(V_SINT_64__XML_ATTR, Long.toString(getVSint64())); + out.writeAttribute(V_UINT_64__XML_ATTR, Long.toString(getVUint64())); + out.writeAttribute(V_FIXED_64__XML_ATTR, Long.toString(getVFixed64())); + out.writeAttribute(V_SFIXED_64__XML_ATTR, Long.toString(getVSfixed64())); + out.writeAttribute(V_FLOAT__XML_ATTR, Float.toString(getVFloat())); + out.writeAttribute(V_DOUBLE__XML_ATTR, Double.toString(getVDouble())); + out.writeAttribute(V_STRING__XML_ATTR, getVString()); + if (getVBytes() != null) { + out.writeAttribute(V_BYTES__XML_ATTR, java.util.Base64.getEncoder().encodeToString(getVBytes())); + } + out.writeAttribute(V_JSON__XML_ATTR, de.haumacher.msgbuf.json.JsonUtil.jsonStringValue(getVJson())); + out.writeAttribute(V_COLOR__XML_ATTR, getVColor().protocolName()); + } + + /** Serializes all fields that are written as XML elements. */ + protected void writeElements(javax.xml.stream.XMLStreamWriter out) throws javax.xml.stream.XMLStreamException { + // No element fields. + } + + /** Creates a new {@link test.xmlprimitives.data.Values} and reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + public static Values_Impl readValues_XmlContent(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + Values_Impl result = new Values_Impl(); + result.readContentXml(in); + return result; + } + + /** Reads properties from the content (attributes and inner tags) of the currently open element in the given {@link javax.xml.stream.XMLStreamReader}. */ + protected final void readContentXml(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + for (int n = 0, cnt = in.getAttributeCount(); n < cnt; n++) { + String name = in.getAttributeLocalName(n); + String value = in.getAttributeValue(n); + + readFieldXmlAttribute(name, value); + } + while (true) { + int event = in.nextTag(); + if (event == javax.xml.stream.XMLStreamConstants.END_ELEMENT) { + break; + } + assert event == javax.xml.stream.XMLStreamConstants.START_ELEMENT; + + String localName = in.getLocalName(); + readFieldXmlElement(in, localName); + } + } + + /** Parses the given attribute value and assigns it to the field with the given name. */ + protected void readFieldXmlAttribute(String name, String value) { + switch (name) { + case V_BOOL__XML_ATTR: { + setVBool(Boolean.parseBoolean(value)); + break; + } + case V_INT_32__XML_ATTR: { + setVInt32(Integer.parseInt(value)); + break; + } + case V_SINT_32__XML_ATTR: { + setVSint32(Integer.parseInt(value)); + break; + } + case V_UINT_32__XML_ATTR: { + setVUint32((int) Long.parseLong(value)); + break; + } + case V_FIXED_32__XML_ATTR: { + setVFixed32((int) Long.parseLong(value)); + break; + } + case V_SFIXED_32__XML_ATTR: { + setVSfixed32(Integer.parseInt(value)); + break; + } + case V_INT_64__XML_ATTR: { + setVInt64(Long.parseLong(value)); + break; + } + case V_SINT_64__XML_ATTR: { + setVSint64(Long.parseLong(value)); + break; + } + case V_UINT_64__XML_ATTR: { + setVUint64(Long.parseLong(value)); + break; + } + case V_FIXED_64__XML_ATTR: { + setVFixed64(Long.parseLong(value)); + break; + } + case V_SFIXED_64__XML_ATTR: { + setVSfixed64(Long.parseLong(value)); + break; + } + case V_FLOAT__XML_ATTR: { + setVFloat(Float.parseFloat(value)); + break; + } + case V_DOUBLE__XML_ATTR: { + setVDouble(Double.parseDouble(value)); + break; + } + case V_STRING__XML_ATTR: { + setVString(value); + break; + } + case V_BYTES__XML_ATTR: { + setVBytes(java.util.Base64.getDecoder().decode(value)); + break; + } + case V_JSON__XML_ATTR: { + setVJson(de.haumacher.msgbuf.json.JsonUtil.parseJsonValue(value)); + break; + } + case V_COLOR__XML_ATTR: { + setVColor(test.xmlprimitives.data.Color.valueOfProtocol(value)); + break; + } + default: { + // Skip unknown attribute. + } + } + } + + /** Reads the element under the cursor and assigns its contents to the field with the given name. */ + protected void readFieldXmlElement(javax.xml.stream.XMLStreamReader in, String localName) throws javax.xml.stream.XMLStreamException { + switch (localName) { + case V_BOOL__XML_ATTR: { + setVBool(Boolean.parseBoolean(in.getElementText())); + break; + } + case V_INT_32__XML_ATTR: { + setVInt32(Integer.parseInt(in.getElementText())); + break; + } + case V_SINT_32__XML_ATTR: { + setVSint32(Integer.parseInt(in.getElementText())); + break; + } + case V_UINT_32__XML_ATTR: { + setVUint32((int) Long.parseLong(in.getElementText())); + break; + } + case V_FIXED_32__XML_ATTR: { + setVFixed32((int) Long.parseLong(in.getElementText())); + break; + } + case V_SFIXED_32__XML_ATTR: { + setVSfixed32(Integer.parseInt(in.getElementText())); + break; + } + case V_INT_64__XML_ATTR: { + setVInt64(Long.parseLong(in.getElementText())); + break; + } + case V_SINT_64__XML_ATTR: { + setVSint64(Long.parseLong(in.getElementText())); + break; + } + case V_UINT_64__XML_ATTR: { + setVUint64(Long.parseLong(in.getElementText())); + break; + } + case V_FIXED_64__XML_ATTR: { + setVFixed64(Long.parseLong(in.getElementText())); + break; + } + case V_SFIXED_64__XML_ATTR: { + setVSfixed64(Long.parseLong(in.getElementText())); + break; + } + case V_FLOAT__XML_ATTR: { + setVFloat(Float.parseFloat(in.getElementText())); + break; + } + case V_DOUBLE__XML_ATTR: { + setVDouble(Double.parseDouble(in.getElementText())); + break; + } + case V_STRING__XML_ATTR: { + setVString(in.getElementText()); + break; + } + case V_BYTES__XML_ATTR: { + setVBytes(java.util.Base64.getDecoder().decode(in.getElementText())); + break; + } + case V_JSON__XML_ATTR: { + setVJson(de.haumacher.msgbuf.json.JsonUtil.parseJsonValue(in.getElementText())); + break; + } + case V_COLOR__XML_ATTR: { + setVColor(test.xmlprimitives.data.Color.valueOfProtocol(in.getElementText())); + break; + } + default: { + internalSkipUntilMatchingEndElement(in); + } + } + } + + protected static final void internalSkipUntilMatchingEndElement(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException { + int level = 0; + while (true) { + switch (in.next()) { + case javax.xml.stream.XMLStreamConstants.START_ELEMENT: level++; break; + case javax.xml.stream.XMLStreamConstants.END_ELEMENT: if (level == 0) { return; } else { level--; break; } + } + } + } + +} diff --git a/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/xmlprimitives.proto b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/xmlprimitives.proto new file mode 100644 index 00000000..ab8817cd --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/java/test/xmlprimitives/xmlprimitives.proto @@ -0,0 +1,77 @@ +syntax = "msgbuf"; + +/** + * All primitive types in all serialization formats, singular, repeated and nullable (issue #44). + */ +package test.xmlprimitives.data; + +enum Color { + RED; + GREEN; +} + +/** Every primitive type as singular field. */ +message Values { + bool vBool; + int32 vInt32; + sint32 vSint32; + uint32 vUint32; + fixed32 vFixed32; + sfixed32 vSfixed32; + int64 vInt64; + sint64 vSint64; + uint64 vUint64; + fixed64 vFixed64; + sfixed64 vSfixed64; + float vFloat; + double vDouble; + string vString; + bytes vBytes; + json vJson; + Color vColor; +} + +/** Every primitive type as repeated field. */ +message Lists { + repeated bool lBool; + repeated int32 lInt32; + repeated sint32 lSint32; + repeated uint32 lUint32; + repeated fixed32 lFixed32; + repeated sfixed32 lSfixed32; + repeated int64 lInt64; + repeated sint64 lSint64; + repeated uint64 lUint64; + repeated fixed64 lFixed64; + repeated sfixed64 lSfixed64; + repeated float lFloat; + repeated double lDouble; + repeated string lString; + repeated bytes lBytes; + repeated Color lColor; +} + +/** Every primitive type as nullable field. */ +message Nullables { + @Nullable bool nBool; + @Nullable int32 nInt32; + @Nullable sint32 nSint32; + @Nullable uint32 nUint32; + @Nullable fixed32 nFixed32; + @Nullable sfixed32 nSfixed32; + @Nullable int64 nInt64; + @Nullable sint64 nSint64; + @Nullable uint64 nUint64; + @Nullable fixed64 nFixed64; + @Nullable sfixed64 nSfixed64; + @Nullable float nFloat; + @Nullable double nDouble; + @Nullable string nString; + @Nullable bytes nBytes; + @Nullable json nJson; + @Nullable Color nColor; + @Nullable repeated int32 nlInt32; + @Nullable repeated uint32 nlUint32; + @Nullable repeated string nlString; + @Nullable repeated bytes nlBytes; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/issue.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/issue.proto new file mode 100644 index 00000000..6101ad9a --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/issue.proto @@ -0,0 +1,9 @@ +package reject.hierarchy.issue; + +/** The definition from the issue report (#45). */ +abstract message Msg { + abstract message Group extends Msg { } + message Item extends Group { int32 n; } +} + +message Item extends Msg { string s; } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/open/base.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/open/base.proto new file mode 100644 index 00000000..75ddd66a --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/open/base.proto @@ -0,0 +1,5 @@ +package reject.hierarchy.open; + +option OpenWorld; + +abstract message Shape { } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/open/one.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/open/one.proto new file mode 100644 index 00000000..82950e50 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/open/one.proto @@ -0,0 +1,5 @@ +package reject.hierarchy.one; + +import "base.proto"; + +message Circle extends reject.hierarchy.open.Shape { } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/open/two.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/open/two.proto new file mode 100644 index 00000000..f88f0fcc --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/open/two.proto @@ -0,0 +1,5 @@ +package reject.hierarchy.two; + +import "base.proto"; + +message Circle extends reject.hierarchy.open.Shape { } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/protocol.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/protocol.proto new file mode 100644 index 00000000..d4abf6f3 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/protocol.proto @@ -0,0 +1,35 @@ +package reject.hierarchy.protocol; + +option NoTypeKind; + +/** Equal identifiers given explicitly. */ +abstract message Shape { } + +@Name("shape") +message Circle extends Shape { } + +abstract message Polygon extends Shape { } + +@Name("shape") +message Square extends Polygon { } + +@XmlName("rect") +message Rect extends Polygon { } + +@XmlName("rect") +message Box extends Polygon { } + +@type_id(7) +message Line extends Shape { } + +@type_id(7) +message Arc extends Shape { } + +/** A concrete root carries no type information, equal type IDs do not matter. */ +message Plain { } + +@Name("x") +message Plain1 extends Plain { } + +@Name("x") +message Plain2 extends Plain { } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/shadow.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/shadow.proto new file mode 100644 index 00000000..e683fc8e --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/shadow.proto @@ -0,0 +1,18 @@ +package reject.hierarchy.shadow; + +option NoTypeKind; + +/** Messages named like nested definitions of their generalizations. */ +abstract message Base { + enum Kind { A; } + + message Item extends Base { } +} + +@Name("TopKind") +message Kind extends Base { } + +message Outer { + @Name("Outer.Item") + message Item extends Base { } +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/typekind.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/typekind.proto new file mode 100644 index 00000000..beb6ddcf --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/hierarchy/typekind.proto @@ -0,0 +1,21 @@ +package reject.hierarchy.typekind; + +/** Distinct type IDs, but the same TypeKind constant. */ +abstract message Msg { } + +message A { + @Name("A.Item") + message Item extends Msg { } +} + +message B { + message Item extends Msg { } +} + +/** A concrete root has a TypeKind enum, too. */ +message Root { } + +message FooBar extends Root { } + +@Name("Other") +message FOO_BAR extends Root { } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/names/a/a.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/a/a.proto new file mode 100644 index 00000000..e0064bd7 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/a/a.proto @@ -0,0 +1,21 @@ +package reject.names.a; + +/** Uses the unqualified name 'Node', also defined in package 'reject.names.b' (issue #46). */ +message User { + Node node; + + message Inner { + repeated Node nodes; + } +} + +/** See {@link Node}. */ +enum Color { + RED; +} + +message Node { + string label; +} + +message Special extends Node { } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/names/b/b.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/b/b.proto new file mode 100644 index 00000000..14ea4bd7 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/b/b.proto @@ -0,0 +1,5 @@ +package reject.names.b; + +message Node { + int32 id; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/names/c/c.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/c/c.proto new file mode 100644 index 00000000..bfe43945 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/c/c.proto @@ -0,0 +1,6 @@ +package reject.names.c; + +/** 'Node' is defined in two other packages, but not in this one. */ +message Use { + Node node; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/names/dup/one.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/dup/one.proto new file mode 100644 index 00000000..82462835 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/dup/one.proto @@ -0,0 +1,3 @@ +package reject.names.dup; + +message Thing { } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/names/dup/twice.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/dup/twice.proto new file mode 100644 index 00000000..dd20e63e --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/dup/twice.proto @@ -0,0 +1,5 @@ +package reject.names.twice; + +message Thing { } + +enum Thing { A; } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/names/dup/two.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/dup/two.proto new file mode 100644 index 00000000..82462835 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/dup/two.proto @@ -0,0 +1,3 @@ +package reject.names.dup; + +message Thing { } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imp/lib.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imp/lib.proto new file mode 100644 index 00000000..fcec6fb1 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imp/lib.proto @@ -0,0 +1,3 @@ +package reject.names.imp; + +message Lib { } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imp/main.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imp/main.proto new file mode 100644 index 00000000..0e683635 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imp/main.proto @@ -0,0 +1,7 @@ +package reject.names.imp; + +import "lib.proto"; + +message Main { + Lib lib; +} diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/a/a.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/a/a.proto new file mode 100644 index 00000000..e65d03ce --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/a/a.proto @@ -0,0 +1,5 @@ +package reject.names.imports.a; + +message Node { string x; } + +message UseA { Node n; } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/b/b.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/b/b.proto new file mode 100644 index 00000000..97bde57b --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/b/b.proto @@ -0,0 +1,3 @@ +package reject.names.imports.b; + +message Node { int32 y; } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/c/c.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/c/c.proto new file mode 100644 index 00000000..c979f515 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/c/c.proto @@ -0,0 +1,6 @@ +package reject.names.imports.c; + +import "../a/a.proto"; + +/** Imports only 'a', so 'Node' is 'a.Node', whether or not 'b' is generated in the same run. */ +message UseC { Node n; } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/d/d.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/d/d.proto new file mode 100644 index 00000000..95379466 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/d/d.proto @@ -0,0 +1,6 @@ +package reject.names.imports.d; + +import "../c/c.proto"; + +/** 'Node' is defined in 'a', which is imported indirectly (through 'c'). */ +message UseD { Node n; } diff --git a/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/e/e.proto b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/e/e.proto new file mode 100644 index 00000000..6b610b06 --- /dev/null +++ b/de.haumacher.msgbuf.generator/src/test/resources/reject/names/imports/e/e.proto @@ -0,0 +1,7 @@ +package reject.names.imports.e; + +import "../a/a.proto"; +import "../b/b.proto"; + +/** Both imported files define 'Node'. */ +message UseE { Node n; } diff --git a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/binary/OctetDataReader.java b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/binary/OctetDataReader.java index 153bdeaf..ac722008 100644 --- a/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/binary/OctetDataReader.java +++ b/de.haumacher.msgbuf/src/main/java/de/haumacher/msgbuf/binary/OctetDataReader.java @@ -479,7 +479,7 @@ private long readVarLong() throws IOException { if (data < 0) { throw new IOException("End of stream received, while reading var int."); } - result |= (data & MASK_7) << shift; + result |= ((long) (data & MASK_7)) << shift; if ((data & BIT_8) == 0) { return result; } diff --git a/de.haumacher.msgbuf/src/test/java/de/haumacher/msgbuf/binary/TestDataReaderWriter.java b/de.haumacher.msgbuf/src/test/java/de/haumacher/msgbuf/binary/TestDataReaderWriter.java index acc71d52..dfc63a66 100644 --- a/de.haumacher.msgbuf/src/test/java/de/haumacher/msgbuf/binary/TestDataReaderWriter.java +++ b/de.haumacher.msgbuf/src/test/java/de/haumacher/msgbuf/binary/TestDataReaderWriter.java @@ -43,6 +43,37 @@ public void readObject(OctetDataReader in) throws IOException { }); } + public void testVarLongMessage() throws IOException { + long[] values = { 0L, 1L, -1L, Integer.MAX_VALUE + 1L, 1L << 35, Long.MIN_VALUE, Long.MAX_VALUE }; + doTest(new IOTest() { + @Override + public void writeObject(OctetDataWriter out) throws IOException { + out.beginObject(); + int id = 1; + for (long value : values) { + out.name(id++); + out.value(value); + out.name(id++); + out.valueSigned(value); + } + out.endObject(); + } + + @Override + public void readObject(OctetDataReader in) throws IOException { + in.beginObject(); + int id = 1; + for (long value : values) { + assertEquals(id++, in.nextName()); + assertEquals(value, in.nextLong()); + assertEquals(id++, in.nextName()); + assertEquals(value, in.nextLongSigned()); + } + in.endObject(); + } + }); + } + public void testStringMessage() throws IOException { doTest(new IOTest() { @Override From 12b636f2b388c0496d87db66ffdbb97564ebc4a2 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 18:49:28 +0200 Subject: [PATCH 204/207] Prepare the changelog and README for release 1.3.0. The changes collected for 1.2.3 add the TypeScript helpers as a new feature, so the release is 1.3.0; the README's dependency snippets still named 1.2.1. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d758e540..c8aae8dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 1.2.3 +## 1.3.0 ### New Features - **TypeScript type definitions**: Generate a TypeScript module per `.proto` file describing its JSON diff --git a/README.md b/README.md index 221e78a0..e4d575cb 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ In contrast to `protobuf`, `msgbuf` supports: de.haumacher.msgbuf msgbuf-api - 1.2.1 + 1.3.0 ``` @@ -32,7 +32,7 @@ To the `build/plugins` section add: de.haumacher.msgbuf msgbuf-generator-maven-plugin - 1.2.1 + 1.3.0 @@ -172,7 +172,7 @@ or its imports. A package must not define a top-level name twice, not even in di ### Transient fields Fields marked with `transient` are not serialized in any format (JSON, binary, XML). They exist only in the in-memory -representation. Readers ignore values of transient fields, e.g. in XML documents written by versions before 1.2.3: +representation. Readers ignore values of transient fields, e.g. in XML documents written by versions before 1.3.0: ```protobuf message A { From b66de73aee53e2c97cd485dadd4b57b1e75db1f2 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 20:03:36 +0200 Subject: [PATCH 205/207] [maven-release-plugin] prepare release msgbuf-api-1.3.0 --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 059fc0bb..9eea572d 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.3-SNAPSHOT + 1.3.0 msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.2.3-SNAPSHOT + 1.3.0 diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 75f89722..6c49cb6c 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.3-SNAPSHOT + 1.3.0 msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index 22bbe1fc..e2b4d469 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.3-SNAPSHOT + 1.3.0 msgbuf-generator-maven-plugin @@ -33,7 +33,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.2.3-SNAPSHOT + 1.3.0 diff --git a/pom.xml b/pom.xml index 39d659b6..f45e0fa5 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.2.3-SNAPSHOT + 1.3.0 pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - HEAD + msgbuf-api-1.3.0 From 2204051a9e3d6ec4b126986d3d4221c48e025cca Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 20:03:39 +0200 Subject: [PATCH 206/207] [maven-release-plugin] prepare for next development iteration --- de.haumacher.msgbuf.generator/pom.xml | 4 ++-- de.haumacher.msgbuf/pom.xml | 2 +- msgbuf-generator-maven-plugin/pom.xml | 4 ++-- pom.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/de.haumacher.msgbuf.generator/pom.xml b/de.haumacher.msgbuf.generator/pom.xml index 9eea572d..3f38245b 100644 --- a/de.haumacher.msgbuf.generator/pom.xml +++ b/de.haumacher.msgbuf.generator/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.3.0 + 1.3.1-SNAPSHOT msgbuf-generator @@ -34,7 +34,7 @@ de.haumacher.msgbuf msgbuf-api - 1.3.0 + 1.3.1-SNAPSHOT diff --git a/de.haumacher.msgbuf/pom.xml b/de.haumacher.msgbuf/pom.xml index 6c49cb6c..e04e26e0 100644 --- a/de.haumacher.msgbuf/pom.xml +++ b/de.haumacher.msgbuf/pom.xml @@ -4,7 +4,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.3.0 + 1.3.1-SNAPSHOT msgbuf-api diff --git a/msgbuf-generator-maven-plugin/pom.xml b/msgbuf-generator-maven-plugin/pom.xml index e2b4d469..efb5242d 100644 --- a/msgbuf-generator-maven-plugin/pom.xml +++ b/msgbuf-generator-maven-plugin/pom.xml @@ -7,7 +7,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.3.0 + 1.3.1-SNAPSHOT msgbuf-generator-maven-plugin @@ -33,7 +33,7 @@ de.haumacher.msgbuf msgbuf-generator - 1.3.0 + 1.3.1-SNAPSHOT diff --git a/pom.xml b/pom.xml index f45e0fa5..3fc7b756 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ de.haumacher.msgbuf msgbuf-parent - 1.3.0 + 1.3.1-SNAPSHOT pom @@ -39,7 +39,7 @@ https://github.com/msgbuf/msgbuf scm:git:https://github.com/msgbuf/msgbuf.git scm:git:https://github.com/msgbuf/msgbuf.git - msgbuf-api-1.3.0 + HEAD From 63644046be374f5447f959528556a3687a8056a8 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Fri, 25 Sep 2026 20:33:14 +0200 Subject: [PATCH 207/207] Update the Central publishing plugin to 0.11.0. The 1.3.0 deployment was uploaded and published, but the release workflow failed while waiting for it: plugin 0.6.0 cannot parse the deployment status the Central Portal returns now (unknown property 'warnings'), so every future release would be reported as failed. Co-Authored-By: Claude Opus 5.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3fc7b756..478d1109 100644 --- a/pom.xml +++ b/pom.xml @@ -102,7 +102,7 @@ org.sonatype.central central-publishing-maven-plugin - 0.6.0 + 0.11.0 true central