aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist
diff options
context:
space:
mode:
authorchibash <chiba@javassist.org>2019-12-24 01:02:05 +0900
committerchibash <chiba@javassist.org>2019-12-24 01:02:05 +0900
commit150709141ca5cafa0be64638bbb724aa9879a15d (patch)
tree7bbb0123348e24f1d9b7393d452e509c5fcd6559 /src/main/javassist
parentafe124ffa5794c881c212fb1ebec51a554d0e332 (diff)
downloadjavassist-150709141ca5cafa0be64638bbb724aa9879a15d.tar.gz
javassist-150709141ca5cafa0be64638bbb724aa9879a15d.zip
fixes a bug involuved in Pull Request #294
Diffstat (limited to 'src/main/javassist')
-rw-r--r--src/main/javassist/compiler/MemberCodeGen.java4
-rw-r--r--src/main/javassist/compiler/Parser.java2
-rw-r--r--src/main/javassist/compiler/ast/ArrayInit.java17
3 files changed, 20 insertions, 3 deletions
diff --git a/src/main/javassist/compiler/MemberCodeGen.java b/src/main/javassist/compiler/MemberCodeGen.java
index f1ec84a5..48acd137 100644
--- a/src/main/javassist/compiler/MemberCodeGen.java
+++ b/src/main/javassist/compiler/MemberCodeGen.java
@@ -365,7 +365,7 @@ public class MemberCodeGen extends CodeGen {
sizeExpr.accept(this);
else
if (sizeExpr == null) {
- int s = init.length();
+ int s = init.size();
bytecode.addIconst(s);
}
else
@@ -414,7 +414,7 @@ public class MemberCodeGen extends CodeGen {
}
if (init != null) {
- int s = init.length();
+ int s = init.size();
ASTList list = init;
for (int i = 0; i < s; i++) {
bytecode.addOpcode(DUP);
diff --git a/src/main/javassist/compiler/Parser.java b/src/main/javassist/compiler/Parser.java
index 5290450c..ae73fb29 100644
--- a/src/main/javassist/compiler/Parser.java
+++ b/src/main/javassist/compiler/Parser.java
@@ -683,7 +683,7 @@ public final class Parser implements TokenId {
lex.get(); // '{'
if(lex.lookAhead() == '}'){
lex.get();
- return new ArrayInit(new IntConst(0,TokenId.IntConstant));
+ return new ArrayInit(null);
}
ASTree expr = parseExpression(tbl);
ArrayInit init = new ArrayInit(expr);
diff --git a/src/main/javassist/compiler/ast/ArrayInit.java b/src/main/javassist/compiler/ast/ArrayInit.java
index f992f426..0b87200e 100644
--- a/src/main/javassist/compiler/ast/ArrayInit.java
+++ b/src/main/javassist/compiler/ast/ArrayInit.java
@@ -25,10 +25,27 @@ public class ArrayInit extends ASTList {
/** default serialVersionUID */
private static final long serialVersionUID = 1L;
+ /**
+ * Constructs an object.
+ * @param firstElement maybe null when the initializer is <code>{}</code> (empty).
+ */
public ArrayInit(ASTree firstElement) {
super(firstElement);
}
+ /**
+ * Gets the number of the elements. Don't call {@link #length()}.
+ *
+ * @return the number of the elements.
+ */
+ public int size() {
+ int s = length();
+ if (s == 1 && head() == null)
+ return 0;
+ else
+ return s;
+ }
+
@Override
public void accept(Visitor v) throws CompileError { v.atArrayInit(this); }