Skip to content

Commit cea4ced

Browse files
hansonrhansonr
authored andcommitted
2 of 2 net.sf.j2s.core_3.2.1.jar adds Java 8 functionality (new files):
the "::" operator lambda expressions java.util.function.* java.util.stream.* default methods in interfaces
1 parent b16b89c commit cea4ced

File tree

93 files changed

+31952
-31
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+31952
-31
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false

sources/net.sf.j2s.core/README.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The seed Eclipse project site/ directory for all SwingJS projects can be found a
66

77
https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.java.core/SwingJS-site.zip?raw=true
88

9+
this file is old. See dist/dropins/README.txt
910

1011
Known issues: 2/2018
1112

sources/net.sf.j2s.core/dist/README.txt

Lines changed: 86 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,32 @@ SwingJS distribution
22

33
https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/dropins/README.txt
44

5-
7/15/2018 Bob Hanson hansonr@stolaf.edu
5+
7/20/2018 Bob Hanson hansonr@stolaf.edu
6+
7+
The base Java version is Java 6. However, many of the functionalities of Java 7 and Java 8 are included.
8+
This includes
9+
10+
the "::" operator
11+
lambda expressions
12+
java.util.function.*
13+
java.util.stream.*
14+
default methods in interfaces
15+
16+
All projects compiled under 3.1.1 need to be recompiled using the Java2Script 3.2.1 transpiler, as
17+
described below. Note that if you use /** @j2sNative */ calls to interface methods that are singlets,
18+
you no longer need to add qualifications (such as $O) to them. It should be no problem to leave them
19+
qualified, though, as the transpiler creates qualified and unqualified aliases.
20+
21+
There are situations where this use of unqualified method names can run into problems. For example, in
22+
java.util.stream.ReferencePipeline, there are three different declarations of the functional interface
23+
method "accept". They were just for erro reporting and have been removed.
24+
My guess that this is a rarity, but I am not sure.
25+
26+
27+
SwingJS has been successfully tested in Eclipse version Neon-Photon on Mac and Windows platforms.
28+
(No reason to believe it would not also work for Linux; just haven't tried that recently.)
29+
Java 8 is the target Java version for transpilation. Please report any missing classes or strange
30+
errors.
631

732
net.sf.j2s.core_3.2.1.jar replaces net.sf.j2s.core_3.1.1.jar
833

@@ -11,7 +36,7 @@ Most importantly, the requirement that the .project file be changed to
1136
indicate a customized Java builder is dropped in version 3.2.1, which just uses
1237
the standard Eclipse java builder, org.eclipse.jdt.core.javabuilder.
1338

14-
Thus, to get started, all you need are:
39+
For v. 3.2.1, to get started with SwingJS, all you need are:
1540

1641
1) the latest transpiler from
1742

@@ -31,8 +56,6 @@ or your project will no longer compile.
3156

3257
Comments below have been adjusted for these differences.
3358

