Skip to content

Commit d5d0255

Browse files
committed
transpiler/runtime fix
@j2sAlias not necessary $__T fixes
1 parent d27ae0a commit d5d0255

File tree

9 files changed

+61
-44
lines changed

9 files changed

+61
-44
lines changed
4.75 KB
Binary file not shown.
228 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200101114436
1+
20200103220342
4.75 KB
Binary file not shown.
228 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200101114436
1+
20200103220342

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class CorePlugin extends Plugin {
2626
*
2727
*/
2828
public static String VERSION = "3.2.6-v1";
29+
// BH 2020.01.03 -- 3.2.6-v1 fixes for $__T and some synthetic methods missing
2930
// BH 2020.01.01 -- 3.2.6-v1 fixes for generic varargs with only one parameter
3031
// BH 2019.12.19 -- 3.2.6-v0 adds C$.$fields$
3132
// BH 2019.12.15 -- 3.2.5-v4 fix for local class within anonymous class not getting name

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

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,9 @@
157157
//
158158
// todo: j2sdoc in static field showing up in default static block only, not in initializer block.
159159

160+
// BH 2020.01.03 -- 3.2.6-v1 fixes for $__T and some synthetic methods missing
160161
// BH 2020.01.01 3.2.6-v1 fixes for generic varargs with only one parameter
161-
162162
// BH 2019.12.19 3.2.6-v0 C$.$clinit$=2 adds C$.$fields$, Clazz._getFields
163-
164163
// BH 2019.11.20 3.2.5-v1 fix and refactoring for FINAL $finals$ fix throughout java.util.stream
165164

166165
// NOTE: All of the original (complicated and only partially working) nested block-counting code in
@@ -319,7 +318,7 @@ public class Java2ScriptVisitor extends ASTVisitor {
319318
private static Map<String, String> global_htMethodsCalled;
320319
private static boolean global_logAllCalls;
321320

322-
private static Map<String, Map<String, List<String[]>>> genericClassMap = new HashMap<String, Map<String, List<String[]>>>();
321+
private static Map<String, Map<String, List<String[]>>> syntheticClassMethodNameMap = new HashMap<String, Map<String, List<String[]>>>();
323322
private static Map<String, Map<String, String>> genericClassTypes = new HashMap<String, Map<String, String>>();
324323

325324
private static Map<String,String> htStrLitCache = new Hashtable<>();
@@ -1281,7 +1280,6 @@ public boolean visit(MethodDeclaration node) {
12811280
private void processMethodDeclaration(MethodDeclaration mnode, IMethodBinding mBinding, List<ASTNode> parameters,
12821281
ASTNode body, boolean isConstructor, int lambdaType) {
12831282
String aliases = (mnode == null ? null : checkJ2SMethodDoc(mnode));
1284-
12851283
int mods = mBinding.getModifiers();
12861284
boolean isNative = Modifier.isNative(mods);
12871285
if (body == null && !isNative && lambdaType == NOT_LAMBDA) {
@@ -1397,6 +1395,9 @@ private boolean addMethodInvocation(SimpleName javaQualifier, List<?> arguments,
13971395
}
13981396
String methodName = mBinding.getName();
13991397
ITypeBinding declaringClass = mBinding.getDeclaringClass();
1398+
if (mBinding.isSynthetic()) {
1399+
System.out.println(">>>synthetic invoc " + methodName + " " + mBinding);
1400+
}
14001401
boolean isStatic = isStatic(mBinding);
14011402
boolean isPrivate = isPrivate(mBinding);
14021403
boolean isPrivateAndNotStatic = isPrivate && !isStatic;
@@ -2354,7 +2355,6 @@ && checkAnnotations(element, CHECK_J2S_IGNORE_AND_ANNOTATIONS)) {
23542355
IMethodBinding method = mnode.resolveBinding();
23552356
if (method == null || !checkAnnotations(mnode, CHECK_J2S_IGNORE_AND_ANNOTATIONS))
23562357
continue;
2357-
23582358
if (methods != null) {
23592359
String mname = method.getName();
23602360
if (class_annotationType == NOT_JAXB
@@ -2520,11 +2520,6 @@ private void processAnnotationTypeMemberDeclaration(AnnotationTypeMemberDeclarat
25202520
buffer.setLength(pt);
25212521
}
25222522

2523-
private String getPackageName(ITypeBinding javaClass) {
2524-
IPackageBinding p = javaClass.getPackage();
2525-
return (p == null ? "_" : p.getName());
2526-
}
2527-
25282523
/**
25292524
* Collect all names of all functional interface abstract methods that this
25302525
* class might refer to so that their unqualified. This is not perfect, as it is
@@ -4246,7 +4241,7 @@ private void addMethodArguments(ITypeBinding[] parameterTypes, boolean methodIsV
42464241
buffer.append("[");
42474242
//
42484243
//
4249-
// bufferDebug(paramType.getComponentType().getName() + " "
4244+
// buffer Debug(paramType.getComponentType().getName() + " "
42504245
// + (atype != null && atype.isArray() ? atype.getComponentType().getName() : null)
42514246
// + " " + (atype != null && atype.isArray() ? atype.getComponentType().isAssignmentCompatible(paramType.getComponentType()) : null)
42524247
// + " " + (atype != null && atype.isArray() ? paramType.getComponentType().isAssignmentCompatible(atype.getComponentType()) : null)
@@ -4718,7 +4713,7 @@ static String getJavaClassNameQualified(ITypeBinding binding) {
47184713
if (binding == null) {
47194714
return null;
47204715
}
4721-
if (binding.isTypeVariable())
4716+
if (isTypeOrArrayType(binding))
47224717
return binding.toString();
47234718
String name = null, bindingKey;
47244719
if ((binding.isAnonymous() || binding.isLocal()) && (name = binding.getBinaryName()) == null
@@ -4739,6 +4734,10 @@ static String getJavaClassNameQualified(ITypeBinding binding) {
47394734
return name;
47404735
}
47414736

4737+
private static boolean isTypeOrArrayType(ITypeBinding binding) {
4738+
return binding.isTypeVariable() || binding.isArray() && binding.getComponentType().isTypeVariable();
4739+
}
4740+
47424741
private static String getJavaClassNameSuperNoBrackets(ITypeBinding typeBinding) {
47434742
ITypeBinding superclass = typeBinding.getSuperclass();
47444743
if (superclass == null)
@@ -4960,7 +4959,8 @@ String getFinalJ2SClassNameQualifier(Name methodQualifier, ITypeBinding declarin
49604959
* @return array listing classes that need to be loaded in order
49614960
*/
49624961
private String getFinalInnerClassList(ITypeBinding javaClass, String javaClassName) {
4963-
String packageName = getPackageName(javaClass);
4962+
IPackageBinding p = javaClass.getPackage();
4963+
String packageName = (p == null ? NULL_PACKAGE : p.getName());
49644964
if (javaClassName == null) {
49654965
javaClassName = getJavaClassNameQualified(javaClass);
49664966
//System.out.println(">>jcn was null! " + javaClassName);
@@ -5113,10 +5113,10 @@ private void visitList(List<ASTNode> list, String separator) {
51135113
* @param binding
51145114
* @return true if this class could have generic replacements
51155115
*/
5116-
private static boolean checkGenericClass(ITypeBinding topBinding, ITypeBinding binding) {
5116+
private boolean checkGenericClass(ITypeBinding topBinding, ITypeBinding binding) {
51175117
// debugListAllOverrides(binding);
51185118
if (topBinding == binding)
5119-
genericClassMap.put(binding.getKey(), null);
5119+
syntheticClassMethodNameMap.put(binding.getKey(), null);
51205120
// check all superclasses from most super to least super
51215121
String classKey = binding.getKey();
51225122
boolean hasGenerics = (binding.isRawType() || binding.getTypeArguments().length > 0);
@@ -5129,9 +5129,9 @@ private static boolean checkGenericClass(ITypeBinding topBinding, ITypeBinding b
51295129
hasGenerics = checkGenericClass(topBinding, interfaces[i]) || hasGenerics;
51305130
}
51315131
if (hasGenerics) {
5132-
checkMethodsWithGenericParams(topBinding.getKey(), binding);
5132+
addSyntheticMethods(topBinding.getKey(), binding);
51335133
} else {
5134-
genericClassMap.put(classKey, null);
5134+
syntheticClassMethodNameMap.put(classKey, null);
51355135
}
51365136
return hasGenerics;
51375137
}
@@ -5143,7 +5143,7 @@ private static boolean checkGenericClass(ITypeBinding topBinding, ITypeBinding b
51435143
* @param topClassKey
51445144
* @param binding
51455145
*/
5146-
private static void checkMethodsWithGenericParams(String topClassKey, ITypeBinding binding) {
5146+
private void addSyntheticMethods(String topClassKey, ITypeBinding binding) {
51475147
Map<String, String> classTypes = getGenericClassTypes(binding);
51485148
if (classTypes == null)
51495149
return;
@@ -5153,18 +5153,19 @@ private static void checkMethodsWithGenericParams(String topClassKey, ITypeBindi
51535153
IMethodBinding m = methods[i];
51545154
String methodName = m.getName();
51555155
ITypeBinding[] params = m.getParameterTypes();
5156-
if (params.length == 0)
5157-
continue;
5158-
String key = m.getKey();
5159-
if (key.indexOf(";T") >= 0 || key.indexOf("(T") >= 0) {
5160-
String[] list = new String[params.length];
5161-
for (int j = list.length; --j >= 0;) {
5162-
String name = params[j].getName();
5163-
list[j] = name + "|" + classTypes.get(name) + ";";
5164-
}
5165-
addGenericClassMethod(classKey, methodName, list);
5166-
addGenericClassMethod(topClassKey, methodName, list);
5156+
boolean haveGeneric = false;
5157+
for (int j = params.length; --j >= 0 && !haveGeneric;)
5158+
if (isTypeOrArrayType(params[j]))
5159+
haveGeneric = true;
5160+
if (!haveGeneric)
5161+
return;
5162+
String[] list = new String[params.length];
5163+
for (int j = list.length; --j >= 0;) {
5164+
String name = params[j].getName();
5165+
list[j] = name + "|" + classTypes.get(name) + ";";
51675166
}
5167+
addSyntheticMethod(classKey, methodName, list);
5168+
addSyntheticMethod(topClassKey, methodName, list);
51685169
}
51695170

51705171
}
@@ -5184,7 +5185,7 @@ private static ASTNode getAbstractOrAnonymousParentForNode(ASTNode node) {
51845185
* @param type
51855186
* @return a map {T:"java.lang.String",K:"java.lang.Object"}
51865187
*/
5187-
private static Map<String, String> getGenericClassTypes(ITypeBinding type) {
5188+
private Map<String, String> getGenericClassTypes(ITypeBinding type) {
51885189
String classKey = type.getKey();
51895190
Map<String, String> classTypes = genericClassTypes.get(classKey);
51905191
if (classTypes != null)
@@ -5245,8 +5246,8 @@ private static Map<String, String> getGenericClassTypes(ITypeBinding type) {
52455246
* @param methodName
52465247
* @return list of generic types for methods with this name
52475248
*/
5248-
private static List<String[]> getGenericMethodList(ITypeBinding methodClass, String methodName) {
5249-
Map<String, List<String[]>> methodList = genericClassMap.get(methodClass.getKey());
5249+
private List<String[]> getGenericMethodList(ITypeBinding methodClass, String methodName) {
5250+
Map<String, List<String[]>> methodList = syntheticClassMethodNameMap.get(methodClass.getKey());
52505251
return (methodList == null ? null : methodList.get(methodName));
52515252
}
52525253

@@ -5257,11 +5258,11 @@ private static List<String[]> getGenericMethodList(ITypeBinding methodClass, Str
52575258
* @param methodName
52585259
* @param list
52595260
*/
5260-
private static void addGenericClassMethod(String classKey, String methodName, String[] list) {
5261+
private void addSyntheticMethod(String classKey, String methodName, String[] list) {
52615262

5262-
Map<String, List<String[]>> classMap = genericClassMap.get(classKey);
5263+
Map<String, List<String[]>> classMap = syntheticClassMethodNameMap.get(classKey);
52635264
if (classMap == null)
5264-
genericClassMap.put(classKey, classMap = new Hashtable<String, List<String[]>>());
5265+
syntheticClassMethodNameMap.put(classKey, classMap = new Hashtable<String, List<String[]>>());
52655266
List<String[]> methodList = classMap.get(methodName);
52665267
if (methodList == null)
52675268
classMap.put(methodName, methodList = new ArrayList<String[]>());
@@ -5291,7 +5292,6 @@ String getFinalMethodNameOrArrayForDeclaration(IMethodBinding mBinding, boolean
52915292

52925293

52935294
List<String[]> methodList = getGenericMethodList(methodClass, nodeName);
5294-
52955295
if (aliases != null) {
52965296
String[] types = aliases.split(",");
52975297
String pname = getFinalMethodNameWith$Params(methodName, null, mBinding, types, false,
@@ -5304,11 +5304,12 @@ String getFinalMethodNameOrArrayForDeclaration(IMethodBinding mBinding, boolean
53045304
} else if (methodList != null) {
53055305
names = new ArrayList<String>();
53065306
for (int i = methodList.size(); --i >= 0;) {
5307+
String[] l = methodList.get(i);
53075308
String pname = getFinalMethodNameWith$Params(methodName, null, mBinding, methodList.get(i), false,
53085309
null, METHOD_NOTSPECIAL);
53095310
if (pname != null)
53105311
names.add(pname);
5311-
if ((mode & METHOD_FULLY_QUALIFIED) == 0)
5312+
if ((mode & METHOD_FULLY_QUALIFIED) == 0)
53125313
names.add(ensureMethod$Name(methodName, mBinding, getJavaClassNameQualified(methodClass)));
53135314
}
53145315
}
@@ -5412,13 +5413,16 @@ private String getParamsAsString(int nParams, String[] genericTypes, ITypeBindin
54125413
// if this is a method invocation and has generics, then we alias that
54135414
boolean haveGeneric = false;
54145415
for (int i = 0; i < nParams; i++) {
5416+
// I guess erasure is not useful here
5417+
// this is things like Map<String, String> vs Map
5418+
//if (!paramTypes[i].equals(paramTypes[i].getErasure())) {
5419+
// buffer Debug(i + " " + paramTypes[i].getName() + " " + paramTypes[i].getErasure().getName());
5420+
//}
54155421
String type = j2sGetParamCode(paramTypes[i], true, toObject);
54165422
if (genericTypes != null) {
54175423
String genericType = genericTypes[i];
54185424
if (genericType != null) {
54195425
boolean isAlias = (genericType.indexOf("|") < 0);
5420-
// if (isAlias)
5421-
// bufferDebug(genericType + " " + i + " " + nParams);
54225426
if (isAlias ? genericType.length() > 0 && !genericType.equals("*")
54235427
: genericType.indexOf("|null") < 0) {
54245428
if (!isAlias && genericType.indexOf("|" + getJavaClassNameQualified(paramTypes[i]) + ";") < 0)
@@ -5458,8 +5462,17 @@ private String j2sGetParamCode(ITypeBinding binding, boolean addAAA, boolean asG
54585462
return (asGenericObject ? "O" : "T" + binding.getName());
54595463
}
54605464
String name = removeBrackets(getJavaClassNameQualified(binding));
5461-
if (!asGenericObject && !binding.isPrimitive())
5465+
if (binding.isArray() && binding.getComponentType().isTypeVariable()) {
5466+
// TK[]
5467+
if (asGenericObject) {
5468+
name = "O" + name.substring(name.indexOf("["));
5469+
} else {
5470+
name = "T" + name;
5471+
}
5472+
} else if (!asGenericObject && !binding.isPrimitive()) {
54625473
name = NameMapper.fixPackageName(name);
5474+
}
5475+
54635476
String arrays = null;
54645477
int pt = name.indexOf("[");
54655478
if (pt >= 0) {
@@ -6215,8 +6228,9 @@ static boolean isJ2SInheritedFieldName(ITypeBinding binding, String name) {
62156228
j2sName = methodName;
62166229
ITypeBinding declaringClass = mBinding.getDeclaringClass();
62176230
String javaClassName = getJavaClassNameQualified(declaringClass);
6218-
if (NameMapper.isMethodNonqualified(javaClassName, methodName))
6231+
if (NameMapper.isMethodNonqualified(javaClassName, methodName)) {
62196232
return j2sName;
6233+
}
62206234

62216235
// BH: Note in the next statement, that Map.put$K$V is translated to actual
62226236
// values
@@ -6229,8 +6243,9 @@ static boolean isJ2SInheritedFieldName(ITypeBinding binding, String name) {
62296243
: mBinding.getMethodDeclaration().getParameterTypes());
62306244

62316245
int nParams = paramTypes.length;
6232-
if (genericTypes != null && genericTypes.length != nParams)
6246+
if (genericTypes != null && genericTypes.length != nParams) {
62336247
return null;
6248+
}
62346249

62356250
// xxx() adds $ to become xxx$() iff it is NOT
62366251
// - (private and not static)
@@ -6252,6 +6267,7 @@ static boolean isJ2SInheritedFieldName(ITypeBinding binding, String name) {
62526267
String s = getParamsAsString(nParams, genericTypes, paramTypes, false);
62536268

62546269
if (specialType != METHOD_ALIAS && addCallingOption$O && s.indexOf("$T") >= 0 && isJava(javaClassName) && !isJava(class_fullName)) {
6270+
62556271
// If the method being called is a Java class and the calling class is NOT a
62566272
// Java class,
62576273
// then also add the $O version.
4.75 KB
Binary file not shown.

0 commit comments

Comments
 (0)