Skip to content

Commit 22743fe

Browse files
hansonrhansonr
authored andcommitted
fix for indiscriminate use of charCodeAt()
only java.lang.string should use charCodeAt(n) for charAt(n).charCodeAt(0)
1 parent c099c7c commit 22743fe

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-7
lines changed
9 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2018-07-19_0557 AM
1+
2018-07-22_0207 PM
Binary file not shown.

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130

131131
import net.sf.j2s.core.CorePlugin;
132132

133+
// BH 7/22/2018 -- fixes improper use of charCodeAt() to replace charCode().$c() when not java.lang.String.charAt
133134
// BH 7/20/2018 -- removes qualifications for single-abstract method overrides
134135
// BH 7/19/2018 -- fixes Enum.Enum
135136
// BH 7/18/2018 -- addw Java 8 try without catch or finally
@@ -1661,14 +1662,12 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
16611662
// methods are not to be qualified
16621663

16631664
for (int i = unqualifiedMethods.size(); --i >= 0;) {
1664-
//buffer.append(">>" + method.getKey() + " " + unqualifiedMethods.get(i).getKey() + "<<\r\n");
16651665
if (method.overrides(unqualifiedMethods.get(i))) {
16661666
dontQualifyMethod = true;
16671667
break;
16681668
}
16691669
}
16701670
}
1671-
//buffer.append("<<" + dontQualifyMethod + "<<");
16721671
element.accept(this);
16731672
dontQualifyMethod = dontQualifyCurrent;
16741673
}
@@ -2346,7 +2345,7 @@ public boolean visit(Assignment node) {
23462345
left.accept(this);
23472346
int ptArray2 = (isArray ? buffer.length() : -1);
23482347
if (!"char".equals(leftName)) {
2349-
if (isIntegerType(leftName) || "booelean".equals(leftName)) {
2348+
if (isIntegerType(leftName) || "boolean".equals(leftName)) {
23502349
// can't just use a |= b because that ends up as 1 or 0, not true or false.
23512350
// byte|short|int|long += ...
23522351
if (!addPrimitiveTypedExpression(left, toBinding, leftName, opType, right, rightName, null, true))
@@ -2997,7 +2996,6 @@ private String getQualifiedSimpleName(SimpleName node) {
29972996
return simpleNameInMethodBinding(node, isQualified, (IMethodBinding) binding);
29982997

29992998
ITypeBinding typeBinding = node.resolveTypeBinding();
3000-
// >>Math<<.max
30012999
return NameMapper.get$QualifiedJ2SFieldName(typeBinding == null ? node.getFullyQualifiedName()
30023000
: assureQualifiedNameAllowP$(typeBinding.getQualifiedName()), true);
30033001
}
@@ -3476,9 +3474,9 @@ private void addCharCodeAt(Expression right, int pt) {
34763474
if (right instanceof MethodInvocation) {
34773475
// if possible, just replace "charAt" with "charCodeAt"
34783476
MethodInvocation m = (MethodInvocation) right;
3479-
if ("charAt".equals(m.getName().toString())) {
3477+
if (m.resolveMethodBinding().getKey().equals("Ljava/lang/String;.charAt(I)C")) {
34803478
if ((pt = buffer.indexOf(".charAt", pt)) >= 0) {
3481-
charCodeAt0 = "Code" + buffer.substring(pt + 5); // At....
3479+
charCodeAt0 = "Code" + buffer.substring(pt + 5);
34823480
buffer.setLength(pt + 5);
34833481
}
34843482
}

0 commit comments

Comments
 (0)