From 7ce40a78896a8a4403c05e98741d9ff59865bf3b Mon Sep 17 00:00:00 2001 From: Lars Poeschel Date: Fri, 6 Aug 2021 17:07:32 +0200 Subject: [PATCH 1/2] dbus-java-utils: ClassBuilderInfo: Don't duplicate constructor arguments When building classes using ClassBuilderInfo, arguments to the super() [superArguments] are automatically added to the constructor of the newly generated class. These arguments are not saved to the private members of the class. Saving to private members in the constructor is only done for [arguments] only. To have both: * saving to private members for getters and setters and * supplying to super() we have to add the argument to both: superArguments and arguments. But this then results to duplicate arguments to the constructor. This commit now removes these double arguments. --- .../freedesktop/dbus/utils/generator/ClassBuilderInfo.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/ClassBuilderInfo.java b/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/ClassBuilderInfo.java index 4634feaa..f73c1017 100644 --- a/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/ClassBuilderInfo.java +++ b/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/ClassBuilderInfo.java @@ -263,8 +263,10 @@ private List createClassFileContent(boolean _staticClass, Set _o String outerIndent = _staticClass ? " " : " "; String cstr = outerIndent + "public " + getClassName() + "("; - if (!constructor.getSuperArguments().isEmpty()) { - cstr += constructor.getSuperArguments().stream().map(e -> e.asOneLineString(allImports, false)).collect(Collectors.joining(", ")); + List filteredSuperArguments = new ArrayList<>(constructor.getSuperArguments()); + filteredSuperArguments.removeIf(e -> constructor.getArguments().contains(e)); + if (!filteredSuperArguments.isEmpty()) { + cstr += filteredSuperArguments.stream().map(e -> e.asOneLineString(allImports, false)).collect(Collectors.joining(", ")); if (!constructor.getArguments().isEmpty()) { cstr += ", "; } From 145898191827dd113872e30f4d56caf67124e555 Mon Sep 17 00:00:00 2001 From: Lars Poeschel Date: Fri, 6 Aug 2021 17:19:27 +0200 Subject: [PATCH 2/2] dbus-java-utils: InterfaceCodeGenerator: Fix constructor for signals The constructor for dbus signals was generated wrong. For example this introspection.xml: did generate this class: public interface Example extends DBusInterface { public static class ExampleSignal extends DBusSignal { private final String newState; public ExampleSignal(String _path, String _interfaceName, String _newState) throws DBusException { super(_path, _interfaceName); this.newState = _newState; } public String getNewState() { return newState; } } } This is wrong. With this interface it is not possible to emit this signal using dbus-java. When the ExampleSignal constructor is called, this leads to the DBusSignal constructor to be called with _path and _interfaceName arguments. DBusSignal class then infers from the enclosing classes arguments, that there must be two string arguments ("ss") to this signal. It is only one. The interface constructor has to look something like this: public ExampleSignal(String _path, String _newState) throws DBusException { super(_path, _newState); this.newState = _newState; } This is what this commit does. It changes the interface generation to reflect this. --- .../dbus/utils/generator/InterfaceCodeGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/InterfaceCodeGenerator.java b/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/InterfaceCodeGenerator.java index 480c0dd0..005e6b9f 100644 --- a/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/InterfaceCodeGenerator.java +++ b/dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/InterfaceCodeGenerator.java @@ -250,7 +250,7 @@ private List extractSignals(Element _signalElement, ClassBuild classConstructor.getThrowArguments().add(DBusException.class.getSimpleName()); classConstructor.getSuperArguments().add(new MemberOrArgument("_path", "String", false)); - classConstructor.getSuperArguments().add(new MemberOrArgument("_interfaceName", "String", false)); + classConstructor.getSuperArguments().addAll(argsList); innerClass.getConstructors().add(classConstructor);