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 @@
20200103220342
20200104085654
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.2.6/SwingJS-site.zip
Binary file not shown.
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.2.6/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.6/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20200103220342
20200104085654
55 changes: 29 additions & 26 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 @@ -12,6 +12,7 @@

import java.text.SimpleDateFormat;
import java.util.ArrayList;
//import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -1293,7 +1294,7 @@ private void processMethodDeclaration(MethodDeclaration mnode, IMethodBinding mB
: temp_add$UnqualifiedMethod ? METHOD_$_QUALIFIED : METHOD_FULLY_QUALIFIED);
if (isUserApplet && lambdaType == NOT_LAMBDA && !isConstructor && !isStatic && isPublic)
qualification |= METHOD_UNQUALIFIED;
String finalName = getFinalMethodNameOrArrayForDeclaration(mBinding, isConstructor, aliases, qualification);
String finalName = getMethodNameWithSyntheticBridgeForDeclaration(mBinding, isConstructor, aliases, qualification);
boolean isMain = (isStatic && isPublic && mBinding.getName().equals("main")
&& mBinding.getKey().indexOf(";.main([Ljava/lang/String;)V") >= 0);

Expand Down Expand Up @@ -5107,14 +5108,15 @@ private void visitList(List<ASTNode> list, String separator) {
/**
* Check a class, interface, or Enum binding for generics.
*
* This is used in the method declaration to add alias names to methods.
* This is used in the method declaration to add synthetic names to methods.
*
* @param topBinding -- the class being declared
* @param binding
* @return true if this class could have generic replacements
*/
private boolean checkGenericClass(ITypeBinding topBinding, ITypeBinding binding) {
// debugListAllOverrides(binding);
// from addClassOrInterface
if (topBinding == binding)
syntheticClassMethodNameMap.put(binding.getKey(), null);
// check all superclasses from most super to least super
Expand Down Expand Up @@ -5145,6 +5147,7 @@ private boolean checkGenericClass(ITypeBinding topBinding, ITypeBinding binding)
*/
private void addSyntheticMethods(String topClassKey, ITypeBinding binding) {
Map<String, String> classTypes = getGenericClassTypes(binding);
//buffer Debug(">addSynthMethods " + topClassKey + " " + classTypes);
if (classTypes == null)
return;
String classKey = binding.getKey();
Expand All @@ -5154,11 +5157,12 @@ private void addSyntheticMethods(String topClassKey, ITypeBinding binding) {
String methodName = m.getName();
ITypeBinding[] params = m.getParameterTypes();
boolean haveGeneric = false;
for (int j = params.length; --j >= 0 && !haveGeneric;)
for (int j = params.length; --j >= 0 && !haveGeneric;) {
if (isTypeOrArrayType(params[j]))
haveGeneric = true;
}
if (!haveGeneric)
return;
continue;
String[] list = new String[params.length];
for (int j = list.length; --j >= 0;) {
String name = params[j].getName();
Expand All @@ -5167,7 +5171,24 @@ private void addSyntheticMethods(String topClassKey, ITypeBinding binding) {
addSyntheticMethod(classKey, methodName, list);
addSyntheticMethod(topClassKey, methodName, list);
}
}

/**
* add a generic class method to syntheticClassMethodNameMap under the class and method
*
* @param classKey
* @param methodName
* @param list
*/
private void addSyntheticMethod(String classKey, String methodName, String[] list) {

Map<String, List<String[]>> classMap = syntheticClassMethodNameMap.get(classKey);
if (classMap == null)
syntheticClassMethodNameMap.put(classKey, classMap = new Hashtable<String, List<String[]>>());
List<String[]> methodList = classMap.get(methodName);
if (methodList == null)
classMap.put(methodName, methodList = new ArrayList<String[]>());
methodList.add(list);
}

private static ASTNode getAbstractOrAnonymousParentForNode(ASTNode node) {
Expand Down Expand Up @@ -5228,7 +5249,7 @@ private Map<String, String> getGenericClassTypes(ITypeBinding type) {
}

String[] tokens = sb.toString().split(",");
for (int i = tokens.length; --i >= 0;) {
for (int i = 0; i < tokens.length; i++) {
String key = tokens[i].trim();
key = key.substring(0, (key + " ").indexOf(" "));
String value = (i < types.length ? getJavaClassNameQualified(types[i]) : "java.lang.Object");
Expand All @@ -5251,24 +5272,6 @@ private List<String[]> getGenericMethodList(ITypeBinding methodClass, String met
return (methodList == null ? null : methodList.get(methodName));
}

/**
* add a generic class method to the genericClassMap under the class and method
*
* @param classKey
* @param methodName
* @param list
*/
private void addSyntheticMethod(String classKey, String methodName, String[] list) {

Map<String, List<String[]>> classMap = syntheticClassMethodNameMap.get(classKey);
if (classMap == null)
syntheticClassMethodNameMap.put(classKey, classMap = new Hashtable<String, List<String[]>>());
List<String[]> methodList = classMap.get(methodName);
if (methodList == null)
classMap.put(methodName, methodList = new ArrayList<String[]>());
methodList.add(list);
}

/**
*
* This is the method used to get the name or names to write into the method
Expand All @@ -5282,8 +5285,8 @@ private void addSyntheticMethod(String classKey, String methodName, String[] lis
* @param mode
* @return j2s-qualified name or an array of j2s-qualified names
*/
String getFinalMethodNameOrArrayForDeclaration(IMethodBinding mBinding, boolean isConstructor,
String aliases, int mode) {
String getMethodNameWithSyntheticBridgeForDeclaration(IMethodBinding mBinding, boolean isConstructor,
String aliases, int mode) {
String nodeName = mBinding.getName();
String methodName = (isConstructor ? "c$" : nodeName);
String qname = getFinalMethodNameWith$Params(methodName, null, mBinding, null, false, null, METHOD_NOTSPECIAL);
Expand Down Expand Up @@ -6693,7 +6696,7 @@ public static void addClassAnnotations(Java2ScriptVisitor visitor, int accessTyp
if (mBinding == null)
continue;
varName = "M:" + mBinding.getName();
signature = visitor.getFinalMethodNameOrArrayForDeclaration(mBinding, mBinding.isConstructor(), null, METHOD_FULLY_QUALIFIED);
signature = visitor.getMethodNameWithSyntheticBridgeForDeclaration(mBinding, mBinding.isConstructor(), null, METHOD_FULLY_QUALIFIED);
type = mBinding.getReturnType();
} else if (a.node instanceof AnnotationTypeMemberDeclaration) {
MethodDeclaration method = (MethodDeclaration) a.node;
Expand Down
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
5 changes: 5 additions & 0 deletions sources/net.sf.j2s.java.core/src/test/Test_Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static class Singleton {
System.out.println("Test_Class nonstatic init " + istatic + " " + sstatic);
}

@SuppressWarnings("unused")
private void test(String s) {

}
Expand All @@ -55,6 +56,7 @@ void c() {

}

@SuppressWarnings("unused")
private void test(Integer i) {
c();
}
Expand Down Expand Up @@ -148,7 +150,9 @@ public void mouseExited(MouseEvent e) {

String pseudofinal = "testPseudo";

@SuppressWarnings("serial")
Hashtable<String, Object> t = new Hashtable<String, Object>() {
@Override
public Object put(String key, Object value) {
super.put(key, value);
System.out.println("t.put:" + key + "/" + value);
Expand Down Expand Up @@ -318,6 +322,7 @@ String hello() {
new Test_Class().new B().testB();
Class<?> cl;
ClassLoader loader = test.Test_Anon.class.getClassLoader();
@SuppressWarnings("unused")
Object x = Class.forName("test.Test_Anon", false, loader).getConstructor().newInstance();

cl = Class.forName("test.Test_Class");
Expand Down
3 changes: 2 additions & 1 deletion sources/net.sf.j2s.java.core/src/test/Test_Ints.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ Map<String, Integer> build() {

static long[] uia = /** @j2sNative new Uint32Array(1) || */null;

static long[] la = new long[3];
private static long uint(int i) {
/**
* @j2sNative
*
* return uia[0] = i, uia[0];
* return C$.uia[0] = i, C$.uia[0];
*/
return 0xFFFFFFFFL & i;
}
Expand Down