Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify plugin does not set replacement property parent #106

Open
bertramn opened this issue May 3, 2019 · 0 comments
Open

simplify plugin does not set replacement property parent #106

bertramn opened this issue May 3, 2019 · 0 comments

Comments

@bertramn
Copy link

bertramn commented May 3, 2019

Problem:

When the simplify plugin replaces multiple choice properties, it does not set the parent of the replacement property which leads to failures in other plugins that may be executed after it. For instance any call to CPropertyInfo.displayName() on a replaced property will fail with a NPE.

This is caused by adding the replaced property to the CClassInfo.properties but not setting the class as the parent of the property.

SimplifyPlugin.java#L167
SimplifyPlugin.java#L192
SimplifyPlugin.java#L195
SimplifyPlugin.java#L243

Possible solution:

The method CPropertyInfo.setParent is package scoped. The only way to set the parent is to first add the replacement property to the class using the CClassInfo.addProperty() method, then remove it from the collection and then add it back at the correct index position.

CPropertyInfo newProperty = createElementPropertyInfo(oldProperty, elementDef, ... );
// attach/detach to set parent
classInfo.addProperty(newProperty);
classInfo.getProperties().remove(newProperty);
// then add to right place and remove old one
classInfo.getProperties().add(index, newProperty);
classInfo.getProperties().remove(oldProperty);

This will require modification of the class properties outside the visitation loop or else the code that modifies the properties list will fail with ConcurrentModificationException. We would need to collect enough information in the visitor to be able to apply the modifications after finalising the visitation.

SimplifyVisitor visitor = new SimplifyVisitor();

for (CPropertyInfo property : classInfo.getProperties()) {
  property.accept(visitor);
}

for(Modification mod : visitor.getModifications()) {
  mod.apply(classInfo);
}

A bit hacky but works reliably.

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

No branches or pull requests

1 participant