Skip to content

Commit

Permalink
Merge pull request #37 from Paullo612/fix-static-object-properties
Browse files Browse the repository at this point in the history
Fix handling of static properties with object arguments
  • Loading branch information
Paullo612 committed May 27, 2023
2 parents b283ffa + 5acd1ad commit 416f45a
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ void apply(CompilerContext context, ClassElement classElement, String name, Valu
if (staticGetters.isEmpty()) {
// FXMLLoader throws |com.sun.javafx.fxml.PropertyNotFoundException| in such case. We're inside annotation
// processor, so, we can throw |CompileErrorException| instead.
throw context.compileError("Static property \"" + name + "\" is read-only.");
throw context.compileError("Static property \"" + name + "\" is read-only or does not exist.");
}

ClassElement staticPropertyType = staticGetters.get(0).getReturnType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,14 @@ public void handleCharacters(CompilerContext context, String text) {
LoadableFXMLElement.loadString(context, value)
);
}

@Override
void apply(CompilerContext context, IdentifiableFXMLElement element) {
getParent().apply(
context,
staticClassElement,
name,
IdentifiableFXMLElement.loadElement(context, element)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ public static EngineLocation getEngineLocation(Engine engine) {
return engine.engineLocation;
}

public static void setSpareWheel(Trunk trunk, Wheel wheel) {
trunk.spareWheel = wheel;
}

// NB: We're inferring static property type from getter, so, getter is mandatory here.
public static Wheel getSpareWheel(Trunk trunk) {
return trunk.spareWheel;
}

private final Property<String> model = new SimpleStringProperty();

private final ObjectProperty<Engine> engine = new SimpleObjectProperty<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.github.paullo612.mlfx.compiler.test;

import java.util.Objects;

public class Trunk {

Wheel spareWheel;

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}

if (o == null || getClass() != o.getClass()) {
return false;
}

Trunk other = (Trunk) o;

return Objects.equals(spareWheel, other.spareWheel);
}

@Override
public String toString() {
return "Trunk { spareWheel = " + spareWheel + "}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
Copyright 2023 Paullo612
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<?import io.github.paullo612.mlfx.compiler.test.Car?>
<?import io.github.paullo612.mlfx.compiler.test.Trunk?>
<?import io.github.paullo612.mlfx.compiler.test.Wheel?>

<Trunk xmlns="http://javafx.com/javafx/19.0.0">
<Car.spareWheel>
<Wheel index="5"/>
</Car.spareWheel>
</Trunk>

0 comments on commit 416f45a

Please sign in to comment.