Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip
Binary file not shown.
Binary file modified sources/net.sf.j2s.core/dist/swingjs/net.sf.j2s.core.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20190829124003
20190907142751
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/SwingJS-site.zip
Binary file not shown.
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/net.sf.j2s.core.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20190829124003
20190907142751
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
import org.eclipse.jdt.core.dom.WhileStatement;
import org.eclipse.jdt.core.dom.WildcardType;

// BH 2019.09.07 adds optimization for lambda methods that do not have finals
// BH 2019.08.29 fix for boxing of binary representation 0b01... (Google Closure Compiler bug)
// BH 2019.05.13 fix for Math.getExponent, ulp, nextDown, nextUp, nextAfter needing qualification
// BH 2019.05.13 fix for Function reference in new Foo()::test(...)
Expand Down Expand Up @@ -163,6 +164,12 @@ public class Java2ScriptVisitor extends ASTVisitor {
*/
private static final boolean ALLOW_NEW_LAMBDA = false;

/**
* If there are no finals for a lambda method, then we can reuse the object.
* This can be huge for preventing repetitive object creation
*/
private static final boolean ALLOW_LAMBDA_OBJECT_REUSE = true;

private static final int NOT_LAMBDA = 0;
private static final int LAMBDA_METHOD = 1;
private static final int LAMBDA_CREATION = 3;
Expand Down Expand Up @@ -657,8 +664,10 @@ private String getClassJavaNameForType(Type type) {
* anonymous class names
* @param isLambda
* @param isClassTrulyLocal
*
* @return anonymous name only if there are no finals
*/
private void processLocalInstance(ASTNode node, ASTNode anonymousClassDeclaration, ITypeBinding binding,
private String processLocalInstance(ASTNode node, ASTNode anonymousClassDeclaration, ITypeBinding binding,
ITypeBinding innerClass, String javaInnerClassName, int lambdaType, boolean isClassTrulyLocal) {

// In the case of local classes, the declaration is dissociated from the
Expand Down Expand Up @@ -701,6 +710,7 @@ private void processLocalInstance(ASTNode node, ASTNode anonymousClassDeclaratio
anonymousSuperclassName, anonName);
if (lambdaType != LAMBDA_METHOD && !isClassTrulyLocal)
buffer.append(")"); // end of line (..., ...)
return finals == null ? anonName : null;
}

/**
Expand Down Expand Up @@ -6808,15 +6818,19 @@ private boolean addLambdaMethodReference(MethodReference node, Expression exp) {
*/
private boolean addLambda$class$Method(MethodReference node, ITypeBinding binding, Expression exp,
ITypeBinding declaringClass, boolean checkFinals) {


allowClazzNewLambda = (ALLOW_NEW_LAMBDA && getLastCharInBuffer() != '=');
int pt = buffer.length();
buffer.append("(function($class$){");
processLocalInstance(node, null, binding, null, null, LAMBDA_METHOD, false);
String anonName = processLocalInstance(node, null, binding, null, null, LAMBDA_METHOD, false);
buffer.append("})(");
appendFinalMethodQualifier(exp, declaringClass, null, FINAL_ESCAPECACHE | FINAL_LAMBDA);
buffer.append(")");
if (checkFinals && allowClazzNewLambda)
buffer.setLength(pt);
if (anonName != null && ALLOW_LAMBDA_OBJECT_REUSE)
addLambdaReuse(pt, anonName);
return !allowClazzNewLambda;

}
Expand Down Expand Up @@ -6871,12 +6885,28 @@ public boolean visit(LambdaExpression node) {
private boolean addLambda$class$Expr(LambdaExpression node, ITypeBinding binding, boolean checkFinals) {
allowClazzNewLambda = (ALLOW_NEW_LAMBDA && getLastCharInBuffer() != '=');
int pt = buffer.length();
processLocalInstance(node, null, binding, null, null, LAMBDA_EXPRESSION, false);
String anonName = processLocalInstance(node, null, binding, null, null, LAMBDA_EXPRESSION, false);
if (checkFinals && allowClazzNewLambda)
buffer.setLength(pt);
if (anonName != null && ALLOW_LAMBDA_OBJECT_REUSE)
addLambdaReuse(pt, anonName);
return !allowClazzNewLambda;
}

/**
* allow reuse of Lambda method and expression objects when they involve no finals
*
* @param pt
* @param anonName
*/
private void addLambdaReuse(int pt, String anonName) {
String tmp = buffer.substring(pt);
buffer.setLength(pt);
anonName = getFinalJ2SClassName(anonName, FINAL_P);
buffer.append("(" + anonName + "$||(" + anonName + "$=(")
.append(tmp).append(")))");
}

private char getLambdaType(ITypeBinding binding) {
String name = removeBracketsAndFixNullPackageName(getJavaClassNameQualified(binding));
if (!name.startsWith("java.util.function.") || name.indexOf("To") >= 0)
Expand Down
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,13 @@ private static PreferencesFactory factory1() {
// 3. Use platform-specific system-wide default
String osName = System.getProperty("os.name");
String platformFactory;
if (osName.startsWith("Windows")) {
platformFactory = "java.util.prefs.WindowsPreferencesFactory";
} else if (osName.contains("OS X")) {
platformFactory = "java.util.prefs.MacOSXPreferencesFactory";
} else {
// if (osName.startsWith("Windows")) {
// platformFactory = "java.util.prefs.WindowsPreferencesFactory";
// } else if (osName.contains("OS X")) {
// platformFactory = "java.util.prefs.MacOSXPreferencesFactory";
// } else {
platformFactory = "java.util.prefs.FileSystemPreferencesFactory";
}
// }
try {
return (PreferencesFactory)
Class.forName(platformFactory, false,
Expand Down
6 changes: 6 additions & 0 deletions sources/net.sf.j2s.java.core/src/test/Test_.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ class Test_ {
private int t = 0;

public int showt() {
if (true && (/**@j2sNative 1? test : */false)) {

}
System.out.println(t);
if (false || (/**@j2sNative test || */false)) {

}
return t;
}

Expand Down
Loading