Author HTML and typed suggestion bindings in the IntelliJ designer
This commit is contained in:
+44
-4
@@ -27,7 +27,32 @@ public final class BindingDiscovery {
|
||||
private final Map<String, Class<?>> paths = new TreeMap<>();
|
||||
private final List<Attribute> attributes = new ArrayList<>();
|
||||
|
||||
private record TargetType(Class<?> type, boolean writable) {}
|
||||
private final Map<String, Class<?>> listElements = new HashMap<>();
|
||||
|
||||
private record TargetType(Class<?> type, boolean writable, Class<?> listElement) {}
|
||||
|
||||
// Invariant element signatures for explicit JavaFX list properties. Keep raw, wildcard
|
||||
// and unresolvable generic declarations in the existing unverified collection path.
|
||||
private static Class<?> listElement(Method method) {
|
||||
if (!(method.getGenericReturnType() instanceof ParameterizedType p)
|
||||
|| p.getActualTypeArguments().length != 1) return null;
|
||||
Type value = p.getActualTypeArguments()[0];
|
||||
if (p.getRawType() == javafx.beans.property.ListProperty.class
|
||||
|| p.getRawType() == javafx.beans.property.ReadOnlyListProperty.class)
|
||||
return value instanceof Class<?> element ? element : null;
|
||||
if ((p.getRawType() == javafx.beans.property.ObjectProperty.class
|
||||
|| p.getRawType() == javafx.beans.property.ReadOnlyObjectProperty.class)
|
||||
&& value instanceof ParameterizedType list
|
||||
&& list.getRawType() == javafx.collections.ObservableList.class
|
||||
&& list.getActualTypeArguments()[0] instanceof Class<?> element) return element;
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean knownListPair(String path, TargetType target, String direction) {
|
||||
return direction.equals("view")
|
||||
&& listElements.containsKey(path)
|
||||
&& target.listElement() != null;
|
||||
}
|
||||
|
||||
private final Set<String> actionHandlers = new HashSet<>();
|
||||
private final Map<String, Class<?>> controlTypes = new HashMap<>();
|
||||
@@ -344,9 +369,10 @@ public final class BindingDiscovery {
|
||||
value = load(componentModel);
|
||||
constrained = true;
|
||||
}
|
||||
targetTypes.put(
|
||||
id + "." + property,
|
||||
new TargetType(value, Property.class.isAssignableFrom(m.getReturnType())));
|
||||
var target =
|
||||
new TargetType(
|
||||
value, Property.class.isAssignableFrom(m.getReturnType()), listElement(m));
|
||||
targetTypes.put(id + "." + property, target);
|
||||
String status, reason;
|
||||
if (!Property.class.isAssignableFrom(m.getReturnType())) {
|
||||
status = "INCOMPATIBLE";
|
||||
@@ -361,6 +387,13 @@ public final class BindingDiscovery {
|
||||
status = "UNRESOLVED";
|
||||
reason =
|
||||
"Declared types are insufficient; rebuild with specific signatures/Model metadata.";
|
||||
} else if (knownListPair(selected, target, direction)) {
|
||||
boolean matches = listElements.get(selected) == target.listElement();
|
||||
status = matches ? "COMPATIBLE" : "INCOMPATIBLE";
|
||||
reason =
|
||||
matches
|
||||
? "Matching observable list element type: " + target.listElement().getName()
|
||||
: "Observable list element types differ.";
|
||||
} else if (Collection.class.isAssignableFrom(source)
|
||||
|| Collection.class.isAssignableFrom(value)
|
||||
|| Map.class.isAssignableFrom(source)
|
||||
@@ -518,6 +551,8 @@ public final class BindingDiscovery {
|
||||
|| m.isSynthetic()) continue;
|
||||
String name = m.getName().substring(0, m.getName().length() - 8);
|
||||
if (name.isEmpty() || paths.containsKey(name)) continue;
|
||||
Class<?> element = listElement(m);
|
||||
if (element != null) listElements.put(name, element);
|
||||
Class<?> value = propertyType(m.getGenericReturnType(), Map.of());
|
||||
Class<?> getter = valueType(vm, name);
|
||||
if (value == Number.class && getter != null && Number.class.isAssignableFrom(box(getter)))
|
||||
@@ -703,6 +738,11 @@ public final class BindingDiscovery {
|
||||
severity = c.status().equals("UNVERIFIED") ? "WARNING" : "ERROR";
|
||||
message = converter + ": " + c.reason();
|
||||
}
|
||||
} else if (knownListPair(path, target, direction)) {
|
||||
if (listElements.get(path) != target.listElement()) {
|
||||
severity = "ERROR";
|
||||
message = "Observable list element types differ.";
|
||||
}
|
||||
} else if (target.type() == null
|
||||
|| source == Object.class
|
||||
|| target.type() == Object.class
|
||||
|
||||
+32
@@ -49,6 +49,14 @@ class ViewModelComputedTest {
|
||||
throw new AssertionError("reserved invoked");
|
||||
}
|
||||
|
||||
public ReadOnlyListProperty<String> tagsProperty() {
|
||||
throw new AssertionError("property invoked");
|
||||
}
|
||||
|
||||
public ObjectProperty<javafx.collections.ObservableList<Integer>> numbersProperty() {
|
||||
throw new AssertionError("property invoked");
|
||||
}
|
||||
|
||||
public ReadOnlyStringProperty readOnlyProperty() {
|
||||
throw new AssertionError("readonly invoked");
|
||||
}
|
||||
@@ -237,6 +245,30 @@ class ViewModelComputedTest {
|
||||
assertNull(System.getProperty(key));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTargetsCheckTheDeclaredElementTypeForDiscoveryAndValidation() throws Exception {
|
||||
for (String path : List.of("tags", "numbers")) {
|
||||
String document =
|
||||
xml(
|
||||
Controller.class,
|
||||
direct(path).replace("property='text'", "property='suggestionsSource'"))
|
||||
.replace(
|
||||
"javafx.scene.control.TextField", "de.neitzel.fx.control.AutoCompleteTextField")
|
||||
.replace("<TextField", "<AutoCompleteTextField")
|
||||
.replace("</TextField>", "</AutoCompleteTextField>");
|
||||
var result = BindingDiscovery.inspect(document, path, "view", getClass().getClassLoader());
|
||||
var target =
|
||||
result.targets().stream()
|
||||
.filter(t -> t.property().equals("suggestionsSource"))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
boolean matching = path.equals("tags");
|
||||
assertEquals(matching ? "COMPATIBLE" : "INCOMPATIBLE", target.status());
|
||||
assertEquals(
|
||||
!matching, result.problems().stream().anyMatch(p -> p.severity().equals("ERROR")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void replacementDoesNotInheritModelAttributesOrDottedTraversal() throws Exception {
|
||||
var result = inspect(xml(ReplacementController.class, direct("home.name")));
|
||||
|
||||
Reference in New Issue
Block a user