Skip to content

Commit ee1514c

Browse files
HeikoKlareptziegler
authored andcommitted
Do not wrap custom Translatable representations as precise types
The wrapping mechanism for Translatables when performing Figure#translate...() operations currently wraps every instance of the Translatable types provided by Draw2d. However, consumers may have custom specializations of those types, which can be incompatible with the implemented wrapping. This particularly applies to types like PointList, for which precision implementations did not exist such that consumers may use custom implementations of them. This adapts the wrapping logic to ensure that only the relevant basic Draw2d types are wrapped to avoid that custom specializations that are potentially incompatible with the implemented wrapping mechanism get wrapped as well.
1 parent 426184f commit ee1514c

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

org.eclipse.draw2d/src/org/eclipse/draw2d/Figure.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,14 +2092,19 @@ public final void translateToRelative(Translatable t) {
20922092
*/
20932093
private Translatable toPreciseShape(Translatable source) {
20942094
if (getParent() instanceof Figure parentFigure && parentFigure.useDoublePrecision()) {
2095-
if (source instanceof Point p && !(source instanceof PrecisionPoint)) {
2096-
return new PrecisionPoint(p);
2097-
} else if (source instanceof Dimension d && !(source instanceof PrecisionDimension)) {
2098-
return new PrecisionDimension(d);
2099-
} else if (source instanceof Rectangle r && !(source instanceof PrecisionRectangle)) {
2100-
return new PrecisionRectangle(r);
2101-
} else if (source instanceof PointList p && !(source instanceof PrecisionPointList)) {
2102-
return new PrecisionPointList(p);
2095+
// Cannot check for instanceof as consumers might have custom specializations
2096+
// which might not be wrapped properly
2097+
if (source.getClass().equals(Point.class)) {
2098+
return new PrecisionPoint((Point) source);
2099+
}
2100+
if (source.getClass().equals(Dimension.class)) {
2101+
return new PrecisionDimension((Dimension) source);
2102+
}
2103+
if (source.getClass().equals(Rectangle.class)) {
2104+
return new PrecisionRectangle((Rectangle) source);
2105+
}
2106+
if (source.getClass().equals(PointList.class)) {
2107+
return new PrecisionPointList((PointList) source);
21032108
}
21042109
}
21052110
// is already precise or doesn't have a precise variant

0 commit comments

Comments
 (0)