Skip to content

Commit 56a602a

Browse files
committed
try(resource) support; working on sorter
1 parent 017ed66 commit 56a602a

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed
175 Bytes
Binary file not shown.
175 Bytes
Binary file not shown.

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
import org.eclipse.jdt.core.dom.WhileStatement;
123123
import org.eclipse.jdt.core.dom.WildcardType;
124124

125+
// BH 7/3/2018 -- adds tryWithResource
125126
// BH 7/3/2018 -- adds effectively final -- FINAL keyword no longer necessary
126127
// BH 6/27/2018 -- fix for a[Integer] not becoming a[Integer.valueOf]
127128
// BH 6/26/2018 -- method logging via j2s.log.methods.called and j2s.log.methods.declared
@@ -1005,10 +1006,20 @@ public boolean visit(ThrowStatement node) {
10051006
return false;
10061007
}
10071008

1008-
@SuppressWarnings("unchecked")
1009+
@SuppressWarnings({ "unchecked", "null" })
10091010
public boolean visit(TryStatement node) {
10101011
buffer.append("try ");
1012+
List<VariableDeclarationExpression> resources = node.resources();
1013+
int pt = (resources == null || resources.size() == 0 ? -1 : buffer.length() + 1);
10111014
node.getBody().accept(this);
1015+
if (pt >= 0) {
1016+
String buf = buffer.substring(pt);
1017+
buffer.setLength(pt);
1018+
for (int i = 0; i < resources.size(); i++) {
1019+
resources.get(i).accept(this);
1020+
}
1021+
buffer.append(buf);
1022+
}
10121023
List<CatchClause> catchClauses = node.catchClauses();
10131024
int size = catchClauses.size();
10141025
if (size > 0) {
-57 Bytes
Binary file not shown.

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -985,17 +985,8 @@ private int compare(int model1, int model2) {
985985
result = 1;
986986
} else {
987987
Comparator c = sortComparators[counter];
988-
// BH ??????? BH
989-
/**
990-
* @j2sNative
991-
*
992-
* result = (c != null ? c.compare$O$O(v1, v2) : typeof c == "object" ?
993-
* ((v1 = v1.toString()) < (v2 = v2.toString) ? -1 : v1 == v2 ? 0 : 1)
994-
* : (v1 < v2 ? -1 : v1 == v2 ? 0 : 1));
995-
*/
996-
{
997-
result = c.compare(v1, v2);
998-
}
988+
// problem here is that comparators are T, but here we have I
989+
result = (/** @j2sNative c.compare$O$O ? c.compare$O$O(v1,v2) : */ c.compare(v1, v2));
999990
}
1000991
if (sortOrder == SortOrder.DESCENDING) {
1001992
result *= -1;

0 commit comments

Comments
 (0)