Skip to content

Commit 98a44b8

Browse files
authored
Merge pull request #61 from BobHanson/hanson1
update for transpiler and runtime - fix #2 for unqualified methods
2 parents 21fc2ca + 51b416d commit 98a44b8

File tree

14 files changed

+56
-32
lines changed

14 files changed

+56
-32
lines changed
-396 Bytes
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-
20180916165130
1+
20180917232142
-396 Bytes
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-
20180916165130
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;) {
-396 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/awt/JSComponent.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,17 @@ public void validateComponent() {
318318

319319
}
320320

321+
/**
322+
* Paint this component, checking to see if the background got painted, and if so, make the
323+
* div background transparent so that that underlying HTML5 canvas shows through.
324+
*
325+
* @param g
326+
*/
327+
public void paintWithBackgroundCheck(Graphics g) {
328+
checkBackgroundPainted(null);
329+
paint(g);
330+
checkBackgroundPainted(getJSGraphic2D(g));
331+
}
332+
333+
321334
}

sources/net.sf.j2s.java.core/src/javax/swing/JComponent.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4573,9 +4573,7 @@ void _paintImmediately(int x, int y, int w, int h) {
45734573
// jpanel.repaint() and then draws on the background,
45744574
// the JPanel's background is made transparent
45754575
// (so that the underlying JRootPane canvas can show).
4576-
checkBackgroundPainted(null);
4577-
paintingComponent.paint(g);
4578-
checkBackgroundPainted(getJSGraphic2D(g));
4576+
paintingComponent.paintWithBackgroundCheck(g);
45794577
}
45804578
} finally {
45814579
g.dispose();

0 commit comments

Comments
 (0)