Skip to content

Commit aae03a6

Browse files
hansonrhansonr
authored andcommitted
more j2sNative issues - PrefixExpressions
1 parent 96c9f82 commit aae03a6

File tree

2 files changed

+52
-14
lines changed

2 files changed

+52
-14
lines changed

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,7 @@ public boolean visit(ArrayInitializer node) {
26002600

26012601
public boolean visit(Assignment node) {
26022602
// note that this is not
2603-
// var x = .....
2603+
// var x = ..... -- that is a visit(VariableDeclaration)
26042604
//
26052605
// includes: =
26062606
// +=, -=, *=, /=, %=
@@ -2611,6 +2611,9 @@ public boolean visit(Assignment node) {
26112611

26122612
Expression left = node.getLeftHandSide();
26132613
Expression right = node.getRightHandSide();
2614+
2615+
// buffer.append("/* assign left=" + left + " " + left.getClass().getName() + " right=" + right + right.getClass().getName() + "*/");
2616+
26142617
ITypeBinding leftTypeBinding = left.resolveTypeBinding();
26152618
ITypeBinding rightTypeBinding = right.resolveTypeBinding();
26162619
String rightName = (rightTypeBinding == null ? null : rightTypeBinding.getName());
@@ -3216,14 +3219,17 @@ public boolean visit(PostfixExpression node) {
32163219
* </pre>
32173220
*/
32183221
public boolean visit(PrefixExpression node) {
3219-
if (getConstantValue(node, true))
3220-
return false;
3222+
Expression exp = node.getOperand();
3223+
// NO! Don't do this! !(/** @j2sNative true||*/false does not work
3224+
// if (getConstantValue(node, true))
3225+
// return false;
32213226
String op = node.getOperator().toString();
3227+
32223228
if ("~".equals(op)) {
32233229
buffer.append(op);
32243230
return true;
32253231
}
3226-
return addPrePost(node, node.getOperand(), node.getOperator().toString(), false);
3232+
return addPrePost(node, exp, node.getOperator().toString(), false);
32273233
}
32283234

32293235
public boolean visit(QualifiedName node) {
@@ -3876,6 +3882,7 @@ private void addNonCharacter(Expression exp) {
38763882
* @param isToString
38773883
*/
38783884
private void addOperand(Expression exp, boolean isToString) {
3885+
38793886
boolean needRtParen = false;//(exp instanceof ParenthesizedExpression && getJ2sJavadoc(exp, DOC_CHECK_ONLY) != null);
38803887
ITypeBinding binding = exp.resolveTypeBinding();
38813888
String name = binding.getName();
@@ -3998,6 +4005,7 @@ private boolean addPrimitiveTypedExpression(Expression left, IVariableBinding as
39984005

39994006
String classIntArray = null;
40004007
String more = null;
4008+
40014009
String prefix = (isAssignment ? "=" : "");
40024010
boolean fromChar = ("char".equals(rightName));
40034011
boolean fromIntType = ("long int short byte".indexOf(rightName) >= 0);
@@ -4252,8 +4260,8 @@ private boolean appendBoxingNode(ASTNode element, boolean toCharCode) {
42524260
buffer.append(toCharCode && name == "char" ? ")" + CHARCODEAT0 : ")." + name + "Value$()");
42534261
return true;
42544262
}
4255-
}
4256-
if (!(element instanceof ParenthesizedExpression) && getConstantValue(exp, true)) {
4263+
}
4264+
if (!(element instanceof ParenthesizedExpression) && !(element instanceof PrefixExpression) && getConstantValue(exp, true)) {
42574265
return false;
42584266
}
42594267
}
@@ -5172,7 +5180,7 @@ private static boolean hasSuperClass(ITypeBinding typeBinding) {
51725180
private Object getConstant(Expression exp) {
51735181
boolean isOK = (getJ2sJavadoc(exp, DOC_CHECK_ONLY) == null);
51745182
if (!isOK) {
5175-
isOK = !(exp instanceof InfixExpression || exp instanceof ParenthesizedExpression);
5183+
isOK = !(exp instanceof InfixExpression || exp instanceof PrefixExpression || exp instanceof ParenthesizedExpression);
51765184
}
51775185
return (isOK ? exp.resolveConstantExpressionValue() : null);
51785186
}
@@ -5295,9 +5303,10 @@ private void setMapJavaDoc(PackageDeclaration node) {
52955303
// normal termination from item after last j2sjavadoc
52965304
}
52975305

5298-
// for (int i = 0, n = list.size(); i < n; i++) {
5299-
// System. out.println(i + " " + (list.get(i) == null ? null : list.get(i).getClass().getName() + " " + list.get(i).getStartPosition() + "..." + (list.get(i).getStartPosition() + list.get(i).getLength())));
5300-
// }
5306+
//System.out.println("/**** list ****/");
5307+
//for (int i = 0, n = list.size(); i < n; i++) {
5308+
// System. out.println(i + " " + (list.get(i) == null ? null : list.get(i).getClass().getName() + " " + list.get(i).getStartPosition() + "..." + (list.get(i).getStartPosition() + list.get(i).getLength())));
5309+
//}
53015310

53025311
// and link javadoc to its closest block
53035312

@@ -5313,11 +5322,7 @@ private void setMapJavaDoc(PackageDeclaration node) {
53135322
item = list.get(++i);
53145323
}
53155324
i++;
5316-
//System.out.println(">>>1 " + item.getStartPosition() + " " + item);
5317-
//if (item instanceof ParenthesizedExpression)
5318-
// item = ((ParenthesizedExpression) item).getExpression();
53195325
Integer pt = Integer.valueOf(item.getStartPosition() * factor);
5320-
//System.out.println(">>>2 " + pt + " " + item);
53215326
List<Javadoc> docs = package_mapBlockJavadoc.get(pt);
53225327
if (docs == null)
53235328
package_mapBlockJavadoc.put(pt, docs = new ArrayList<Javadoc>());
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package test;
2+
3+
class Test_Native2 extends Test_ {
4+
5+
public static void main(String[] args) {
6+
7+
if (/** @j2sNative true || */ false)
8+
System.out.println("OK");
9+
10+
// if (true ||false) System.out.println$S("OK");
11+
12+
13+
boolean b = !(/** @j2sNative true || */false);
14+
15+
// var b=!(true ||false);
16+
17+
18+
assert(!b);
19+
b = !(/** @j2sNative true || */false);
20+
21+
// b=!(true ||false);
22+
23+
int c;
24+
25+
c = ~(/** @j2sNative 1|| */0);
26+
27+
// c=~(1||0);
28+
29+
30+
}
31+
32+
}
33+

0 commit comments

Comments
 (0)