Skip to content

Commit decc38a

Browse files
committed
implicit boxing in lambda expressions
This had not been implemented.
1 parent f5cb0ca commit decc38a

File tree

13 files changed

+84
-37
lines changed

13 files changed

+84
-37
lines changed
Binary file not shown.
35 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20250313105418
1+
20250318122834
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20250313105418
1+
20250318122834

sources/net.sf.j2s.core/src/j2s/swingjs/Java2ScriptVisitor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ private void processMethodDeclaration(MethodDeclaration mnode, IMethodBinding mB
13831383

13841384
buffer.append(") ");
13851385
if (lambdaType != NOT_LAMBDA) {
1386-
addLambdaBody(body);
1386+
addLambdaBody(body, mBinding.getReturnType());
13871387
if (body == null)
13881388
return;
13891389
} else if (isConstructor) {
@@ -7575,16 +7575,17 @@ private void addLambdaReuse(int pt, String anonName) {
75757575
buffer.append("(" + anonName + "$||(" + anonName + "$=(").append(tmp).append(")))");
75767576
}
75777577

7578-
private void addLambdaBody(ASTNode body) {
7578+
private void addLambdaBody(ASTNode body, ITypeBinding retType) {
75797579
if (body instanceof Block) {
7580+
buffer.append("/*block*/");
75807581
body.accept(this);
75817582
} else {
75827583
// there may be no return, but we still want to do this
75837584
buffer.append("{ return ");
75847585
if (body == null)
75857586
return; // handled elsewhere
75867587
buffer.append("(");
7587-
body.accept(this);
7588+
addExpressionAsTargetType((Expression) body, retType, "r", null);
75887589
buffer.append(");}");
75897590
}
75907591
}
Binary file not shown.

sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,26 +262,25 @@ public static Object getTextMetrics(HTML5CanvasContext2D context, Font font,
262262
if (text == null || text.length() == 0)
263263
return 0;
264264
// Chrome delivers integer values, so we x 10 and then reduce.
265-
boolean isChrome = (/** @j2sNative J2S._isChrome || **/ false);
265+
// just setting this true generally; we don't need huge precision, I think.
266+
// boolean isChrome = true || (/** @j2sNative J2S._isChrome || **/ false);
266267
@SuppressWarnings("unused")
267-
String fontInfo = getCanvasFontScaled(font, isChrome ? 10 : 1);
268+
String fontInfo = getCanvasFontScaled(font, 100);//isChrome ? 100 : 1);
268269
if (context == null)
269270
context = getDefaultCanvasContext2d();
270271
Object tm = null;
271272
/**
272273
* @j2sNative
273274
* context.font = fontInfo;
274275
* tm = context.measureText(text);
275-
if (isChrome) {
276-
tm = { "width":tm.width/10,
277-
"actualBoundingBoxAscent":tm.actualBoundingBoxAscent/10,
278-
"actualBoundingBoxDescent":tm.actualBoundingBoxDescent/10,
279-
"actualBoundingBoxLeft":tm.actualBoundingBoxLeft/10,
280-
"actualBoundingBoxRight":tm.actualBoundingBoxRight/10,
281-
"fontBoundingBoxAscent":tm.fontBoundingBoxAscent/10,
282-
"fontBoundingBoxDescent":tm.fontBoundingBoxDescent/10
283-
}
284-
}
276+
tm = { "width":tm.width/100,
277+
"actualBoundingBoxAscent":tm.actualBoundingBoxAscent/100,
278+
"actualBoundingBoxDescent":tm.actualBoundingBoxDescent/100,
279+
"actualBoundingBoxLeft":tm.actualBoundingBoxLeft/100,
280+
"actualBoundingBoxRight":tm.actualBoundingBoxRight/100,
281+
"fontBoundingBoxAscent":tm.fontBoundingBoxAscent/100,
282+
"fontBoundingBoxDescent":tm.fontBoundingBoxDescent/100
283+
}
285284
*/
286285
{
287286
}

sources/net.sf.j2s.java.core/src/test/Test_Font.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.awt.Graphics2D;
66
import java.awt.font.FontRenderContext;
77
import java.awt.font.TextLayout;
8+
import java.text.NumberFormat;
9+
import java.util.Locale;
810

911
import javax.swing.JFrame;
1012
import javax.swing.JLabel;
@@ -21,8 +23,33 @@
2123
*
2224
*/
2325
public class Test_Font {//extends Test_ {
26+
protected static String formatMDLFloat(float fl) {
27+
String s, fs = "";
28+
int l;
29+
NumberFormat nf = NumberFormat.getNumberInstance(Locale.ENGLISH);
30+
nf.setMinimumIntegerDigits(1);
31+
nf.setMaximumIntegerDigits(4);
32+
nf.setMinimumFractionDigits(4);
33+
nf.setMaximumFractionDigits(4);
34+
nf.setGroupingUsed(false);
35+
if (Double.isNaN(fl) || Double.isInfinite(fl))
36+
s = "0.0000";
37+
else
38+
s = nf.format(fl);
39+
l = 10 - s.length();
40+
for (int f = 0; f < l; f++)
41+
fs += " ";
42+
fs += s;
43+
return fs;
44+
}
45+
2446
public static void main(String[] args) {
2547

48+
49+
System.out.println(formatMDLFloat(2.3f));
50+
51+
if (true)
52+
return;
2653
JLabel c = new JLabel("testing");
2754
Graphics2D g = (Graphics2D) c.getGraphics();
2855
assert (g == null);

sources/net.sf.j2s.java.core/src/test/Test_J8_Stream.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.HashMap;
77
import java.util.List;
88
import java.util.Map;
9+
import java.util.Set;
910
import java.util.Spliterator;
1011
import java.util.Spliterator.OfInt;
1112
import java.util.function.BiConsumer;
@@ -33,10 +34,20 @@ public static <E> E returnSame(E elem) {
3334
}
3435

3536
public class Test_J8_Stream extends Test_J8_Stream0 {
36-
37+
3738
@SuppressWarnings("unused")
3839
public static void main(String[] args) {
3940

41+
List<Integer> list = new ArrayList<>();
42+
list.add(Integer.valueOf(33333));
43+
Set<Integer> begSymCls = list
44+
.stream()
45+
.filter(b -> b == 33333)
46+
.map(b -> 22322)
47+
.collect(Collectors.toSet());
48+
49+
50+
4051
String st = "test\ning\r\nnow";
4152
String[] lines = st.split("\n");
4253
int[] ptr = new int[1];

sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -895,15 +895,20 @@ Clazz._loadWasm = function(cls, lib){
895895
Clazz._isQuietLoad = false;
896896
J2S._wasmPath = libPath;
897897
var src = libPath + libName + ".js";
898-
$.getScript(src, function() {jnainchiModule().then(
899-
function(module){
900-
J2S._module = module;
901-
for (var i = 0; i < funcs.length; i++) {
902-
funcs[i].apply(null, [module]);
903-
}
904-
cls.wasmInitialized = true;
905-
})
906-
});
898+
var f = function(module){
899+
J2S._module = module;
900+
for (var i = 0; i < funcs.length; i++) {
901+
funcs[i].apply(null, [module]);
902+
}
903+
cls.wasmInitialized = true;
904+
J2S.wasm[libName].$ready = true;
905+
}
906+
// may have been preloaded by other JavaScript
907+
var module = J2S[libName + "_module"]
908+
if (module)
909+
f(module);
910+
else
911+
$.getScript(src, function() {jnainchiModule().then(function(module) { f(module) })});
907912
}
908913

909914
Clazz.newClass = function (prefix, name, clazz, clazzSuper, interfacez, type) {

sources/net.sf.j2s.java.core/srcjs/swingjs2.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14144,7 +14144,7 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
1414414144
// Google closure compiler cannot handle Clazz.new or Clazz.super
1414514145

1414614146
// BH 2025.03.12 adds support for writable byte[] parameters in WASM
14147-
// BH 2025.03.06 adds support for JNA+WASM
14147+
// BH 2025.03.06 adds support for JNA+WASM, automated loading of Java native classes if WASM is available
1414814148
// BH 2025.02.22 add hashCode$() for Java Integer.TYPE and related types
1414914149
// BH 2025.01.31 added checks for JavaScript SyntaxError similar to other Error types
1415014150
// BH 2024.11.23 implementing java.awt.Toolkit.getDefaultToolkit().getDesktopProperty("awt.multiClickInterval")
@@ -15031,15 +15031,19 @@ Clazz._loadWasm = function(cls, lib){
1503115031
Clazz._isQuietLoad = false;
1503215032
J2S._wasmPath = libPath;
1503315033
var src = libPath + libName + ".js";
15034-
$.getScript(src, function() {jnainchiModule().then(
15035-
function(module){
15036-
J2S._module = module;
15037-
for (var i = 0; i < funcs.length; i++) {
15038-
funcs[i].apply(null, [module]);
15039-
}
15040-
cls.wasmInitialized = true;
15041-
})
15042-
});
15034+
var f = function(module){
15035+
J2S._module = module;
15036+
for (var i = 0; i < funcs.length; i++) {
15037+
funcs[i].apply(null, [module]);
15038+
}
15039+
cls.wasmInitialized = true;
15040+
}
15041+
// may have been preloaded by other JavaScript
15042+
var module = J2S[libName + "_module"]
15043+
if (module)
15044+
f(module);
15045+
else
15046+
$.getScript(src, function() {jnainchiModule().then(function(module) { f(module) })});
1504315047
}
1504415048

1504515049
Clazz.newClass = function (prefix, name, clazz, clazzSuper, interfacez, type) {

0 commit comments

Comments
 (0)