Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2de76ea

Browse files
author
sebastigurin
committed
empty varargs method call bugfix and compiler support for isExceptionOf
1 parent 552bcfc commit 2de76ea

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,8 @@ public boolean visit(TryStatement node) {
11361136
buffer.append("{\r\n");
11371137
scopeAdded = true;
11381138
}
1139-
buffer.append("if (Clazz.instanceOf (" + catchEName + ", ");
1139+
buffer.append("if (Clazz.exceptionOf (" + catchEName + ", ");//sgurin : isExceptionOf compiler support.
1140+
//old code was: buffer.append("if (Clazz.instanceOf (" + catchEName + ", ");
11401141
type.accept(this);
11411142
buffer.append(")) ");
11421143
} else {

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,18 +1855,37 @@ public boolean visit(MethodInvocation node) {
18551855
buffer.append(", ");
18561856
}
18571857
boolean needBrackets = true;
1858-
//if (args.size() == 1) {
1858+
1859+
//sgurin: corrected bug when vararg parameter is an empty array.
1860+
if (args.size() == 0) {
1861+
if (needBrackets) buffer.append("[]");
1862+
}
1863+
else {
18591864
Expression arg = (Expression) args.get(args.size() - 1);
18601865
ITypeBinding resolveTypeBinding = arg.resolveTypeBinding();
1861-
if (resolveTypeBinding != null && resolveTypeBinding.isArray()) {
1862-
needBrackets = false;
1863-
}
1864-
//}
1865-
if (needBrackets) buffer.append("[");
1866-
//IMethodBinding methodDeclaration = node.resolveMethodBinding();
1867-
//visitMethodParameterList(node.arguments(), methodDeclaration, paramTypes.length - 1, size);
1868-
visitList(args, ", ", paramTypes.length - 1, size);
1869-
if (needBrackets) buffer.append("]");
1866+
if (resolveTypeBinding != null && resolveTypeBinding.isArray())
1867+
needBrackets = false;
1868+
if (needBrackets) buffer.append("[");
1869+
visitList(args, ", ", paramTypes.length - 1, size);
1870+
if (needBrackets) buffer.append("]");
1871+
}
1872+
1873+
//old Code:
1874+
// //if (args.size() == 1) {
1875+
// Expression arg = (Expression) args.get(args.size() - 1);
1876+
// ITypeBinding resolveTypeBinding = arg.resolveTypeBinding();
1877+
// if (resolveTypeBinding != null && resolveTypeBinding.isArray()) {
1878+
// needBrackets = false;
1879+
// }
1880+
// //}
1881+
// if (needBrackets) buffer.append("[");
1882+
// //IMethodBinding methodDeclaration = node.resolveMethodBinding();
1883+
// //visitMethodParameterList(node.arguments(), methodDeclaration, paramTypes.length - 1, size);
1884+
// visitList(args, ", ", paramTypes.length - 1, size);
1885+
// if (needBrackets) buffer.append("]");
1886+
1887+
1888+
18701889
} else {
18711890
IMethodBinding methodDeclaration = node.resolveMethodBinding();
18721891
visitMethodParameterList(node.arguments(), methodDeclaration);

src/net/sf/j2s/core/compiler/Java2ScriptCompiler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ public static String[] getClazzAbbrMap() {
531531
"Clazz.prepareFields", "Y", //
532532
"Clazz.newArray", "A", //
533533
"Clazz.instanceOf", "O", //
534+
"Clazz.exceptionOf", "e", //sgurin
534535
"Clazz.inheritArgs", "G", //
535536
"Clazz.checkPrivateMethod", "X", //
536537
"Clazz.makeFunction", "Q", //

0 commit comments

Comments
 (0)