Skip to content
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
20190923090813
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
20190923090813
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class Java2ScriptCompiler {

private IJavaProject project;

private boolean isDebugging;

static boolean isActive(IJavaProject project) {
try {
return new File(project.getProject().getLocation().toOSString(), J2S_OPTIONS_FILE_NAME).exists();
Expand Down Expand Up @@ -152,6 +154,8 @@ boolean initializeProject(IJavaProject project, boolean isCompilationParticipant
siteFolder = projectFolder + "/" + siteFolder;
j2sPath = siteFolder + "/swingjs/j2s";

if (isDebugging)
System.out.println("Java2ScriptCompiler writing to " + j2sPath);
// method declarations and invocations are only logged
// when the designated files are deleted prior to building

Expand Down Expand Up @@ -199,7 +203,7 @@ boolean initializeProject(IJavaProject project, boolean isCompilationParticipant
if (nonqualifiedPackages.length() == 0)
nonqualifiedPackages = null;
// includes @j2sDebug blocks
boolean isDebugging = "debug".equals(getProperty("j2s.compiler.mode"));
isDebugging = "debug".equals(getProperty("j2s.compiler.mode"));

String classReplacements = getProperty("j2s.class.replacements");

Expand Down Expand Up @@ -375,7 +379,10 @@ private void createJSFile(String j2sPath, String packageName, String elementName
}
}
}
writeToFile(new File(j2sPath, elementName + ".js"), js);
File f = new File(j2sPath, elementName + ".js");
if (isDebugging)
System.out.println("Java2ScriptCompiler creating " + f);
writeToFile(f, js);
}

private String getFileContents(File file) {
Expand Down
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.
3 changes: 2 additions & 1 deletion sources/net.sf.j2s.java.core/src/java/io/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,8 @@ public boolean isDirectory() {
// return ((fs.getBooleanAttributes(this) & FileSystem.BA_DIRECTORY)
// != 0);
//
return true;
// BH 2019.09.23 return true;
return false;
}

/**
Expand Down
107 changes: 107 additions & 0 deletions sources/net.sf.j2s.java.core/src/java/io/ObjectInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.io;

/**
* ObjectInput extends the DataInput interface to include the reading of
* objects. DataInput includes methods for the input of primitive types,
* ObjectInput extends that interface to include objects, arrays, and Strings.
*
* @author unascribed
* @see java.io.InputStream
* @see java.io.ObjectOutputStream
* @see java.io.ObjectInputStream
* @since JDK1.1
*/
public interface ObjectInput extends DataInput, AutoCloseable {
/**
* Read and return an object. The class that implements this interface
* defines where the object is "read" from.
*
* @return the object read from the stream
* @exception java.lang.ClassNotFoundException If the class of a serialized
* object cannot be found.
* @exception IOException If any of the usual Input/Output
* related exceptions occur.
*/
public Object readObject()
throws ClassNotFoundException, IOException;

/**
* Reads a byte of data. This method will block if no input is
* available.
* @return the byte read, or -1 if the end of the
* stream is reached.
* @exception IOException If an I/O error has occurred.
*/
public int read() throws IOException;

/**
* Reads into an array of bytes. This method will
* block until some input is available.
* @param b the buffer into which the data is read
* @return the actual number of bytes read, -1 is
* returned when the end of the stream is reached.
* @exception IOException If an I/O error has occurred.
*/
public int read(byte b[]) throws IOException;

/**
* Reads into an array of bytes. This method will
* block until some input is available.
* @param b the buffer into which the data is read
* @param off the start offset of the data
* @param len the maximum number of bytes read
* @return the actual number of bytes read, -1 is
* returned when the end of the stream is reached.
* @exception IOException If an I/O error has occurred.
*/
public int read(byte b[], int off, int len) throws IOException;

/**
* Skips n bytes of input.
* @param n the number of bytes to be skipped
* @return the actual number of bytes skipped.
* @exception IOException If an I/O error has occurred.
*/
public long skip(long n) throws IOException;

/**
* Returns the number of bytes that can be read
* without blocking.
* @return the number of available bytes.
* @exception IOException If an I/O error has occurred.
*/
public int available() throws IOException;

/**
* Closes the input stream. Must be called
* to release any resources associated with
* the stream.
* @exception IOException If an I/O error has occurred.
*/
public void close() throws IOException;
}
Loading