Eden-06 / FRaMED-2.0

FRaMED 2.0 is the reimplementation of the Full-fledged Role Modeling EDitor allowing the graphical specification of Role-based Software Systems by means of compartments (aka. contexts), objects, roles, and relationships.
Eclipse Public License 2.0
3 stars 0 forks source link

staticly coded references to container elements #1

Open SriousTaken opened 6 years ago

SriousTaken commented 6 years ago

Sometimes in the code a reference to one container child is staticly coded. This means something like containerChildren.get(0). This should be refactored and replace with a for loop asking for the property shape id of the found child.

SriousTaken commented 4 years ago

Example: Bad code in class DataTypePattern, operation move:

ContainerShape dropShadowShape = (ContainerShape) ((ContainerShape) typeBodyShape).getContainer().getChildren().get(0);

Explanation: The executed casts are checked before the displayed code here. Ignoring these, typeBodyShape.getContainer().getChildren().get(0); should not be used as the code .get(0) assumes the children to get is the first one. However this can not be ensured for the lifetime of the software. Instead there should be a for-loop to search over all getContainer().getChildren() for a specific Id. See the good example for reference.

Example: Good solution in class DataTypePattern, operation update:

for(Shape shape : containerShape.getChildren()) {
   ...
   if(UIUtil.isShape_IdValue(shape, literals.SHAPE_ID_DATATYPE_NAME)) {
      text.setValue(businessTypeName);
      returnValue = true;
}   }