|
122 | 122 | import org.eclipse.jdt.core.dom.WhileStatement; |
123 | 123 | import org.eclipse.jdt.core.dom.WildcardType; |
124 | 124 |
|
| 125 | +// BH 6/24/2018 -- synchronized(a = new Object()) {...} ---> ...; only if an assignment or not a simple function call to Object.getTreeLock() |
125 | 126 | // BH 6/23/2018 -- synchronized(a = new Object()) {...} ---> if(!(a = new Object()) {throw new NullPointerException()}else{...} |
126 | 127 | // BH 6/21/2018 -- CharSequence.subSequence() should be defined both subSequence$I$I and subSequence |
127 | 128 | // BH 6/20/2018 -- fixes for (int var : new int[] {3,4,5}) becoming for var var |
@@ -910,11 +911,30 @@ public boolean visit(SwitchCase node) { |
910 | 911 | } |
911 | 912 |
|
912 | 913 | public boolean visit(SynchronizedStatement node) { |
913 | | - // we wrap this with a simple if() statement, |
914 | | - // checking that it is not null |
915 | | - buffer.append("if(!("); |
916 | | - node.getExpression().accept(this); |
917 | | - buffer.append(")){throw new NullPointerException()}else"); |
| 914 | + // we could wrap this with a simple if() statement, |
| 915 | + // checking that it is not null, but that seems to me |
| 916 | + // to be unnecessary. When would one ever intentionally |
| 917 | + // produce a null pointer exception from synchronized(...)? |
| 918 | + |
| 919 | + Expression e = node.getExpression(); |
| 920 | + if (e instanceof Name |
| 921 | + || e instanceof TypeLiteral |
| 922 | + || e instanceof ThisExpression) |
| 923 | + return false; |
| 924 | + buffer.append("/*sync " + e.getClass().getName() + "*/"); |
| 925 | + // get actual JavaScript code |
| 926 | + int pt = buffer.length(); |
| 927 | + e.accept(this); |
| 928 | + String expr = buffer.substring(pt, buffer.length()); |
| 929 | + buffer.setLength(pt); |
| 930 | + // ignore (treeLock()) |
| 931 | + if (e instanceof MethodInvocation && expr.indexOf(".getTreeLock()") >= 0){ |
| 932 | + MethodInvocation m = (MethodInvocation) e; |
| 933 | + m.getExpression().getName(); |
| 934 | + return false; |
| 935 | + } |
| 936 | + buffer.append(expr); |
| 937 | + buffer.append(";"); |
918 | 938 | node.getBody().accept(this); |
919 | 939 | return false; |
920 | 940 | } |
|
0 commit comments