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);

0 commit comments

Comments
 (0)