Skip to content

Commit c9d6507

Browse files
author
jossonsmith
committed
Merge with /trunk for constant char bugs and Dialog#open bug
1 parent 0b8e8e6 commit c9d6507

File tree

5 files changed

+60
-78
lines changed

5 files changed

+60
-78
lines changed

build.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ source.. = src/
22
output.. = bin/
33
bin.includes = META-INF/,\
44
.,\
5-
plugin.xml
5+
plugin.xml,\
6+
schema/
67
src.includes = META-INF/,\
78
plugin.xml

plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
</extension>
6363

6464
<extension
65+
id="InternalASTScriptVisitor"
66+
name="InternalASTScriptVisitor"
6567
point="net.sf.j2s.core.extendedASTScriptVisitor">
6668
<extendedASTScriptVisitor
6769
class="net.sf.j2s.core.compiler.ASTExtendedVisitor"

src/net/sf/j2s/core/astvisitors/ASTKeywordParser.java

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,20 +1144,35 @@ private void charVisit(ASTNode node, boolean beCare) {
11441144
}
11451145
}
11461146

1147-
public boolean visit(InfixExpression node) {
1147+
boolean checkConstantValue(Expression node) {
11481148
Object constValue = node.resolveConstantExpressionValue();
11491149
if (constValue != null && (constValue instanceof Number
11501150
|| constValue instanceof Character
11511151
|| constValue instanceof Boolean)) {
11521152
if (constValue instanceof Character) {
11531153
buffer.append('\'');
1154-
}
1155-
buffer.append(constValue);
1156-
if (constValue instanceof Character) {
1154+
char charValue = ((Character)constValue).charValue();
1155+
if (charValue < 32 || charValue > 127) {
1156+
buffer.append("\\u");
1157+
String hexStr = Integer.toHexString(charValue);
1158+
int zeroLen = 4 - hexStr.length();
1159+
for (int i = 0; i < zeroLen; i++) {
1160+
buffer.append('0');
1161+
}
1162+
buffer.append(hexStr);
1163+
} else {
1164+
buffer.append(constValue);
1165+
}
11571166
buffer.append('\'');
1167+
} else {
1168+
buffer.append(constValue);
11581169
}
1159-
return false;
1170+
return true;
11601171
}
1172+
return false;
1173+
}
1174+
public boolean visit(InfixExpression node) {
1175+
if (checkConstantValue(node)) return false;
11611176
ITypeBinding expTypeBinding = node.resolveTypeBinding();
11621177
boolean beCare = false;
11631178
if (expTypeBinding != null
@@ -1534,19 +1549,7 @@ public void endVisit(PrefixExpression node) {
15341549
}
15351550

15361551
public boolean visit(PrefixExpression node) {
1537-
Object constValue = node.resolveConstantExpressionValue();
1538-
if (constValue != null && (constValue instanceof Number
1539-
|| constValue instanceof Character
1540-
|| constValue instanceof Boolean)) {
1541-
if (constValue instanceof Character) {
1542-
buffer.append('\'');
1543-
}
1544-
buffer.append(constValue);
1545-
if (constValue instanceof Character) {
1546-
buffer.append('\'');
1547-
}
1548-
return false;
1549-
}
1552+
if (checkConstantValue(node)) return false;
15501553
String op = node.getOperator().toString();
15511554
if ("~".equals(op) || "!".equals(op)) {
15521555
buffer.append(op);
@@ -1711,20 +1714,7 @@ public boolean visit(QualifiedName node) {
17111714
// }
17121715
// }
17131716
// }
1714-
Object constValue = node.resolveConstantExpressionValue();
1715-
if (constValue != null && (constValue instanceof Number
1716-
|| constValue instanceof Character
1717-
|| constValue instanceof Boolean)
1718-
&& isSimpleQualified(node)) {
1719-
if (constValue instanceof Character) {
1720-
buffer.append('\'');
1721-
}
1722-
buffer.append(constValue);
1723-
if (constValue instanceof Character) {
1724-
buffer.append('\'');
1725-
}
1726-
return false;
1727-
}
1717+
if (isSimpleQualified(node) && checkConstantValue(node)) return false;
17281718
ASTNode parent = node.getParent();
17291719
if (parent != null && !(parent instanceof QualifiedName)) {
17301720
Name qualifier = node.getQualifier();

src/net/sf/j2s/core/astvisitors/ASTScriptVisitor.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,19 +1919,7 @@ public void endVisit(SimpleName node) {
19191919
}
19201920

19211921
public boolean visit(SimpleName node) {
1922-
Object constValue = node.resolveConstantExpressionValue();
1923-
if (constValue != null && (constValue instanceof Number
1924-
|| constValue instanceof Character
1925-
|| constValue instanceof Boolean)) {
1926-
if (constValue instanceof Character) {
1927-
buffer.append('\'');
1928-
}
1929-
buffer.append(constValue);
1930-
if (constValue instanceof Character) {
1931-
buffer.append('\'');
1932-
}
1933-
return false;
1934-
}
1922+
if (checkConstantValue(node)) return false;
19351923
IBinding binding = node.resolveBinding();
19361924
if (binding != null
19371925
&& binding instanceof ITypeBinding) {

src/net/sf/j2s/core/astvisitors/SWTScriptVisitor.java

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,7 @@ protected String[] skipDeclarePackages() {
9292
// }
9393

9494
public boolean visit(SimpleName node) {
95-
Object constValue = node.resolveConstantExpressionValue();
96-
if (constValue != null && (constValue instanceof Number
97-
|| constValue instanceof Character
98-
|| constValue instanceof Boolean)) {
99-
if (constValue instanceof Character) {
100-
buffer.append('\'');
101-
}
102-
buffer.append(constValue);
103-
if (constValue instanceof Character) {
104-
buffer.append('\'');
105-
}
106-
return false;
107-
}
95+
if (checkConstantValue(node)) return false;
10896
IBinding binding = node.resolveBinding();
10997
if (binding != null
11098
&& binding instanceof ITypeBinding) {
@@ -130,20 +118,7 @@ public boolean visit(SimpleName node) {
130118
return super.visit(node);
131119
}
132120
public boolean visit(QualifiedName node) {
133-
Object constValue = node.resolveConstantExpressionValue();
134-
if (constValue != null && (constValue instanceof Number
135-
|| constValue instanceof Character
136-
|| constValue instanceof Boolean)
137-
&& isSimpleQualified(node)) {
138-
if (constValue instanceof Character) {
139-
buffer.append('\'');
140-
}
141-
buffer.append(constValue);
142-
if (constValue instanceof Character) {
143-
buffer.append('\'');
144-
}
145-
return false;
146-
}
121+
if (isSimpleQualified(node) && checkConstantValue(node)) return false;
147122
// IBinding nodeBinding = node.resolveBinding();
148123
// if (nodeBinding instanceof IVariableBinding) {
149124
// IVariableBinding varBinding = (IVariableBinding) nodeBinding;
@@ -371,12 +346,37 @@ public boolean visit(MethodInvocation node) {
371346
IMethodBinding methodBinding = node.resolveMethodBinding();
372347
if ("open".equals(methodBinding.getName()) && methodBinding.getParameterTypes().length == 0) {
373348
if (Bindings.findTypeInHierarchy(methodBinding.getDeclaringClass(), "org.eclipse.swt.widgets.Dialog") != null) {
374-
int lastIndexOf = buffer.lastIndexOf(";\r\n");
375-
if (lastIndexOf == -1) {
376-
lastIndexOf = 0;
349+
int lastIndexOf1 = buffer.lastIndexOf(";\r\n");
350+
if (lastIndexOf1 != -1) {
351+
lastIndexOf1 += 3;
352+
}
353+
int lastIndexOf2 = buffer.lastIndexOf("}\r\n");
354+
if (lastIndexOf2 != -1) {
355+
lastIndexOf2 += 3;
356+
}
357+
int lastIndexOf3 = buffer.lastIndexOf("}");
358+
if (lastIndexOf3 != -1) {
359+
lastIndexOf3 += 1;
360+
}
361+
int lastIndexOf4 = buffer.lastIndexOf("{\r\n");
362+
if (lastIndexOf4 != -1) {
363+
lastIndexOf4 += 3;
364+
}
365+
int lastIndexOf5 = buffer.lastIndexOf("{");
366+
if (lastIndexOf5 != -1) {
367+
lastIndexOf5 += 1;
368+
}
369+
int lastIndexOf = -1;
370+
if (lastIndexOf1 == -1 && lastIndexOf2 == -1
371+
&& lastIndexOf3 == -1 && lastIndexOf1 == -1
372+
&& lastIndexOf2 == -1 && lastIndexOf3 == -1) {
373+
lastIndexOf = buffer.length(); // should never be in here!
374+
} else {
375+
lastIndexOf = Math.max(Math.max(Math.max(lastIndexOf1, lastIndexOf2), lastIndexOf3),
376+
Math.max(lastIndexOf4, lastIndexOf5));
377377
}
378-
String s = buffer.substring(lastIndexOf + 3);
379-
buffer.delete(lastIndexOf + 3, buffer.length());
378+
String s = buffer.substring(lastIndexOf);
379+
buffer.delete(lastIndexOf, buffer.length());
380380
buffer.append("DialogSync2Async.block (");
381381
node.getExpression().accept(this);
382382
buffer.append(", this, function () {\r\n");
@@ -483,6 +483,7 @@ public boolean visit(Block node) {
483483
}
484484
for (int i = 0; i < swtBlockWhileCount + swtDialogOpenCount; i++) {
485485
buffer.append("});\r\n");
486+
buffer.append("return;\r\n"); /* always return directly when dialog#open is called */
486487
}
487488
metSWTBlockWhile = lastSWTBlockWhile;
488489
metDialogOpen = lastDialogOpen;

0 commit comments

Comments
 (0)