Skip to content

Conversation

@JohannesLeurs
Copy link
Contributor

The SymbolBuilderDecorator contains instructions to set an initializing value for the access modifier attribute in generated symbol builders:

ASTCDAttribute accessModifier = this.getCDAttributeFacade().createAttribute(PROTECTED.build(), ACCESS_MODIFIER, "accessModifier");
this.replaceTemplate(VALUE, accessModifier, new StringHookPoint("= " + ACCESS_MODIFIER_ALL_INCLUSION));

However, no init value is generated for the access modifier.

The problem is the following:

  1. The access modifier attribute is created: List<ASTCDAttribute> defaultAttrs = createSymbolAttributes(symbolClass);
  2. The access modifier attribute is added to the decoratedSymbolClass if the current symbol does not inherit it from another symbol that is extended: decoratedSymbolClass.addAllCDMembers(defaultAttrs);
  3. The builderDecorator is applied to the decoratedSymbolClass in order to create a new ASTCDClass object named symbolBuilder which is consequently used: ASTCDClass symbolBuilder = builderDecorator.decorate(decoratedSymbolClass);
  4. In order to do so, the builderDecorator deepClones all attributes of the original CDClass
  5. As a result, the accessModifier attribute has a differerent object identity. While we registered the template-replacement for "no initial value" to ALL_INCLUSION on the original ASTCDAttribute, the template replacement map does not contain an entry for the new ASTCDAttribute. Hence, cd2java's default "no initial value" template is applied.

Hence, template replacements have to be transferred to during the decoration of the BuilderDecorator, or they have to be registered after the cloning. I did the latter in this merge request. This way, I added the replacement in the same way like it is already done for the build-Method in the SymbolBuilderDecorator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant