Skip to content

Commit 7104256

Browse files
authored
Merge pull request #232 from BobHanson/master
various updates
2 parents b3db746 + 61b4fc1 commit 7104256

Some content is hidden

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

78 files changed

+5086
-1336
lines changed
Binary file not shown.
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-
20240225103130
1+
20241217101652
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-
20240225103130
1+
20241217101652

sources/net.sf.j2s.core/src/j2s/CorePlugin.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ public class CorePlugin extends Plugin {
2626
* the actual "x.y.z" version is specified in plugin.xml.
2727
*
2828
*/
29-
public static String VERSION = "5.0.1-v2";
29+
public static String VERSION = "5.0.1-v4";
3030

3131
// if you change the x.x.x number, be sure to also indicate that in
3232
// j2sApplet.js and also (Bob only) update.bat, update-clean.bat
3333

34+
// BH 2024.07.14 -- 5.0.1-v4 fixes numerical array initializer using characters ['a','b',...]
35+
// BH 2024.02.22 -- 5.0.1-v3 fixes long extension issue causing MutableBitInteger to miscalculate subtraction(no change in version #)
3436
// BH 2023.11.27 -- 5.0.1-v2 final refactoring and creatiton of J2SUtil
3537
// BH 2023.11.21 -- 5.0.1-v2 adds Java8 syntaxes for try and switch; removes dependency for instanceOf and exception checking
3638
// BH 2023.11.09 -- 5.0.1-v1 merges Jmol legacy (.j2sjmol) with Java8//11 (.j2s)

sources/net.sf.j2s.core/src/j2s/jmol/J2SLegacyVisitor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2100,7 +2100,7 @@ public boolean visit(ArrayCreation node) {
21002100
buffer.append(" Clazz.newBooleanArray(");
21012101
boxList(dim, ", ");
21022102
buffer.append(", false)");
2103-
} else {
2103+
} else {
21042104
if (dim != null && dim.size() > 1) {
21052105
buffer.append(" Clazz.newArray(");
21062106
boxList(dim, ", ");
@@ -2140,6 +2140,8 @@ public boolean visit(ArrayInitializer node) {
21402140
buffer.append("]");
21412141
return false;
21422142
}
2143+
// note that this does NOT allow for new byte[] {'a', 'b', 'c'}
2144+
// only implemented that for SwingJS
21432145
if (elementType.isPrimitive()) {
21442146
String typeCode = elementType.getName();
21452147
if ("int".equals(typeCode)

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

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
// TODO: superclass inheritance for JAXB XmlAccessorType
3232
// TODO: Transpiler bug allows static String name, but JavaScript function().name is read-only and will be "clazz"
3333

34-
//BH 2024.02.22 -- 3.3.1-v7 fixes long extension issue causing MutableBitInteger to miscalculate subtraction(no change in version #)
34+
//BH 2024.07.14 -- 5.0.1-v4 fixes numerical array initializer using characters ['a','b',...], but not new int[] { "test".charAt(3) }
35+
//BH 2024.02.22 -- 5.0.1-v3 fixes long extension issue causing MutableBitInteger to miscalculate subtraction(no change in version #)
36+
//BH 2023.11.27 -- 5.0.1-v2 final refactoring and creatiton of J2SUtil
37+
//BH 2023.11.21 -- 5.0.1-v2 adds Java8 syntaxes for try and switch; removes dependency for instanceOf and exception checking
38+
//BH 2023.11.09 -- 5.0.1-v1 merges Jmol legacy (.j2sjmol) with Java8//11 (.j2s)
3539
//BH 2023.03.29 -- 3.3.1-v7 fixes outer static method call from within lambda expression.
3640
//BH 2023.02.09 -- 3.3.1.v6 fixes j2s.excluded.paths needing /src/xxxx
3741
//BH 2022.06.27 -- 3.3.1-v5 fixes missing method annotations
@@ -3015,15 +3019,63 @@ private void addArrayConstructor(ITypeBinding binding, List<ASTNode> dim) {
30153019

30163020
public boolean visit(ArrayInitializer node) {
30173021
// as in: public String[] d = {"1", "2"};
3018-
buffer.append(clazzArray(node.resolveTypeBinding(), ARRAY_INITIALIZED));
3022+
ITypeBinding type = node.resolveTypeBinding();
3023+
buffer.append(clazzArray(type, ARRAY_INITIALIZED));
30193024
buffer.append(", [");
3025+
int toChar = toCharType(type);
30203026
@SuppressWarnings("unchecked")
3021-
List<ASTNode> expressions = node.expressions();
3022-
visitList(expressions, ", ");
3027+
List<ASTNode> ex = node.expressions();
3028+
if (toChar == 0) {
3029+
visitList(ex, ", ");
3030+
} else {
3031+
fixCharArrayInit(buffer, ex, toChar);
3032+
}
30233033
buffer.append("])");
30243034
return false;
30253035
}
30263036

3037+
private static int toCharType(ITypeBinding type) {
3038+
switch (type == null ? "" : type.getName()) {
3039+
case "char[]":
3040+
return 1;
3041+
case "byte[]":
3042+
case "short[]":
3043+
case "int[]":
3044+
case "long[]":
3045+
case "float[]":
3046+
case "double[]":
3047+
return -1;
3048+
default:
3049+
return 0;
3050+
}
3051+
}
3052+
3053+
private void fixCharArrayInit(StringBuffer buffer, List<ASTNode> list, int toChar) {
3054+
for (Iterator<ASTNode> iter = list.iterator(); iter.hasNext();) {
3055+
int pt = buffer.length();
3056+
appendBoxingNode(iter.next(), false, null, false, false);
3057+
if (toChar != 0) {
3058+
String s = buffer.substring(pt);
3059+
// only fix "x" and number
3060+
// not fixed: int[] a = new int[] {"test".charAt(0)}
3061+
try {
3062+
if (pt > 0 && (s.charAt(0) == '"') != (toChar == 1)) {
3063+
buffer.replace(pt, buffer.length(),
3064+
(toChar == 1 ?
3065+
"\"" + ((char) Integer.parseInt(s)) + "\""
3066+
: s.length() == 3 ? "" + (byte) s.charAt(1) : s)
3067+
);
3068+
}
3069+
} catch (@SuppressWarnings("unused") Exception e) {
3070+
// ignore
3071+
}
3072+
}
3073+
if (!iter.hasNext())
3074+
return;
3075+
buffer.append(", ");
3076+
}
3077+
}
3078+
30273079
public boolean visit(Assignment node) {
30283080
// note that this is not
30293081
// var x = ..... -- that is a visit(VariableDeclaration)
@@ -4431,8 +4483,6 @@ private void addNonCharacter(Expression exp) {
44314483
switch (name) {
44324484
case "char":
44334485
case "Character":
4434-
addOperand(exp, false);
4435-
break;
44364486
case "Byte":
44374487
case "Short":
44384488
case "Integer":
Binary file not shown.
-223 KB
Binary file not shown.
Binary file not shown.

sources/net.sf.j2s.java.core/site-resources_4.2/jsmol/js/JSmolJavaExt.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,8 @@ return buf.join('');
10021002

10031003
if(String.prototype.$replace==null){
10041004
java.lang.String=String;
1005+
Clazz._setDeclared("String", String);
1006+
10051007
if(Clazz._supportsNativeObject){
10061008
for(var i=0;i<Clazz._extendedObjectMethods.length;i++){
10071009
var p=Clazz._extendedObjectMethods[i];
@@ -1075,9 +1077,7 @@ for(i=0;i<arr.length-1;i++){
10751077
funStr+="\""+arr[i]+"\" + $"+orders[i]+" + ";
10761078
}
10771079
funStr+="\""+arr[i]+"\"; }";
1078-
var f=null;
1079-
eval(funStr)
1080-
return f;
1080+
return eval(funStr);
10811081
};
10821082

10831083
sp.replaceAll=function(exp,str){
@@ -1666,6 +1666,8 @@ c$.get = function(o, i){return o[i]};
16661666
javautil.Date=Date;
16671667
Date.TYPE="javautil.Date";
16681668
Date.__CLASS_NAME__="Date";
1669+
Clazz._setDeclared("java.util.Date", Date);
1670+
Clazz._setDeclared("Date", Date);
16691671
Clazz.implementOf(Date,[java.io.Serializable,java.lang.Comparable]);
16701672
Clazz.defineMethod(javautil.Date,"clone",
16711673
function(){

0 commit comments

Comments
 (0)