34-
SwingJS has been successfully tested in Eclipse version Neon-Photon on Mac and Windows platforms.
35-
(No reason to believe it would not also work for Linux; just haven't tried that recently.)
3659

3760
INSTALLATION INSTRUCTIONS
3861

@@ -77,6 +100,10 @@ On Mac systems, the Eclipse directory is generally
77100
2. Restart Eclipse and check for the presence of the plug-in at
78101
help...about Eclipse...installation details...Plug-ins...(wait several seconds for tabulation)
79102

103+
Search for "j2s" to find j2s.sourceforge.net Java2Script Core
104+
105+
If that is not there, you don't have net.sf.j2s.core.jar in the proper directory.
106+
80107
Note relating to updating to 3.2.1 from 3.1.1 version of Java2Script:
81108

82109
If the version on this readout does not match the version that is
@@ -88,10 +115,6 @@ On Mac systems, the Eclipse directory is generally
88115
Eclipse once with the -clean flag.
89116

90117

91-
search for "j2s" to find j2s.sourceforge.net Java2Script Core
92-
93-
If that is not there, you don't have net.sf.j2s.core.jar in the proper directory.
94-
95118

96119
----------------------------------
97120
Creating a new J2S/SwingJS project
@@ -101,7 +124,7 @@ Create an Eclipse Java project for your work, if you have not done so already.
101124
If your source code is not all already in src/, navigate to the project...properties...
102125
Java Build Path...source and add all the source directories you need.
103126

104-
Note that your project must not include any Jar file based dependencies.
127+
Note that your project must not include any Jar file-based dependencies.
105128
All source code must be available. (Source code from decompiling .class files will work.)
106129

107130

@@ -124,36 +147,32 @@ Simply download and unzip that file into your project, creating a top-level site
124147
Enabling the Java2Script/SwingJS transpiler
125148
-------------------------------------------
126149

127-
1. Create in your Eclipse project the file:
150+
1. Create in your Eclipse project the empty file:
128151

129152
.j2s
130153

131-
containing simply:
154+
The next time you build the project, the transpiler will see that and
155+
add to it:
132156

133157
j2s.compiler.status=enable
158+
j2s.site.directory=site
134159

135-
2. Edit the .project file to indicate that the j2s transpiler is to be used
136-
rather than the standard Java compiler by changing the buildSpec buildCommand from
137-
138-
org.eclipse.jdt.core.javabuilder
139-
140-
to
141-
142-
net.sf.j2s.core.java2scriptbuilder
143-
160+
along with several other commented-out options. If you want, you can
161+
add these two yourself before you run the transpiler.
144162

145163
--------------------
146164
Building the project
147165
--------------------
148166

149167
Build your project as you normally would. Java class files will be created as usual in the bin/ directory.
150168
JavaScript equivalents of these files will be created in the site/swingjs/j2s directory. You might have to
151-
do a project refresh to see these site files.
169+
do a project refresh to see these site files. If you open one in Eclipse, notice that each time you build
170+
the project (for example by saving a changed Java file with Project...Save Automatically set), Eclipse
171+
will prompt you to reload this file with changes.
152172

153173
Do take a look at the .js files created. You will notice that they are all the methods and fields of your
154-
Java project *except* final static constants. SwingJS does not recreate those by name; it just uses them.
155-
(The only thing this should affect is that java.lang.reflect.Field does not indicate these names.)
156-
174+
Java project *except* final static constants. SwingJS does not recreate final static constants by name;
175+
It just uses them. This means that the java.lang.reflect.Field methods will not indicate these names.
157176

158177
----------------------------------------------
159178
Testing the JavaScript version of your project
@@ -163,7 +182,34 @@ The J2S transpiler will automatically set up for you in site/ a sample HTML page
163182
that subclasses JApplet or contains a public void main(String[] args) method. You will want to
164183
associate those files with an external HTML browser. We recommend Firefox.
165184

166-
Since you will be running AJAX locally within these browsers, you may need to enable local
185+
Do not change these files, as they will be recreated each time the transpiler runs. If you want
186+
a different configuration -- a different width or height, or some additional "applet" parameters,
187+
make a copy of this file and change within it the Info block:
188+
189+
Info = {
190+
code: _CODE_,
191+
main: _MAIN_,
192+
width: 850,
193+
height: 550,
194+
readyFunction: null,
195+
serverURL: 'https://chemapps.stolaf.edu/jmol/jsmol/php/jsmol.php',
196+
j2sPath: 'swingjs/j2s',
197+
console:'sysoutdiv',
198+
allowjavascript: true
199+
}
200+
201+
These Info key/value pairs are equivalent to Java applet parameters. Use Info.args for the main(args[])
202+
parameters. For instance:
203+
204+
args:["test","true"],
205+
206+
The serverURL reference allows for reading files in AJAX from servers that are not configured with
207+
208+
access-control-origin: *
209+
210+
You can try removing that if you want to.
211+
212+
Since you will be running AJAX locally within your browser, you may need to enable local
167213
file reading in your browser. Instructions for doing that can be found at
168214
http://wiki.jmol.org/index.php/Troubleshooting/Local_Files
169215

@@ -176,9 +222,13 @@ If you find you are missing a Java class, please contact me (Bob Hanson) at hans
176222
You can try adding these yourself by **temporarily** adding one or more of the Java classes found
177223
at http://grepcode.com to the proper package in your project. For example, java/awt.
178224

179-
If you do that, be sure to use the OpenJDK version. Most of the code in the SwingJS project started with
180-
Java 6-b14 or 6-b27. Build your project, then delete these Java files, because you do not necessarily
181-
want your Java code using that version, just JavaScript.
225+
If you do that, be sure to use the OpenJDK version. For example:
226+
227+
http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes
228+
229+
Most of the code in the SwingJS project started with
230+
Java 6-b14 or 6-b27. Build your project, then delete these Java files, because, should this file be added
231+
to an updated verison of SwingJS, you should probably use the one provided, not your own. Your choice.
182232

183233

184234
----------------
@@ -198,15 +248,20 @@ working site is https://chemapps.stolaf.edu/swingjs/physlets
198248

199249
Phet applets have not been put on GitHub yet.
200250

251+
Note that these sites use an older v. 3.1.1 transpiler and runtime.
201252

253+
Feb. 17, 2018
202254

203-
As of Feb. 17, 2018, we are actively converting a variety of functioning Java applets.
255+
We are actively converting a variety of functioning Java applets.
204256

205257
The physlets Animator, Doppler, and Optics are working.
206258

207-
As of Jan. 2, 2018, all known Java-to-JavaScript issues have been dealt with.
259+
Jan. 2, 2018
260+
208261
Efficient Google Closure Compiler compression is in place.
209262

210-
As of Dec. 17, 2017, SwingJS is fully operational in its "version 2" format,
263+
Dec. 17, 2017
264+
265+
SwingJS is fully operational in its "version 2" format (still v. 3.1.1),
211266
which includes fully qualified method, array, and number typing.
212267

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2018-07-19_0557 AM
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
3+
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
4+
*
5+
*
6+
*
7+
*
8+
*
9+
*
10+
*
11+
*
12+
*
13+
*
14+
*
15+
*
16+
*
17+
*
18+
*
19+
*
20+
*
21+
*
22+
*
23+
*
24+
*/
25+
26+
package java.lang;
27+
28+
/**
29+
* An object that may hold resources (such as file or socket handles)
30+
* until it is closed. The {@link #close()} method of an {@code AutoCloseable}
31+
* object is called automatically when exiting a {@code
32+
* try}-with-resources block for which the object has been declared in
33+
* the resource specification header. This construction ensures prompt
34+
* release, avoiding resource exhaustion exceptions and errors that
35+
* may otherwise occur.
36+
*
37+
* @apiNote
38+
* <p>It is possible, and in fact common, for a base class to
39+
* implement AutoCloseable even though not all of its subclasses or
40+
* instances will hold releasable resources. For code that must operate
41+
* in complete generality, or when it is known that the {@code AutoCloseable}
42+
* instance requires resource release, it is recommended to use {@code
43+
* try}-with-resources constructions. However, when using facilities such as
44+
* {@link java.util.stream.Stream} that support both I/O-based and
45+
* non-I/O-based forms, {@code try}-with-resources blocks are in
46+
* general unnecessary when using non-I/O-based forms.
47+
*
48+
* @author Josh Bloch
49+
* @since 1.7
50+
*/
51+
public interface AutoCloseable {
52+
/**
53+
* Closes this resource, relinquishing any underlying resources.
54+
* This method is invoked automatically on objects managed by the
55+
* {@code try}-with-resources statement.
56+
*
57+
* <p>While this interface method is declared to throw {@code
58+
* Exception}, implementers are <em>strongly</em> encouraged to
59+
* declare concrete implementations of the {@code close} method to
60+
* throw more specific exceptions, or to throw no exception at all
61+
* if the close operation cannot fail.
62+
*
63+
* <p> Cases where the close operation may fail require careful
64+
* attention by implementers. It is strongly advised to relinquish
65+
* the underlying resources and to internally <em>mark</em> the
66+
* resource as closed, prior to throwing the exception. The {@code
67+
* close} method is unlikely to be invoked more than once and so
68+
* this ensures that the resources are released in a timely manner.
69+
* Furthermore it reduces problems that could arise when the resource
70+
* wraps, or is wrapped, by another resource.
71+
*
72+
* <p><em>Implementers of this interface are also strongly advised
73+
* to not have the {@code close} method throw {@link
74+
* InterruptedException}.</em>
75+
*
76+
* This exception interacts with a thread's interrupted status,
77+
* and runtime misbehavior is likely to occur if an {@code
78+
* InterruptedException} is {@linkplain Throwable#addSuppressed
79+
* suppressed}.
80+
*
81+
* More generally, if it would cause problems for an
82+
* exception to be suppressed, the {@code AutoCloseable.close}
83+
* method should not throw it.
84+
*
85+
* <p>Note that unlike the {@link java.io.Closeable#close close}
86+
* method of {@link java.io.Closeable}, this {@code close} method
87+
* is <em>not</em> required to be idempotent. In other words,
88+
* calling this {@code close} method more than once may have some
89+
* visible side effect, unlike {@code Closeable.close} which is
90+
* required to have no effect if called more than once.
91+
*
92+
* However, implementers of this interface are strongly encouraged
93+
* to make their {@code close} methods idempotent.
94+
*
95+
* @throws Exception if this resource cannot be closed
96+
*/
97+
void close() throws Exception;
98+
}

0 commit comments

Comments
 (0)