Skip to content

Commit 81625cc

Browse files
authored
Merge pull request #148 from BobHanson/master
transpiler upgrade for synthetic bridge methods
2 parents c445326 + f974630 commit 81625cc

File tree

10 files changed

+38
-29
lines changed

10 files changed

+38
-29
lines changed
1.43 KB
Binary file not shown.
32 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200103220342
1+
20200104085654
1.43 KB
Binary file not shown.
32 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200103220342
1+
20200104085654

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

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

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

@@ -5107,14 +5108,15 @@ private void visitList(List<ASTNode> list, String separator) {
51075108
/**
51085109
* Check a class, interface, or Enum binding for generics.
51095110
*
5110-
* This is used in the method declaration to add alias names to methods.
5111+
* This is used in the method declaration to add synthetic names to methods.
51115112
*
51125113
* @param topBinding -- the class being declared
51135114
* @param binding
51145115
* @return true if this class could have generic replacements
51155116
*/
51165117
private boolean checkGenericClass(ITypeBinding topBinding, ITypeBinding binding) {
51175118
// debugListAllOverrides(binding);
5119+
// from addClassOrInterface
51185120
if (topBinding == binding)
51195121
syntheticClassMethodNameMap.put(binding.getKey(), null);
51205122
// check all superclasses from most super to least super
@@ -5145,6 +5147,7 @@ private boolean checkGenericClass(ITypeBinding topBinding, ITypeBinding binding)
51455147
*/
51465148
private void addSyntheticMethods(String topClassKey, ITypeBinding binding) {
51475149
Map<String, String> classTypes = getGenericClassTypes(binding);
5150+
//buffer Debug(">addSynthMethods " + topClassKey + " " + classTypes);
51485151
if (classTypes == null)
51495152
return;
51505153
String classKey = binding.getKey();
@@ -5154,11 +5157,12 @@ private void addSyntheticMethods(String topClassKey, ITypeBinding binding) {
51545157
String methodName = m.getName();
51555158
ITypeBinding[] params = m.getParameterTypes();
51565159
boolean haveGeneric = false;
5157-
for (int j = params.length; --j >= 0 && !haveGeneric;)
5160+
for (int j = params.length; --j >= 0 && !haveGeneric;) {
51585161
if (isTypeOrArrayType(params[j]))
51595162
haveGeneric = true;
5163+
}
51605164
if (!haveGeneric)
5161-
return;
5165+
continue;
51625166
String[] list = new String[params.length];
51635167
for (int j = list.length; --j >= 0;) {
51645168
String name = params[j].getName();
@@ -5167,7 +5171,24 @@ private void addSyntheticMethods(String topClassKey, ITypeBinding binding) {
51675171
addSyntheticMethod(classKey, methodName, list);
51685172
addSyntheticMethod(topClassKey, methodName, list);
51695173
}
5174+
}
5175+
5176+
/**
5177+
* add a generic class method to syntheticClassMethodNameMap under the class and method
5178+
*
5179+
* @param classKey
5180+
* @param methodName
5181+
* @param list
5182+
*/
5183+
private void addSyntheticMethod(String classKey, String methodName, String[] list) {
51705184

5185+
Map<String, List<String[]>> classMap = syntheticClassMethodNameMap.get(classKey);
5186+
if (classMap == null)
5187+
syntheticClassMethodNameMap.put(classKey, classMap = new Hashtable<String, List<String[]>>());
5188+
List<String[]> methodList = classMap.get(methodName);
5189+
if (methodList == null)
5190+
classMap.put(methodName, methodList = new ArrayList<String[]>());
5191+
methodList.add(list);
51715192
}
51725193

51735194
private static ASTNode getAbstractOrAnonymousParentForNode(ASTNode node) {
@@ -5228,7 +5249,7 @@ private Map<String, String> getGenericClassTypes(ITypeBinding type) {
52285249
}
52295250

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

5254-
/**
5255-
* add a generic class method to the genericClassMap under the class and method
5256-
*
5257-
* @param classKey
5258-
* @param methodName
5259-
* @param list
5260-
*/
5261-
private void addSyntheticMethod(String classKey, String methodName, String[] list) {
5262-
5263-
Map<String, List<String[]>> classMap = syntheticClassMethodNameMap.get(classKey);
5264-
if (classMap == null)
5265-
syntheticClassMethodNameMap.put(classKey, classMap = new Hashtable<String, List<String[]>>());
5266-
List<String[]> methodList = classMap.get(methodName);
5267-
if (methodList == null)
5268-
classMap.put(methodName, methodList = new ArrayList<String[]>());
5269-
methodList.add(list);
5270-
}
5271-
52725275
/**
52735276
*
52745277
* This is the method used to get the name or names to write into the method
@@ -5282,8 +5285,8 @@ private void addSyntheticMethod(String classKey, String methodName, String[] lis
52825285
* @param mode
52835286
* @return j2s-qualified name or an array of j2s-qualified names
52845287
*/
5285-
String getFinalMethodNameOrArrayForDeclaration(IMethodBinding mBinding, boolean isConstructor,
5286-
String aliases, int mode) {
5288+
String getMethodNameWithSyntheticBridgeForDeclaration(IMethodBinding mBinding, boolean isConstructor,
5289+
String aliases, int mode) {
52875290
String nodeName = mBinding.getName();
52885291
String methodName = (isConstructor ? "c$" : nodeName);
52895292
String qname = getFinalMethodNameWith$Params(methodName, null, mBinding, null, false, null, METHOD_NOTSPECIAL);
@@ -6693,7 +6696,7 @@ public static void addClassAnnotations(Java2ScriptVisitor visitor, int accessTyp
66936696
if (mBinding == null)
66946697
continue;
66956698
varName = "M:" + mBinding.getName();
6696-
signature = visitor.getFinalMethodNameOrArrayForDeclaration(mBinding, mBinding.isConstructor(), null, METHOD_FULLY_QUALIFIED);
6699+
signature = visitor.getMethodNameWithSyntheticBridgeForDeclaration(mBinding, mBinding.isConstructor(), null, METHOD_FULLY_QUALIFIED);
66976700
type = mBinding.getReturnType();
66986701
} else if (a.node instanceof AnnotationTypeMemberDeclaration) {
66996702
MethodDeclaration method = (MethodDeclaration) a.node;
1.43 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/test/Test_Class.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static class Singleton {
4747
System.out.println("Test_Class nonstatic init " + istatic + " " + sstatic);
4848
}
4949

50+
@SuppressWarnings("unused")
5051
private void test(String s) {
5152

5253
}
@@ -55,6 +56,7 @@ void c() {
5556

5657
}
5758

59+
@SuppressWarnings("unused")
5860
private void test(Integer i) {
5961
c();
6062
}
@@ -148,7 +150,9 @@ public void mouseExited(MouseEvent e) {
148150

149151
String pseudofinal = "testPseudo";
150152

153+
@SuppressWarnings("serial")
151154
Hashtable<String, Object> t = new Hashtable<String, Object>() {
155+
@Override
152156
public Object put(String key, Object value) {
153157
super.put(key, value);
154158
System.out.println("t.put:" + key + "/" + value);
@@ -318,6 +322,7 @@ String hello() {
318322
new Test_Class().new B().testB();
319323
Class<?> cl;
320324
ClassLoader loader = test.Test_Anon.class.getClassLoader();
325+
@SuppressWarnings("unused")
321326
Object x = Class.forName("test.Test_Anon", false, loader).getConstructor().newInstance();
322327

323328
cl = Class.forName("test.Test_Class");

sources/net.sf.j2s.java.core/src/test/Test_Ints.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ Map<String, Integer> build() {
2929

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

32+
static long[] la = new long[3];
3233
private static long uint(int i) {
3334
/**
3435
* @j2sNative
3536
*
36-
* return uia[0] = i, uia[0];
37+
* return C$.uia[0] = i, C$.uia[0];
3738
*/
3839
return 0xFFFFFFFFL & i;
3940
}

0 commit comments

Comments
 (0)