Skip to content

Commit

Permalink
Throw an exception if the dockable doesn't override updateProperties …
Browse files Browse the repository at this point in the history
…when it contains DockingProperty instances.
  • Loading branch information
andrewauclair committed Jan 6, 2024
1 parent 6aa617b commit a0b838a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docking-api/src/ModernDocking/internal/DockingInternal.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ of this software and associated documentation files (the "Software"), to deal
import javax.swing.*;
import java.awt.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -95,6 +96,17 @@ private void validateDockingProperties(Dockable dockable) {
.filter(field -> field.getAnnotation(DockingProperty.class) != null)
.collect(Collectors.toList());

if (dockingPropFields.size() > 0) {
try {
Method updateProperties = dockable.getClass().getMethod("updateProperties");
if (updateProperties.getDeclaringClass() == Dockable.class) {
throw new RuntimeException("Dockable class " + dockable.getClass().getSimpleName() + " contains DockingProperty instances and should override updateProperties");
}
} catch (NoSuchMethodException ignored) {
// updateProperties has a default implementation in Dockable, so we will always find it and this exception should never happen
}
}

for (Field field : dockingPropFields) {
try {
// make sure we can access the field if it is private/protected. only try this if we're sure we can't already access it
Expand Down

0 comments on commit a0b838a

Please sign in to comment.