Skip to content

Commit

Permalink
Merge pull request #36 from Paullo612/fix-two-slots-primitive-express…
Browse files Browse the repository at this point in the history
…ions

Fix handling of binding expressions that return two slot primitives
  • Loading branch information
Paullo612 committed May 27, 2023
2 parents 1eec744 + dd52c11 commit b283ffa
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ void renderSetter(
ClassElement targetType) {
expressionRenderer.render(methodVisitor -> {
methodVisitor.loadThis();
methodVisitor.swap();
methodVisitor.invokeVirtual(
Type.getType(propertyClass),
new Method("set", "(" + RenderUtils.type(targetType) + ")V")
);

Type propertyType = Type.getType(propertyClass);
Type type = RenderUtils.type(targetType);

methodVisitor.swap(type, propertyType);
methodVisitor.invokeVirtual(propertyType, new Method("set", "(" + type + ")V"));
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
package io.github.paullo612.mlfx.compiler.test;

import javafx.beans.DefaultProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
Expand Down Expand Up @@ -53,6 +55,8 @@ public static EngineLocation getEngineLocation(Engine engine) {

private final ObjectProperty<EventHandler<ActionEvent>> onDrive = new SimpleObjectProperty<>(this, "onDrive");

private final DoubleProperty engineRPM = new SimpleDoubleProperty();

public String getModel() {
return model.getValue();
}
Expand Down Expand Up @@ -101,6 +105,18 @@ public ObjectProperty<EventHandler<ActionEvent>> onDriveProperty() {
return onDrive;
}

public double getEngineRPM() {
return engineRPM.get();
}

public void setEngineRPM(double value) {
engineRPM.set(value);
}

public DoubleProperty engineRPMProperty() {
return engineRPM;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Car)) {
Expand All @@ -113,7 +129,8 @@ public boolean equals(Object obj) {
&& Objects.equals(engine.get(), other.engine.get())
&& Objects.equals(anotherEngine, other.anotherEngine)
&& Objects.equals(bodyColors, other.bodyColors)
&& Objects.equals(wheels, other.wheels);
&& Objects.equals(wheels, other.wheels)
&& engineRPM.get() == other.engineRPM.get();
}

protected String dumpFields() {
Expand All @@ -130,7 +147,8 @@ protected String dumpFields() {
",\n engine = " + engine +
",\n anotherEngine = " + anotherEngine +
",\n bodyColors = " + bodyColors +
",\n wheels = " + wheels;
",\n wheels = " + wheels +
",\n engineRPM = " + engineRPM.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package io.github.paullo612.mlfx.compiler.test;

import javafx.beans.DefaultProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

Expand All @@ -39,6 +41,8 @@ public static Engine createV8Engine() {

private final Crankshaft crankshaft = new Crankshaft();

private final DoubleProperty RPM = new SimpleDoubleProperty();

public EngineType getEngineType() {
return engineType;
}
Expand All @@ -63,6 +67,14 @@ public Crankshaft getCrankshaft() {
return crankshaft;
}

public double getRPM() {
return RPM.get();
}

public DoubleProperty RPMProperty() {
return RPM;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Engine)) {
Expand All @@ -74,7 +86,8 @@ public boolean equals(Object obj) {
return Objects.equals(engineType, other.engineType)
&& Objects.equals(engineLocation, other.engineLocation)
&& Objects.equals(manufacturer.get(), other.manufacturer.get())
&& crankshaft.equals(other.crankshaft);
&& crankshaft.equals(other.crankshaft)
&& RPM.get() == other.RPM.get();
}

@Override
Expand All @@ -84,6 +97,7 @@ public String toString() {
",\n engineLocation = " + engineLocation +
",\n manufacturer = " + manufacturer.get() +
",\n crankshaft = " + crankshaft +
",\n RPM = " + RPM.get() +
"\n}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.
*/
package io.github.paullo612.mlfx.compiler.compliance.two_slots_primitive_expression;

import io.github.paullo612.mlfx.api.CompileFXML;

@CompileFXML(fxmlDirectories = "io/github/paullo612/mlfx/compiler/compliance/two_slots_primitive_expression")
class TwoSlotsPrimitiveExpression { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--
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.Engine?>

<Car engineRPM="${engine.RPM}" xmlns="http://javafx.com/javafx/19.0.0" xmlns:fx="http://javafx.com/fxml/1">
<Engine fx:id="engine"/>
</Car>

0 comments on commit b283ffa

Please sign in to comment.