Skip to content

Commit 51b416d

Browse files
hansonrhansonr
authored andcommitted
updated transpiler creates unqualified public JApplet method aliases
1 parent d332343 commit 51b416d

File tree

10 files changed

+35
-27
lines changed

10 files changed

+35
-27
lines changed
-3.28 KB
Binary file not shown.
58 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20180916182707
1+
20180917232142
-3.28 KB
Binary file not shown.
58 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20180916182707
1+
20180917232142

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

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public class Java2ScriptVisitor extends ASTVisitor {
262262
* parameterized
263263
*
264264
*/
265-
private boolean temp_addUnqualifiedMethod;
265+
private boolean temp_add$UnqualifiedMethod;
266266

267267
// the three key elements of any class
268268

@@ -1001,15 +1001,10 @@ private void processMethodDeclaration(IMethodBinding mBinding, List<ASTNode> par
10011001
boolean isPrivate = !isPublic && !isConstructor && isPrivate(mBinding);
10021002
boolean isStatic = isStatic(mBinding);
10031003
int qualification = (lambdaType != NOT_LAMBDA ? METHOD_FULLY_QUALIFIED
1004-
: temp_addUnqualifiedMethod ? METHOD_$_QUALIFIED
1005-
: isUserApplet && !isConstructor && !isStatic && isPublic ? METHOD_UNQUALIFIED
1004+
: temp_add$UnqualifiedMethod ? METHOD_$_QUALIFIED
10061005
: METHOD_FULLY_QUALIFIED);
1007-
1008-
// boolean addUnqualified = lambdaType == NOT_LAMBDA && (temp_addUnqualifiedMethod // method call to lambda
1009-
// || isUserApplet && !isConstructor && !isStatic && isPublic
1010-
// // public applet methods could never be overloaded in
1011-
// // JavaScript anyway.
1012-
// );
1006+
if (isUserApplet && lambdaType == NOT_LAMBDA && !isConstructor && !isStatic && isPublic)
1007+
qualification |= METHOD_UNQUALIFIED;
10131008
String finalName = getFinalMethodNameOrArrayForDeclaration(mBinding, isConstructor, qualification);
10141009
boolean isMain = isStatic && isPublic && mBinding.getName().equals("main")
10151010
&& mBinding.getKey().endsWith(";.main([Ljava/lang/String;)V");
@@ -2020,15 +2015,14 @@ private void addClassOrInterface(ASTNode node, ITypeBinding binding, List<?> bod
20202015
log("default method " + method.getKey());
20212016
defpt = buffer.length();
20222017
}
2023-
boolean addUnqualifiedCurrent = temp_addUnqualifiedMethod;
2018+
boolean addUnqualifiedCurrent = temp_add$UnqualifiedMethod;
20242019
if (unqualifiedMethods != null) {
20252020
// check for all methods that override a functional interface abstract method,
2026-
// as those
2027-
// methods are not to be qualified
2021+
// as those methods are to be qualified only with $
20282022

20292023
for (int i = unqualifiedMethods.size(); --i >= 0;) {
20302024
if (method.overrides(unqualifiedMethods.get(i))) {
2031-
temp_addUnqualifiedMethod = true;
2025+
temp_add$UnqualifiedMethod = true;
20322026
break;
20332027
}
20342028
}
@@ -2038,7 +2032,7 @@ private void addClassOrInterface(ASTNode node, ITypeBinding binding, List<?> bod
20382032
defaults.append(buffer.substring(defpt));
20392033
buffer.setLength(defpt);
20402034
}
2041-
temp_addUnqualifiedMethod = addUnqualifiedCurrent;
2035+
temp_add$UnqualifiedMethod = addUnqualifiedCurrent;
20422036
}
20432037
}
20442038
}
@@ -4847,19 +4841,28 @@ private String getFinalMethodNameOrArrayForDeclaration(IMethodBinding mBinding,
48474841
ITypeBinding methodClass = mBinding.getDeclaringClass();
48484842
List<String> names = null;
48494843
List<String[]> methodList = getGenericMethodList(methodClass, nodeName);
4844+
48504845
if (methodList != null) {
48514846
names = new ArrayList<String>();
48524847
for (int i = methodList.size(); --i >= 0;) {
48534848
String pname = getFinalMethodNameWith$Params(methodName, null, mBinding, methodList.get(i), false,
48544849
METHOD_NOTSPECIAL);
48554850
if (pname != null)
48564851
names.add(pname);
4857-
if (qualification == METHOD_FULLY_QUALIFIED)
4852+
if (qualification != METHOD_FULLY_QUALIFIED)
48584853
names.add(ensureMethod$Name(methodName, mBinding, getJavaClassNameQualified(methodClass)));
48594854
}
4860-
} else if (qualification != METHOD_FULLY_QUALIFIED && !methodName.equals(qname) && !classHasMethod(methodClass, methodName)) {
4861-
names = new ArrayList<String>();
4862-
names.add(methodName + (qualification == METHOD_UNQUALIFIED || methodName.indexOf("$") >= 0 ? "" : "$"));
4855+
}
4856+
if ((qualification & METHOD_$_QUALIFIED) != 0 && !methodName.equals(qname)
4857+
&& !classHasNoParameterMethod(methodClass, methodName)) {
4858+
if (names == null)
4859+
names = new ArrayList<String>();
4860+
names.add(methodName + (methodName.indexOf("$") >= 0 ? "" : "$"));
4861+
}
4862+
if ((qualification & METHOD_UNQUALIFIED) != 0) {
4863+
if (names == null)
4864+
names = new ArrayList<String>();
4865+
names.add(methodName);
48634866
}
48644867
if (names == null || names.size() == 0)
48654868
return "'" + qname + "'";
@@ -4872,7 +4875,7 @@ private String getFinalMethodNameOrArrayForDeclaration(IMethodBinding mBinding,
48724875
return "[" + qname.substring(1) + "]";
48734876
}
48744877

4875-
private static boolean classHasMethod(ITypeBinding methodClass, String methodName) {
4878+
private static boolean classHasNoParameterMethod(ITypeBinding methodClass, String methodName) {
48764879
while (methodClass != null) {
48774880
IMethodBinding[] methods = methodClass.getDeclaredMethods();
48784881
for (int i = methods.length; --i >= 0;) {
-3.28 KB
Binary file not shown.

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ public JSGraphics2D(Object canvas) { // this must be Object, because we are
8686
hints = new RenderingHints(new Hashtable());
8787
this.canvas = (HTML5Canvas) canvas;
8888
ctx = this.canvas.getContext("2d");
89-
// reduce antialiasing, thank you,
90-
// http://www.rgraph.net/docs/howto-get-crisp-lines-with-no- antialias.html
91-
if (!isShifted)
92-
ctx.translate(-0.5, -0.5);
93-
isShifted = true;
89+
// removed - caused blurriness 9/17/2018
90+
// // reduce antialiasing, thank you,
91+
// // http://www.rgraph.net/docs/howto-get-crisp-lines-with-no- antialias.html
92+
// if (!isShifted)
93+
// ctx.translate(-0.5, -0.5);
94+
// isShifted = true;
9495
transform = new AffineTransform();
9596
setStroke(new BasicStroke());
9697
/**

sources/net.sf.j2s.java.core/srcjs/swingjs2.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15169,6 +15169,7 @@ Clazz._getStackTrace = function(n) {
1516915169
estack.pop();
1517015170
}
1517115171
var s = "\n";
15172+
try {
1517215173
var c = arguments.callee;
1517315174
for (var i = 0; i < n; i++) {
1517415175
if (!(c = c.caller))
@@ -15190,7 +15191,7 @@ Clazz._getStackTrace = function(n) {
1519015191
s += getArgs(c);
1519115192
}
1519215193
}
15193-
15194+
} catch(e){}
1519415195
s += estack.join("\n");
1519515196
if (Clazz._stack.length) {
1519615197
s += "\nsee Clazz._stack";
@@ -18672,6 +18673,7 @@ m$(C$, ['printStackTrace$java_io_PrintStream','printStackTrace$java_io_PrintWrit
1867218673

1867318674
Clazz.newMeth(C$, 'fillInStackTrace$', function () {
1867418675
this.stackTrace = Clazz.array(StackTraceElement);
18676+
try {
1867518677
var caller = arguments.callee.caller;
1867618678
var superCaller = null;
1867718679
var callerList = [];
@@ -18706,6 +18708,8 @@ while (index < 20 && caller != null) {
1870618708
}
1870718709
caller = (superCaller && superCaller.arguments && superCaller.arguments.callee) ? superCaller.arguments.callee.caller : null;
1870818710
}
18711+
} catch (e) {};
18712+
1870918713
Clazz.initializingException = false;
1871018714
return this;
1871118715
});

0 commit comments

Comments
 (0)