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
The table of contents is too big for display.
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 @@
20181204022550
20181213165944
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 @@
20181204022550
20181213165944
49 changes: 46 additions & 3 deletions sources/net.sf.j2s.core/src/net/sf/j2s/core/CorePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,62 @@ public class CorePlugin extends Plugin {
* register the bundle version properly. So we use VERSION here instead.
*
*/
public static String VERSION = "3.2.4.04";
public static String VERSION = "3.2.4.05";
// BH 12/13/2018 -- 3.2.4.05 fixes problem with OuterClass.this.foo() not using .apply()
// BH 11/10/2018 -- 3.2.4.04 additional support for JAXB
// BH 11/04/2018 -- 3.2.4.02 support for JAXB - all accessor types, ObjectFactory, package-level namespace, but not yet accessor type
// BH 11/4/2018 -- 3.2.4.02 broad JAXB support
// BH 10/27/2018 -- 3.2.4.01 support for JAXB FIELD+propOrder and NONE types
// BH 9/28/2018 -- 3.2.4.00 adds minimal support for JAXB
// BH 9/23/2018 -- 3.2.3.00 new transpiler + SwingJS-site.zip - support for java.applet.Applet and java.awt.* controls without use of a2s.*
// BH 9/23/2018 -- 3.2.3.00 adds support for java.applet.Applet and java.awt.* controls without use of a2s.*
// BH 9/16/2018 -- 3.2.2.06 removes "$" in JApplet public method alternative name
// 3.2.2.04 2018.08.15 fixing Java->JavaScript "getFinal" code for class names.
// 3.2.2.04 adds support for window-level applets, such as JmolApplet
// 3.2.2.03 adds Java 8 function and stream
// 3.2.2.02 adds $-qualified names for all methods
// BH 8/20/2018 -- fix for return (short)++;
// BH 8/19/2018 -- refactored to simplify $finals$
// BH 8/12/2018 -- refactored to simplify naming issues
// BH 8/6/2018 -- additional Java 8 fixes; enum $valueOf$S to valueOf$S
// BH 8/1/2018 -- adds interface default methods as C$.$defaults$(C$)
// BH 7/29/2018 -- java.util.stream.Collectors is returning java.util.Collectionthis.b$['java.util.Collection'].add
// BH 7/25/2018 -- allows for direct private function calls in inner and anonymous classes using var p$, p$$, p$$$, etc
// BH 7/22/2018 -- fixes improper use of charCodeAt() to replace charCode().$c() when not java.lang.String.charAt
// BH 7/20/2018 -- removes qualifications for single-abstract method overrides
// BH 7/19/2018 -- fixes Enum.Enum
// BH 7/18/2018 -- addw Java 8 try without catch or finally
// BH 7/16/2018 -- adds Java 8 :: operator
// BH 7/15/2018 -- adds Java 8 lambda expressions
// BH 7/14/2018 -- removes java2scriptbuilder; uses CompilationParticipant instead
// BH 7/5/2018 -- fixes int | char
// BH 7/3/2018 -- adds tryWithResource
// BH 7/3/2018 -- adds effectively final -- FINAL keyword no longer necessary
// BH 6/27/2018 -- fix for a[Integer] not becoming a[Integer.valueOf]
// BH 6/26/2018 -- method logging via j2s.log.methods.called and j2s.log.methods.declared
// BH 6/24/2018 -- synchronized(a = new Object()) {...} ---> ...; only if an assignment or not a simple function call to Object.getTreeLock()
// BH 6/23/2018 -- synchronized(a = new Object()) {...} ---> if(!(a = new Object()) {throw new NullPointerException()}else{...}
// BH 6/21/2018 -- CharSequence.subSequence() should be defined both subSequence$I$I and subSequence
// BH 6/20/2018 -- fixes for (int var : new int[] {3,4,5}) becoming for var var
// BH 6/19/2018 -- adds .j2s j2s.class.replacements=org.apache.log4j.->jalview.javascript.log4j.;
// BH 5/15/2018 -- fix for a[pt++] |= 3 incrementing pt twice and disregarding a[][] (see test/Test_Or.java)
// BH 3/27/2018 -- fix for anonymous inner classes of inner classes not having this.this$0
// BH 1/5/2018 -- @j2sKeep removed; refactored into one class
// BH 12/31/2017 -- competely rewritten for no run-time ambiguities
// BH 9/10/2017 -- adds full byte, short, and int distinction using class-level local fields $b$, $s$, and $i$, which are IntXArray[1]. (See ASTKeywordVisitor)
// BH 9/7/2017 -- primitive casting for *=,/=,+=,-=,&=,|=,^=
// BH 9/7/2017 -- primitive numeric casting -- (byte) was ignored so that (byte) 0xFF remained 0xFF.
// BH 9/7/2017 -- fixed multiple issues with char and Character
// BH 9/4/2017 -- java.awt, javax.swing, swingjs code added; additional fixes required
// BH 8/30/2017 -- all i/o working, including printf and FileOutputStream
// BH 8/19/2017 -- String must implement CharSequence, so all .length() -> .length$()
// BH 8/19/2017 -- varargs logic fixed for missing argument
// BH 8/18/2017 -- array instanceof, reflection, componentType fixes
// BH 8/16/2017 -- JSE8-UnionType catch (Exception... | Exception...) {...}
// BH 8/13/2017 -- includes native code calls in System.err
// BH 7/31/2017 -- extensively reworked for fully qualified method names and no SAEM
// 3.2.1.01 original SwingJS version through 2017 adds $-signatures for methods
// 3.1.1 last Zhou Renjian unqualified name version


/**
* The constructor.
*/
Expand Down
116 changes: 28 additions & 88 deletions sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,54 +139,6 @@
// as a need to recompile automatically
// TODO: Create a j2s configuration tag "j2s.jaxb.packages= package;package;package..."
// that will direct the transpiler to create __ANN__ in any class within this package.
// BH 11/4/2018 -- 3.2.4.02 broad JAXB support
// BH 10/27/2018 -- 3.2.4.01 support for JAXB FIELD+propOrder and NONE types
// BH 9/28/2018 -- 3.2.4.00 adds minimal support for JAXB
// BH 9/23/2018 -- 3.2.3.00 adds support for java.applet.Applet and java.awt.* controls without use of a2s.*
// BH 9/16/2018 -- 3.2.2.06 removes "$" in JApplet public method alternative name
// BH 8/20/2018 -- fix for return (short)++;
// BH 8/19/2018 -- refactored to simplify $finals$
// BH 8/12/2018 -- refactored to simplify naming issues
// BH 8/6/2018 -- additional Java 8 fixes; enum $valueOf$S to valueOf$S
// BH 8/1/2018 -- adds interface default methods as C$.$defaults$(C$)
// BH 7/29/2018 -- java.util.stream.Collectors is returning java.util.Collectionthis.b$['java.util.Collection'].add

// BH 7/25/2018 -- allows for direct private function calls in inner and anonymous classes using var p$, p$$, p$$$, etc
// BH 7/22/2018 -- fixes improper use of charCodeAt() to replace charCode().$c() when not java.lang.String.charAt
// BH 7/20/2018 -- removes qualifications for single-abstract method overrides
// BH 7/19/2018 -- fixes Enum.Enum
// BH 7/18/2018 -- addw Java 8 try without catch or finally
// BH 7/16/2018 -- adds Java 8 :: operator
// BH 7/15/2018 -- adds Java 8 lambda expressions
// BH 7/14/2018 -- removes java2scriptbuilder; uses CompilationParticipant instead
// BH 7/5/2018 -- fixes int | char
// BH 7/3/2018 -- adds tryWithResource
// BH 7/3/2018 -- adds effectively final -- FINAL keyword no longer necessary
// BH 6/27/2018 -- fix for a[Integer] not becoming a[Integer.valueOf]
// BH 6/26/2018 -- method logging via j2s.log.methods.called and j2s.log.methods.declared
// BH 6/24/2018 -- synchronized(a = new Object()) {...} ---> ...; only if an assignment or not a simple function call to Object.getTreeLock()
// BH 6/23/2018 -- synchronized(a = new Object()) {...} ---> if(!(a = new Object()) {throw new NullPointerException()}else{...}
// BH 6/21/2018 -- CharSequence.subSequence() should be defined both subSequence$I$I and subSequence
// BH 6/20/2018 -- fixes for (int var : new int[] {3,4,5}) becoming for var var
// BH 6/19/2018 -- adds .j2s j2s.class.replacements=org.apache.log4j.->jalview.javascript.log4j.;
// BH 5/15/2018 -- fix for a[pt++] |= 3 incrementing pt twice and disregarding a[][] (see test/Test_Or.java)
// BH 3/27/2018 -- fix for anonymous inner classes of inner classes not having this.this$0
// BH 1/5/2018 -- @j2sKeep removed; refactored into one class

// BH 12/31/2017 -- competely rewritten for no run-time ambiguities
// BH 9/10/2017 -- adds full byte, short, and int distinction using class-level local fields $b$, $s$, and $i$, which are IntXArray[1]. (See ASTKeywordVisitor)
// BH 9/7/2017 -- primitive casting for *=,/=,+=,-=,&=,|=,^=
// BH 9/7/2017 -- primitive numeric casting -- (byte) was ignored so that (byte) 0xFF remained 0xFF.
// BH 9/7/2017 -- fixed multiple issues with char and Character
// BH 9/4/2017 -- java.awt, javax.swing, swingjs code added; additional fixes required
// BH 8/30/2017 -- all i/o working, including printf and FileOutputStream
// BH 8/19/2017 -- String must implement CharSequence, so all .length() -> .length$()
// BH 8/19/2017 -- varargs logic fixed for missing argument
// BH 8/18/2017 -- array instanceof, reflection, componentType fixes
// BH 8/16/2017 -- JSE8-UnionType catch (Exception... | Exception...) {...}
// BH 8/13/2017 -- includes native code calls in System.err
// BH 7/31/2017 -- extensively reworked for fully qualified method names and no SAEM

/**
*
* @author zhou renjian 2006-12-3
Expand Down Expand Up @@ -640,10 +592,6 @@ private String getClassJavaNameForType(Type type) {
QualifiedType qualType = (QualifiedType) type;
return getClassJavaNameForType(qualType.getQualifier()) + "." + qualType.getName().getIdentifier();
}
// if (type instanceof NameQualifiedType) {
// NameQualifiedType nType = (NameQualifiedType) type;
// return getClassJavaNameForClass(nType.getQualifier()) + "." + nType.getName().getIdentifier();
// }
if (type instanceof ArrayType)
return getClassJavaNameForType(((ArrayType) type).getElementType());
if (type instanceof ParameterizedType)
Expand Down Expand Up @@ -1174,30 +1122,19 @@ private void addMethodInvocation(SimpleName javaQualifier, List<?> arguments, IM
ITypeBinding declaringClass = mBinding.getDeclaringClass();
String declaringClassJavaClassName = getJavaClassNameQualified(declaringClass);

// System. out.println -- System.out is static, but println is not.
// nonetheless, Modifier.isStatic() returns true.

boolean isStatic = isStatic(mBinding);// || expression != null && isStatic(expression.resolveTypeBinding()));
// if (!isStatic && expression instanceof Name) {
// IBinding binding = ((Name) expression).resolveBinding();
// // no, because sometimes these are not fully qualified className =
// // expression.toString();
// // because System.out is the name of a static field, not a class
// isStatic |= isStatic(binding);
// }
boolean isStatic = isStatic(mBinding);
boolean isPrivate = isPrivate(mBinding);
boolean isPrivateAndNotStatic = isPrivate && !isStatic;
String privateVar = (isPrivateAndNotStatic ? getPrivateVar(declaringClass, false) : null);
boolean doLog = (!isPrivate && global_htMethodsCalled != null);

boolean needBname = (!isStatic && expression == null && lambdaArity < 0
&& !areEqual(declaringClass, class_typeBinding)
&& !class_typeBinding.isAssignmentCompatible(declaringClass));

boolean needBname = (!isStatic && lambdaArity < 0 &&
(expression == null
? !areEqual(declaringClass, class_typeBinding)
&& !class_typeBinding.isAssignmentCompatible(declaringClass)
: expression instanceof ThisExpression && ((ThisExpression) expression).getQualifier() != null)
);
String bname = (needBname ? getThisRefOrSyntheticReference(javaQualifier, declaringClass, null) : null);

// add the qualifier

int pt = buffer.length();
if (isPrivateAndNotStatic) {
// note that the following expression will not work if the method is private:
Expand All @@ -1209,22 +1146,20 @@ private void addMethodInvocation(SimpleName javaQualifier, List<?> arguments, IM
doLog = false;
if (bname != null)
allowClazzNewLambda = false;
} else {
if (expression == null) {
doLog = false;
if (bname != null) {
buffer.append(bname);
buffer.append(".");
} else if (!isStatic) {
buffer.append("this.");
} else {
// this will be C$., I think.
}
} else {
appendFinalMethodQualifier(expression, declaringClassJavaClassName, bname,
(isStatic && !isPrivate ? FINAL_ESCAPECACHE : FINAL_CACHE));
} else if (expression == null) {
doLog = false;
if (bname != null) {
buffer.append(bname);
buffer.append(".");
} else if (!isStatic) {
buffer.append("this.");
} else {
// this will be C$., I think.
}
} else {
appendFinalMethodQualifier(expression, declaringClassJavaClassName, bname,
(isStatic && !isPrivate ? FINAL_ESCAPECACHE : FINAL_CACHE));
buffer.append(".");
}
// keep a pointer, because we may rewrite this
int ptLog = (doLog ? buffer.length() : 0);
Expand All @@ -1247,8 +1182,7 @@ private void addMethodInvocation(SimpleName javaQualifier, List<?> arguments, IM
&& (methodName.equals("indexOf") || methodName.equals("lastIndexOf"))) {
// indicate to boxer method to use method "q" not "p" here.
// This allows characters to be left as strings in String.indexOf$I and
// String.lastIndexOf$I
// for faster processing.
// String.lastIndexOf$I for faster processing.
isIndexOf = true;
}
}
Expand Down Expand Up @@ -1344,6 +1278,7 @@ private void appendFinalMethodQualifier(Expression qualifier, String declaringCl
} else {
// xxxx.field.foo()
// (x ? y : z).foo()
// xxx.this.foo()
qualifier.accept(this);
}
}
Expand Down Expand Up @@ -3431,8 +3366,13 @@ public boolean visit(SuperFieldAccess node) {
*
*/
public boolean visit(ThisExpression node) {
buffer.append(node.getQualifier() == null ? "this"
: getThisRefOrSyntheticReference(node, node.resolveTypeBinding(), "this"));
if (node.getQualifier() == null) {
buffer.append("this");
return false;
}
// xxxx.this.x
// xxxx.this.foo()
buffer.append(getThisRefOrSyntheticReference(node, node.resolveTypeBinding(), "this"));
return false;
}

Expand Down
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
136 changes: 136 additions & 0 deletions sources/net.sf.j2s.java.core/src/components/SimpleTableDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle or the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package components;

/*
* SimpleTableDemo.java requires no other files.
*/

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class SimpleTableDemo extends JPanel {
private boolean DEBUG = false;

public SimpleTableDemo() {
super(new GridLayout(1,0));

String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};

Object[][] data = {
{"Kathy", "Smith",
"Snowboarding", new Integer(5), new Boolean(false)},
{"John", "Doe",
"Rowing", new Integer(3), new Boolean(true)},
{"Sue", "Black",
"Knitting", new Integer(2), new Boolean(false)},
{"Jane", "White",
"Speed reading", new Integer(20), new Boolean(true)},
{"Joe", "Brown",
"Pool", new Integer(10), new Boolean(false)}
};

final JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
table.setFillsViewportHeight(true);

if (DEBUG) {
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
printDebugData(table);
}
});
}

//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);

//Add the scroll pane to this panel.
add(scrollPane);
}

private void printDebugData(JTable table) {
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
javax.swing.table.TableModel model = table.getModel();

System.out.println("Value of data: ");
for (int i=0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j=0; j < numCols; j++) {
System.out.print(" " + model.getValueAt(i, j));
}
System.out.println();
}
System.out.println("--------------------------");
}

/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("SimpleTableDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.
SimpleTableDemo newContentPane = new SimpleTableDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);

//Display the window.
frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
Loading