aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/javassist/compiler')
-rw-r--r--src/main/javassist/compiler/AccessorMaker.java21
-rw-r--r--src/main/javassist/compiler/CodeGen.java128
-rw-r--r--src/main/javassist/compiler/CompileError.java4
-rw-r--r--src/main/javassist/compiler/Javac.java79
-rw-r--r--src/main/javassist/compiler/JvstCodeGen.java101
-rw-r--r--src/main/javassist/compiler/JvstTypeChecker.java22
-rw-r--r--src/main/javassist/compiler/KeywordTable.java15
-rw-r--r--src/main/javassist/compiler/Lex.java155
-rw-r--r--src/main/javassist/compiler/MemberCodeGen.java124
-rw-r--r--src/main/javassist/compiler/MemberResolver.java85
-rw-r--r--src/main/javassist/compiler/NoFieldException.java2
-rw-r--r--src/main/javassist/compiler/Parser.java146
-rw-r--r--src/main/javassist/compiler/SymbolTable.java10
-rw-r--r--src/main/javassist/compiler/SyntaxError.java3
-rw-r--r--src/main/javassist/compiler/TypeChecker.java72
-rw-r--r--src/main/javassist/compiler/ast/ASTList.java20
-rw-r--r--src/main/javassist/compiler/ast/ASTree.java5
-rw-r--r--src/main/javassist/compiler/ast/ArrayInit.java5
-rw-r--r--src/main/javassist/compiler/ast/AssignExpr.java4
-rw-r--r--src/main/javassist/compiler/ast/BinExpr.java4
-rw-r--r--src/main/javassist/compiler/ast/CallExpr.java5
-rw-r--r--src/main/javassist/compiler/ast/CastExpr.java6
-rw-r--r--src/main/javassist/compiler/ast/CondExpr.java5
-rw-r--r--src/main/javassist/compiler/ast/Declarator.java9
-rw-r--r--src/main/javassist/compiler/ast/DoubleConst.java6
-rw-r--r--src/main/javassist/compiler/ast/Expr.java6
-rw-r--r--src/main/javassist/compiler/ast/FieldDecl.java6
-rw-r--r--src/main/javassist/compiler/ast/InstanceOfExpr.java5
-rw-r--r--src/main/javassist/compiler/ast/IntConst.java6
-rw-r--r--src/main/javassist/compiler/ast/Keyword.java4
-rw-r--r--src/main/javassist/compiler/ast/Member.java5
-rw-r--r--src/main/javassist/compiler/ast/MethodDecl.java3
-rw-r--r--src/main/javassist/compiler/ast/NewExpr.java9
-rw-r--r--src/main/javassist/compiler/ast/Pair.java8
-rw-r--r--src/main/javassist/compiler/ast/Stmnt.java9
-rw-r--r--src/main/javassist/compiler/ast/StringL.java4
-rw-r--r--src/main/javassist/compiler/ast/Symbol.java4
-rw-r--r--src/main/javassist/compiler/ast/Variable.java4
38 files changed, 684 insertions, 425 deletions
diff --git a/src/main/javassist/compiler/AccessorMaker.java b/src/main/javassist/compiler/AccessorMaker.java
index 05d19ed1..02030c1b 100644
--- a/src/main/javassist/compiler/AccessorMaker.java
+++ b/src/main/javassist/compiler/AccessorMaker.java
@@ -16,9 +16,22 @@
package javassist.compiler;
-import javassist.*;
-import javassist.bytecode.*;
import java.util.HashMap;
+import java.util.Map;
+
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+import javassist.bytecode.AccessFlag;
+import javassist.bytecode.Bytecode;
+import javassist.bytecode.ClassFile;
+import javassist.bytecode.ConstPool;
+import javassist.bytecode.Descriptor;
+import javassist.bytecode.ExceptionsAttribute;
+import javassist.bytecode.FieldInfo;
+import javassist.bytecode.MethodInfo;
+import javassist.bytecode.SyntheticAttribute;
/**
* AccessorMaker maintains accessors to private members of an enclosing
@@ -27,14 +40,14 @@ import java.util.HashMap;
public class AccessorMaker {
private CtClass clazz;
private int uniqueNumber;
- private HashMap accessors;
+ private Map<String,Object> accessors;
static final String lastParamType = "javassist.runtime.Inner";
public AccessorMaker(CtClass c) {
clazz = c;
uniqueNumber = 1;
- accessors = new HashMap();
+ accessors = new HashMap<String,Object>();
}
public String getConstructor(CtClass c, String desc, MethodInfo orig)
diff --git a/src/main/javassist/compiler/CodeGen.java b/src/main/javassist/compiler/CodeGen.java
index ab02d8cf..d4c748f8 100644
--- a/src/main/javassist/compiler/CodeGen.java
+++ b/src/main/javassist/compiler/CodeGen.java
@@ -18,10 +18,36 @@ package javassist.compiler;
import java.util.ArrayList;
import java.util.Arrays;
-import javassist.compiler.ast.*;
-import javassist.bytecode.*;
-
-/* The code generator is implemeted by three files:
+import java.util.List;
+
+import javassist.bytecode.Bytecode;
+import javassist.bytecode.Opcode;
+import javassist.compiler.ast.ASTList;
+import javassist.compiler.ast.ASTree;
+import javassist.compiler.ast.ArrayInit;
+import javassist.compiler.ast.AssignExpr;
+import javassist.compiler.ast.BinExpr;
+import javassist.compiler.ast.CallExpr;
+import javassist.compiler.ast.CastExpr;
+import javassist.compiler.ast.CondExpr;
+import javassist.compiler.ast.Declarator;
+import javassist.compiler.ast.DoubleConst;
+import javassist.compiler.ast.Expr;
+import javassist.compiler.ast.FieldDecl;
+import javassist.compiler.ast.InstanceOfExpr;
+import javassist.compiler.ast.IntConst;
+import javassist.compiler.ast.Keyword;
+import javassist.compiler.ast.Member;
+import javassist.compiler.ast.MethodDecl;
+import javassist.compiler.ast.NewExpr;
+import javassist.compiler.ast.Pair;
+import javassist.compiler.ast.Stmnt;
+import javassist.compiler.ast.StringL;
+import javassist.compiler.ast.Symbol;
+import javassist.compiler.ast.Variable;
+import javassist.compiler.ast.Visitor;
+
+/* The code generator is implemented by three files:
* CodeGen.java, MemberCodeGen.java, and JvstCodeGen.
* I just wanted to split a big file into three smaller ones.
*/
@@ -47,7 +73,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
*/
public boolean inStaticMethod;
- protected ArrayList breakList, continueList;
+ protected List<Integer> breakList, continueList;
/**
* doit() in ReturnHook is called from atReturn().
@@ -171,18 +197,16 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
if (dim == 0)
return name;
- else {
- StringBuffer sbuf = new StringBuffer();
- int d = dim;
- while (d-- > 0)
- sbuf.append('[');
+ StringBuffer sbuf = new StringBuffer();
+ int d = dim;
+ while (d-- > 0)
+ sbuf.append('[');
- sbuf.append('L');
- sbuf.append(name);
- sbuf.append(';');
+ sbuf.append('L');
+ sbuf.append(name);
+ sbuf.append(';');
- return sbuf.toString();
- }
+ return sbuf.toString();
}
protected static String toJvmTypeName(int type, int dim) {
@@ -242,16 +266,21 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
expr.accept(typeChecker);
}
+ @Override
public void atASTList(ASTList n) throws CompileError { fatal(); }
-
+
+ @Override
public void atPair(Pair n) throws CompileError { fatal(); }
+ @Override
public void atSymbol(Symbol n) throws CompileError { fatal(); }
+ @Override
public void atFieldDecl(FieldDecl field) throws CompileError {
field.getInit().accept(this);
}
+ @Override
public void atMethodDecl(MethodDecl method) throws CompileError {
ASTList mods = method.getModifiers();
setMaxLocals(1);
@@ -263,7 +292,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
inStaticMethod = true;
}
}
-
+
ASTList params = method.getParams();
while (params != null) {
atDeclarator((Declarator)params.head());
@@ -320,6 +349,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
protected abstract void insertDefaultSuperCall() throws CompileError;
+ @Override
public void atStmnt(Stmnt st) throws CompileError {
if (st == null)
return; // empty
@@ -417,10 +447,10 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
}
private void atWhileStmnt(Stmnt st, boolean notDo) throws CompileError {
- ArrayList prevBreakList = breakList;
- ArrayList prevContList = continueList;
- breakList = new ArrayList();
- continueList = new ArrayList();
+ List<Integer> prevBreakList = breakList;
+ List<Integer> prevContList = continueList;
+ breakList = new ArrayList<Integer>();
+ continueList = new ArrayList<Integer>();
ASTree expr = st.head();
Stmnt body = (Stmnt)st.tail();
@@ -454,19 +484,16 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
hasReturned = alwaysBranch;
}
- protected void patchGoto(ArrayList list, int targetPc) {
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- int pc = ((Integer)list.get(i)).intValue();
+ protected void patchGoto(List<Integer> list, int targetPc) {
+ for (int pc:list)
bytecode.write16bit(pc, targetPc - pc + 1);
- }
}
private void atForStmnt(Stmnt st) throws CompileError {
- ArrayList prevBreakList = breakList;
- ArrayList prevContList = continueList;
- breakList = new ArrayList();
- continueList = new ArrayList();
+ List<Integer> prevBreakList = breakList;
+ List<Integer> prevContList = continueList;
+ breakList = new ArrayList<Integer>();
+ continueList = new ArrayList<Integer>();
Stmnt init = (Stmnt)st.head();
ASTList p = st.tail();
@@ -517,8 +544,8 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
private void atSwitchStmnt(Stmnt st) throws CompileError {
compileExpr(st.head());
- ArrayList prevBreakList = breakList;
- breakList = new ArrayList();
+ List<Integer> prevBreakList = breakList;
+ breakList = new ArrayList<Integer>();
int opcodePc = bytecode.currentPc();
bytecode.addOpcode(LOOKUPSWITCH);
int npads = 3 - (opcodePc & 3);
@@ -583,8 +610,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
expr = TypeChecker.stripPlusExpr(expr);
if (expr instanceof IntConst)
return (int)((IntConst)expr).get();
- else
- throw new CompileError("bad case label");
+ throw new CompileError("bad case label");
}
private void atBreakStmnt(Stmnt st, boolean notCont)
@@ -672,6 +698,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
bc.addOpcode(MONITORENTER);
ReturnHook rh = new ReturnHook(this) {
+ @Override
protected boolean doit(Bytecode b, int opcode) {
b.addAload(var);
b.addOpcode(MONITOREXIT);
@@ -711,7 +738,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
"sorry, cannot break/continue in synchronized block");
}
- private static int getListSize(ArrayList list) {
+ private static int getListSize(List<Integer> list) {
return list == null ? 0 : list.size();
}
@@ -724,6 +751,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
return false;
}
+ @Override
public void atDeclarator(Declarator d) throws CompileError {
d.setLocalVar(getMaxLocals());
d.setClassName(resolveClassName(d.getClassName()));
@@ -745,10 +773,13 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
}
}
+ @Override
public abstract void atNewExpr(NewExpr n) throws CompileError;
+ @Override
public abstract void atArrayInit(ArrayInit init) throws CompileError;
+ @Override
public void atAssignExpr(AssignExpr expr) throws CompileError {
atAssignExpr(expr, true);
}
@@ -931,6 +962,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
return false;
}
+ @Override
public void atCondExpr(CondExpr expr) throws CompileError {
if (booleanExpr(false, expr.condExpr()))
expr.elseExpr().accept(this);
@@ -974,6 +1006,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
return -1;
}
+ @Override
public void atBinExpr(BinExpr expr) throws CompileError {
int token = expr.getOperator();
@@ -1136,7 +1169,6 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
arrayDim = 0;
return true;
}
- else {
int pc = bytecode.currentPc();
bytecode.addIndex(0); // correct later
if (booleanExpr(isAndAnd, bexpr.oprand2()))
@@ -1147,7 +1179,6 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
bytecode.addIndex(6); // skip GOTO instruction
bytecode.addOpcode(Opcode.GOTO);
}
- }
}
else if (isAlwaysBranch(expr, branchIf)) {
// Opcode.GOTO is not added here. The caller must add it.
@@ -1207,8 +1238,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
if (type1 == NULL)
return exprType;
- else
- return type1;
+ return type1;
}
private static final int ifOp[] = { EQ, IF_ICMPEQ, IF_ICMPNE,
@@ -1390,6 +1420,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
bytecode.addOpcode(op);
}
+ @Override
public void atCastExpr(CastExpr expr) throws CompileError {
String cname = resolveClassName(expr.getClassName());
String toClass = checkCastExpr(expr, cname);
@@ -1403,6 +1434,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
bytecode.addCheckcast(toClass);
}
+ @Override
public void atInstanceOfExpr(InstanceOfExpr expr) throws CompileError {
String cname = resolveClassName(expr.getClassName());
String toClass = checkCastExpr(expr, cname);
@@ -1443,7 +1475,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
{
if (srcType == destType)
return;
-
+
int op, op2;
int stype = typePrecedence(srcType);
int dtype = typePrecedence(destType);
@@ -1475,6 +1507,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
bytecode.addOpcode(op2);
}
+ @Override
public void atExpr(Expr expr) throws CompileError {
// array access, member access,
// (unary) +, (unary) -, ++, --, !, ~
@@ -1483,7 +1516,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
ASTree oprand = expr.oprand1();
if (token == '.') {
String member = ((Symbol)expr.oprand2()).get();
- if (member.equals("class"))
+ if (member.equals("class"))
atClassObject(expr); // .class
else
atFieldRead(expr);
@@ -1560,6 +1593,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
throw new CompileError("invalid type for " + expr.getName());
}
+ @Override
public abstract void atCallExpr(CallExpr expr) throws CompileError;
protected abstract void atFieldRead(ASTree expr) throws CompileError;
@@ -1749,7 +1783,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
if (doDup && isPost)
bytecode.addOpcode(DUP2);
- bytecode.addLconst((long)1);
+ bytecode.addLconst(1);
bytecode.addOpcode(token == PLUSPLUS ? LADD : LSUB);
if (doDup && !isPost)
bytecode.addOpcode(DUP2);
@@ -1835,7 +1869,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
exprType = INT;
}
else if (t == LONG) {
- bytecode.addLconst((long)1);
+ bytecode.addLconst(1);
bytecode.addOpcode(token == PLUSPLUS ? LADD : LSUB);
}
else if (t == FLOAT) {
@@ -1856,8 +1890,10 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
protected abstract void atFieldPlusPlus(int token, boolean isPost,
ASTree oprand, Expr expr, boolean doDup) throws CompileError;
+ @Override
public abstract void atMember(Member n) throws CompileError;
+ @Override
public void atVariable(Variable v) throws CompileError {
Declarator d = v.getDeclarator();
exprType = d.getType();
@@ -1887,6 +1923,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
}
}
+ @Override
public void atKeyword(Keyword k) throws CompileError {
arrayDim = 0;
int token = k.get();
@@ -1914,13 +1951,14 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
if (token == THIS)
className = getThisName();
else
- className = getSuperName();
+ className = getSuperName();
break;
default :
fatal();
}
}
+ @Override
public void atStringL(StringL s) throws CompileError {
exprType = CLASS;
arrayDim = 0;
@@ -1928,6 +1966,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
bytecode.addLdc(s.get());
}
+ @Override
public void atIntConst(IntConst i) throws CompileError {
arrayDim = 0;
long value = i.get();
@@ -1942,6 +1981,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
}
}
+ @Override
public void atDoubleConst(DoubleConst d) throws CompileError {
arrayDim = 0;
if (d.getType() == DoubleConstant) {
diff --git a/src/main/javassist/compiler/CompileError.java b/src/main/javassist/compiler/CompileError.java
index 331b7847..5b857cf2 100644
--- a/src/main/javassist/compiler/CompileError.java
+++ b/src/main/javassist/compiler/CompileError.java
@@ -20,6 +20,8 @@ import javassist.CannotCompileException;
import javassist.NotFoundException;
public class CompileError extends Exception {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
private Lex lex;
private String reason;
@@ -43,10 +45,12 @@ public class CompileError extends Exception {
public Lex getLex() { return lex; }
+ @Override
public String getMessage() {
return reason;
}
+ @Override
public String toString() {
return "compile error: " + reason;
}
diff --git a/src/main/javassist/compiler/Javac.java b/src/main/javassist/compiler/Javac.java
index fc3d803f..084487b4 100644
--- a/src/main/javassist/compiler/Javac.java
+++ b/src/main/javassist/compiler/Javac.java
@@ -16,23 +16,31 @@
package javassist.compiler;
+import javassist.CannotCompileException;
+import javassist.CtBehavior;
import javassist.CtClass;
-import javassist.CtPrimitiveType;
-import javassist.CtMember;
+import javassist.CtConstructor;
import javassist.CtField;
-import javassist.CtBehavior;
+import javassist.CtMember;
import javassist.CtMethod;
-import javassist.CtConstructor;
-import javassist.CannotCompileException;
+import javassist.CtPrimitiveType;
import javassist.Modifier;
+import javassist.NotFoundException;
+import javassist.bytecode.BadBytecode;
import javassist.bytecode.Bytecode;
import javassist.bytecode.CodeAttribute;
import javassist.bytecode.LocalVariableAttribute;
-import javassist.bytecode.BadBytecode;
import javassist.bytecode.Opcode;
-import javassist.NotFoundException;
-
-import javassist.compiler.ast.*;
+import javassist.compiler.ast.ASTList;
+import javassist.compiler.ast.ASTree;
+import javassist.compiler.ast.CallExpr;
+import javassist.compiler.ast.Declarator;
+import javassist.compiler.ast.Expr;
+import javassist.compiler.ast.FieldDecl;
+import javassist.compiler.ast.Member;
+import javassist.compiler.ast.MethodDecl;
+import javassist.compiler.ast.Stmnt;
+import javassist.compiler.ast.Symbol;
public class Javac {
JvstCodeGen gen;
@@ -91,14 +99,12 @@ public class Javac {
try {
if (mem instanceof FieldDecl)
return compileField((FieldDecl)mem);
- else {
- CtBehavior cb = compileMethod(p, (MethodDecl)mem);
- CtClass decl = cb.getDeclaringClass();
- cb.getMethodInfo2()
- .rebuildStackMapIf6(decl.getClassPool(),
- decl.getClassFile2());
- return cb;
- }
+ CtBehavior cb = compileMethod(p, (MethodDecl)mem);
+ CtClass decl = cb.getDeclaringClass();
+ cb.getMethodInfo2()
+ .rebuildStackMapIf6(decl.getClassPool(),
+ decl.getClassFile2());
+ return cb;
}
catch (BadBytecode bb) {
throw new CompileError(bb.getMessage());
@@ -120,6 +126,7 @@ public class Javac {
protected void setInit(ASTree i) { init = i; }
+ @Override
protected ASTree getInitAST() {
return init;
}
@@ -158,24 +165,22 @@ public class Javac {
cons.setExceptionTypes(tlist);
return cons;
}
- else {
- Declarator r = md.getReturn();
- CtClass rtype = gen.resolver.lookupClass(r);
- recordReturnType(rtype, false);
- CtMethod method = new CtMethod(rtype, r.getVariable().get(),
- plist, gen.getThisClass());
- method.setModifiers(mod);
- gen.setThisMethod(method);
- md.accept(gen);
- if (md.getBody() != null)
- method.getMethodInfo().setCodeAttribute(
- bytecode.toCodeAttribute());
- else
- method.setModifiers(mod | Modifier.ABSTRACT);
+ Declarator r = md.getReturn();
+ CtClass rtype = gen.resolver.lookupClass(r);
+ recordReturnType(rtype, false);
+ CtMethod method = new CtMethod(rtype, r.getVariable().get(),
+ plist, gen.getThisClass());
+ method.setModifiers(mod);
+ gen.setThisMethod(method);
+ md.accept(gen);
+ if (md.getBody() != null)
+ method.getMethodInfo().setCodeAttribute(
+ bytecode.toCodeAttribute());
+ else
+ method.setModifiers(mod | Modifier.ABSTRACT);
- method.setExceptionTypes(tlist);
- return method;
- }
+ method.setExceptionTypes(tlist);
+ return method;
}
catch (NotFoundException e) {
throw new CompileError(e.toString());
@@ -437,6 +442,7 @@ public class Javac {
final String m = method;
ProceedHandler h = new ProceedHandler() {
+ @Override
public void doit(JvstCodeGen gen, Bytecode b, ASTList args)
throws CompileError
{
@@ -449,6 +455,7 @@ public class Javac {
gen.addNullIfVoid();
}
+ @Override
public void setReturnType(JvstTypeChecker check, ASTList args)
throws CompileError
{
@@ -481,6 +488,7 @@ public class Javac {
final String m = method;
ProceedHandler h = new ProceedHandler() {
+ @Override
public void doit(JvstCodeGen gen, Bytecode b, ASTList args)
throws CompileError
{
@@ -491,6 +499,7 @@ public class Javac {
gen.addNullIfVoid();
}
+ @Override
public void setReturnType(JvstTypeChecker check, ASTList args)
throws CompileError
{
@@ -525,12 +534,14 @@ public class Javac {
final ASTree texpr = p.parseExpression(stable);
ProceedHandler h = new ProceedHandler() {
+ @Override
public void doit(JvstCodeGen gen, Bytecode b, ASTList args)
throws CompileError
{
gen.compileInvokeSpecial(texpr, methodIndex, descriptor, args);
}
+ @Override
public void setReturnType(JvstTypeChecker c, ASTList args)
throws CompileError
{
diff --git a/src/main/javassist/compiler/JvstCodeGen.java b/src/main/javassist/compiler/JvstCodeGen.java
index 797db0ce..5a43d65e 100644
--- a/src/main/javassist/compiler/JvstCodeGen.java
+++ b/src/main/javassist/compiler/JvstCodeGen.java
@@ -16,9 +16,21 @@
package javassist.compiler;
-import javassist.*;
-import javassist.bytecode.*;
-import javassist.compiler.ast.*;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtPrimitiveType;
+import javassist.NotFoundException;
+import javassist.bytecode.Bytecode;
+import javassist.bytecode.Descriptor;
+import javassist.compiler.ast.ASTList;
+import javassist.compiler.ast.ASTree;
+import javassist.compiler.ast.CallExpr;
+import javassist.compiler.ast.CastExpr;
+import javassist.compiler.ast.Declarator;
+import javassist.compiler.ast.Expr;
+import javassist.compiler.ast.Member;
+import javassist.compiler.ast.Stmnt;
+import javassist.compiler.ast.Symbol;
/* Code generator accepting extended Java syntax for Javassist.
*/
@@ -36,6 +48,7 @@ public class JvstCodeGen extends MemberCodeGen {
private CtClass dollarType = null;
CtClass returnType = null;
String returnCastName = null;
+ @SuppressWarnings("unused")
private String returnVarName = null; // null if $_ is not used.
public static final String wrapperCastName = "$w";
String proceedName = null;
@@ -78,6 +91,7 @@ public class JvstCodeGen extends MemberCodeGen {
/* To support $args, $sig, and $type.
* $args is an array of parameter list.
*/
+ @Override
public void atMember(Member mem) throws CompileError {
String name = mem.get();
if (name.equals(paramArrayName)) {
@@ -120,6 +134,7 @@ public class JvstCodeGen extends MemberCodeGen {
className = "java/lang/Class";
}
+ @Override
protected void atFieldAssign(Expr expr, int op, ASTree left,
ASTree right, boolean doDup) throws CompileError
{
@@ -158,6 +173,7 @@ public class JvstCodeGen extends MemberCodeGen {
}
}
+ @Override
public void atCastExpr(CastExpr expr) throws CompileError {
ASTList classname = expr.getClassName();
if (classname != null && expr.getArrayDim() == 0) {
@@ -227,6 +243,7 @@ public class JvstCodeGen extends MemberCodeGen {
/* Delegates to a ProcHandler object if the method call is
* $proceed(). It may process $cflow().
*/
+ @Override
public void atCallExpr(CallExpr expr) throws CompileError {
ASTree method = expr.oprand1();
if (method instanceof Member) {
@@ -301,8 +318,7 @@ public class JvstCodeGen extends MemberCodeGen {
return (left instanceof Member
&& ((Member)left).get().equals(paramListName));
}
- else
- return false;
+ return false;
}
/*
@@ -314,6 +330,7 @@ public class JvstCodeGen extends MemberCodeGen {
}
*/
+ @Override
public int getMethodArgsLength(ASTList args) {
String pname = paramListName;
int n = 0;
@@ -332,6 +349,7 @@ public class JvstCodeGen extends MemberCodeGen {
return n;
}
+ @Override
public void atMethodArgs(ASTList args, int[] types, int[] dims,
String[] cnames) throws CompileError {
CtClass[] params = paramTypeList;
@@ -409,6 +427,7 @@ public class JvstCodeGen extends MemberCodeGen {
/*
* Makes it valid to write "return <expr>;" for a void method.
*/
+ @Override
protected void atReturnStmnt(Stmnt st) throws CompileError {
ASTree result = st.getLeft();
if (result != null && returnType == CtClass.voidType) {
@@ -442,12 +461,10 @@ public class JvstCodeGen extends MemberCodeGen {
returnVarName = resultName;
if (resultName == null)
return -1;
- else {
- int varNo = getMaxLocals();
- int locals = varNo + recordVar(type, resultName, varNo, tbl);
- setMaxLocals(locals);
- return varNo;
- }
+ int varNo = getMaxLocals();
+ int locals = varNo + recordVar(type, resultName, varNo, tbl);
+ setMaxLocals(locals);
+ return varNo;
}
/**
@@ -537,12 +554,10 @@ public class JvstCodeGen extends MemberCodeGen {
{
if (varName == null)
return -1;
- else {
- int varNo = getMaxLocals();
- int locals = varNo + recordVar(type, varName, varNo, tbl);
- setMaxLocals(locals);
- return varNo;
- }
+ int varNo = getMaxLocals();
+ int locals = varNo + recordVar(type, varName, varNo, tbl);
+ setMaxLocals(locals);
+ return varNo;
}
private int recordVar(CtClass cc, String varName, int varNo,
@@ -608,36 +623,34 @@ public class JvstCodeGen extends MemberCodeGen {
code.addAnewarray(javaLangObject); // anewarray Object
return 1;
}
- else {
- CtClass[] args = new CtClass[1];
- int n = params.length;
- code.addIconst(n); // iconst_<n>
- code.addAnewarray(javaLangObject); // anewarray Object
- for (int i = 0; i < n; ++i) {
- code.addOpcode(Bytecode.DUP); // dup
- code.addIconst(i); // iconst_<i>
- if (params[i].isPrimitive()) {
- CtPrimitiveType pt = (CtPrimitiveType)params[i];
- String wrapper = pt.getWrapperName();
- code.addNew(wrapper); // new <wrapper>
- code.addOpcode(Bytecode.DUP); // dup
- int s = code.addLoad(regno, pt); // ?load <regno>
- regno += s;
- args[0] = pt;
- code.addInvokespecial(wrapper, "<init>",
- Descriptor.ofMethod(CtClass.voidType, args));
- // invokespecial
- }
- else {
- code.addAload(regno); // aload <regno>
- ++regno;
- }
-
- code.addOpcode(Bytecode.AASTORE); // aastore
+ CtClass[] args = new CtClass[1];
+ int n = params.length;
+ code.addIconst(n); // iconst_<n>
+ code.addAnewarray(javaLangObject); // anewarray Object
+ for (int i = 0; i < n; ++i) {
+ code.addOpcode(Bytecode.DUP); // dup
+ code.addIconst(i); // iconst_<i>
+ if (params[i].isPrimitive()) {
+ CtPrimitiveType pt = (CtPrimitiveType)params[i];
+ String wrapper = pt.getWrapperName();
+ code.addNew(wrapper); // new <wrapper>
+ code.addOpcode(Bytecode.DUP); // dup
+ int s = code.addLoad(regno, pt); // ?load <regno>
+ regno += s;
+ args[0] = pt;
+ code.addInvokespecial(wrapper, "<init>",
+ Descriptor.ofMethod(CtClass.voidType, args));
+ // invokespecial
+ }
+ else {
+ code.addAload(regno); // aload <regno>
+ ++regno;
}
- return 8;
+ code.addOpcode(Bytecode.AASTORE); // aastore
}
+
+ return 8;
}
protected void compileUnwrapValue(CtClass type, Bytecode code)
diff --git a/src/main/javassist/compiler/JvstTypeChecker.java b/src/main/javassist/compiler/JvstTypeChecker.java
index 9619890e..13e47291 100644
--- a/src/main/javassist/compiler/JvstTypeChecker.java
+++ b/src/main/javassist/compiler/JvstTypeChecker.java
@@ -16,8 +16,17 @@
package javassist.compiler;
-import javassist.*;
-import javassist.compiler.ast.*;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtPrimitiveType;
+import javassist.NotFoundException;
+import javassist.compiler.ast.ASTList;
+import javassist.compiler.ast.ASTree;
+import javassist.compiler.ast.CallExpr;
+import javassist.compiler.ast.CastExpr;
+import javassist.compiler.ast.Expr;
+import javassist.compiler.ast.Member;
+import javassist.compiler.ast.Symbol;
/* Type checker accepting extended Java syntax for Javassist.
*/
@@ -44,6 +53,7 @@ public class JvstTypeChecker extends TypeChecker {
/* To support $args, $sig, and $type.
* $args is an array of parameter list.
*/
+ @Override
public void atMember(Member mem) throws CompileError {
String name = mem.get();
if (name.equals(codeGen.paramArrayName)) {
@@ -66,6 +76,7 @@ public class JvstTypeChecker extends TypeChecker {
super.atMember(mem);
}
+ @Override
protected void atFieldAssign(Expr expr, int op, ASTree left, ASTree right)
throws CompileError
{
@@ -84,6 +95,7 @@ public class JvstTypeChecker extends TypeChecker {
super.atFieldAssign(expr, op, left, right);
}
+ @Override
public void atCastExpr(CastExpr expr) throws CompileError {
ASTList classname = expr.getClassName();
if (classname != null && expr.getArrayDim() == 0) {
@@ -138,6 +150,7 @@ public class JvstTypeChecker extends TypeChecker {
/* Delegates to a ProcHandler object if the method call is
* $proceed(). It may process $cflow().
*/
+ @Override
public void atCallExpr(CallExpr expr) throws CompileError {
ASTree method = expr.oprand1();
if (method instanceof Member) {
@@ -175,10 +188,10 @@ public class JvstTypeChecker extends TypeChecker {
return (left instanceof Member
&& ((Member)left).get().equals(codeGen.paramListName));
}
- else
- return false;
+ return false;
}
+ @Override
public int getMethodArgsLength(ASTList args) {
String pname = codeGen.paramListName;
int n = 0;
@@ -197,6 +210,7 @@ public class JvstTypeChecker extends TypeChecker {
return n;
}
+ @Override
public void atMethodArgs(ASTList args, int[] types, int[] dims,
String[] cnames) throws CompileError {
CtClass[] params = codeGen.paramTypeList;
diff --git a/src/main/javassist/compiler/KeywordTable.java b/src/main/javassist/compiler/KeywordTable.java
index 5f516e3d..65137d9b 100644
--- a/src/main/javassist/compiler/KeywordTable.java
+++ b/src/main/javassist/compiler/KeywordTable.java
@@ -16,18 +16,19 @@
package javassist.compiler;
-public final class KeywordTable extends java.util.HashMap {
+import java.util.HashMap;
+
+public final class KeywordTable extends HashMap<String,Integer> {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
public KeywordTable() { super(); }
public int lookup(String name) {
- Object found = get(name);
- if (found == null)
- return -1;
- else
- return ((Integer)found).intValue();
+ return containsKey(name) ? get(name) : -1;
}
public void append(String name, int t) {
- put(name, Integer.valueOf(t));
+ put(name, t);
}
}
diff --git a/src/main/javassist/compiler/Lex.java b/src/main/javassist/compiler/Lex.java
index eebb856e..498b22fb 100644
--- a/src/main/javassist/compiler/Lex.java
+++ b/src/main/javassist/compiler/Lex.java
@@ -32,6 +32,7 @@ public class Lex implements TokenId {
private Token lookAheadTokens;
private String input;
+ @SuppressWarnings("unused")
private int position, maxlen, lineNumber;
/**
@@ -52,12 +53,10 @@ public class Lex implements TokenId {
public int get() {
if (lookAheadTokens == null)
return get(currentToken);
- else {
- Token t;
- currentToken = t = lookAheadTokens;
- lookAheadTokens = lookAheadTokens.next;
- return t.tokenId;
- }
+ Token t;
+ currentToken = t = lookAheadTokens;
+ lookAheadTokens = lookAheadTokens.next;
+ return t.tokenId;
}
/**
@@ -129,15 +128,12 @@ public class Lex implements TokenId {
tbuf.append('.');
return readDouble(tbuf, c, token);
}
- else{
- ungetc(c);
- return readSeparator('.');
- }
+ ungetc(c);
+ return readSeparator('.');
}
else if (Character.isJavaIdentifierStart((char)c))
return readIdentifier(c, token);
- else
- return readSeparator(c);
+ return readSeparator(c);
}
private int getNextNonWhiteChar() {
@@ -249,19 +245,17 @@ public class Lex implements TokenId {
for (;;) {
c = getc();
if ('0' <= c && c <= '9')
- value = value * 16 + (long)(c - '0');
+ value = value * 16 + (c - '0');
else if ('A' <= c && c <= 'F')
- value = value * 16 + (long)(c - 'A' + 10);
+ value = value * 16 + (c - 'A' + 10);
else if ('a' <= c && c <= 'f')
- value = value * 16 + (long)(c - 'a' + 10);
+ value = value * 16 + (c - 'a' + 10);
else {
token.longValue = value;
if (c == 'L' || c == 'l')
return LongConstant;
- else {
- ungetc(c);
- return IntConstant;
- }
+ ungetc(c);
+ return IntConstant;
}
}
else if ('0' <= c2 && c2 <= '7') {
@@ -269,15 +263,13 @@ public class Lex implements TokenId {
for (;;) {
c = getc();
if ('0' <= c && c <= '7')
- value = value * 8 + (long)(c - '0');
+ value = value * 8 + (c - '0');
else {
token.longValue = value;
if (c == 'L' || c == 'l')
return LongConstant;
- else {
- ungetc(c);
- return IntConstant;
- }
+ ungetc(c);
+ return IntConstant;
}
}
}
@@ -290,7 +282,7 @@ public class Lex implements TokenId {
token.longValue = value;
if (c2 == 'F' || c2 == 'f') {
- token.doubleValue = (double)value;
+ token.doubleValue = value;
return FloatConstant;
}
else if (c2 == 'E' || c2 == 'e'
@@ -343,12 +335,10 @@ public class Lex implements TokenId {
if (c == 'F' || c == 'f')
return FloatConstant;
- else {
- if (c != 'D' && c != 'd')
- ungetc(c);
+ if (c != 'D' && c != 'd')
+ ungetc(c);
- return DoubleConstant;
- }
+ return DoubleConstant;
}
// !"#$%&'( )*+,-./0 12345678 9:;<=>?
@@ -362,51 +352,45 @@ public class Lex implements TokenId {
int c2, c3;
if ('!' <= c && c <= '?') {
int t = equalOps[c - '!'];
- if (t == 0)
+ if (t == 0)
return c;
- else {
- c2 = getc();
- if (c == c2)
- switch (c) {
- case '=' :
- return EQ;
- case '+' :
- return PLUSPLUS;
- case '-' :
- return MINUSMINUS;
- case '&' :
- return ANDAND;
- case '<' :
- c3 = getc();
- if (c3 == '=')
- return LSHIFT_E;
- else {
- ungetc(c3);
- return LSHIFT;
- }
- case '>' :
+ c2 = getc();
+ if (c == c2)
+ switch (c) {
+ case '=' :
+ return EQ;
+ case '+' :
+ return PLUSPLUS;
+ case '-' :
+ return MINUSMINUS;
+ case '&' :
+ return ANDAND;
+ case '<' :
+ c3 = getc();
+ if (c3 == '=')
+ return LSHIFT_E;
+ ungetc(c3);
+ return LSHIFT;
+ case '>' :
+ c3 = getc();
+ if (c3 == '=')
+ return RSHIFT_E;
+ else if (c3 == '>') {
c3 = getc();
if (c3 == '=')
- return RSHIFT_E;
- else if (c3 == '>') {
- c3 = getc();
- if (c3 == '=')
- return ARSHIFT_E;
- else {
- ungetc(c3);
- return ARSHIFT;
- }
- }
- else {
- ungetc(c3);
- return RSHIFT;
- }
- default :
- break;
+ return ARSHIFT_E;
+ ungetc(c3);
+ return ARSHIFT;
}
- else if (c2 == '=')
- return t;
- }
+ else {
+ ungetc(c3);
+ return RSHIFT;
+ }
+ default :
+ break;
+ }
+ else if (c2 == '=')
+ return t;
}
else if (c == '^') {
c2 = getc();
@@ -442,17 +426,15 @@ public class Lex implements TokenId {
int t = ktable.lookup(name);
if (t >= 0)
return t;
- else {
- /* tbuf.toString() is executed quickly since it does not
- * need memory copy. Using a hand-written extensible
- * byte-array class instead of StringBuffer is not a good idea
- * for execution speed. Converting a byte array to a String
- * object is very slow. Using an extensible char array
- * might be OK.
- */
- token.textValue = name;
- return Identifier;
- }
+ /* tbuf.toString() is executed quickly since it does not
+ * need memory copy. Using a hand-written extensible
+ * byte-array class instead of StringBuffer is not a good idea
+ * for execution speed. Converting a byte array to a String
+ * object is very slow. Using an extensible char array
+ * might be OK.
+ */
+ token.textValue = name;
+ return Identifier;
}
private static final KeywordTable ktable = new KeywordTable();
@@ -516,6 +498,7 @@ public class Lex implements TokenId {
|| c == '\n';
}
+ @SuppressWarnings("unused")
private static boolean isDigit(int c) {
return '0' <= c && c <= '9';
}
@@ -542,10 +525,8 @@ public class Lex implements TokenId {
return input.charAt(position++);
else
return -1;
- else {
- int c = lastChar;
- lastChar = -1;
- return c;
- }
+ int c = lastChar;
+ lastChar = -1;
+ return c;
}
}
diff --git a/src/main/javassist/compiler/MemberCodeGen.java b/src/main/javassist/compiler/MemberCodeGen.java
index 07c113a3..ad254816 100644
--- a/src/main/javassist/compiler/MemberCodeGen.java
+++ b/src/main/javassist/compiler/MemberCodeGen.java
@@ -16,11 +16,36 @@
package javassist.compiler;
-import javassist.*;
-import javassist.bytecode.*;
-import javassist.compiler.ast.*;
-
import java.util.ArrayList;
+import java.util.List;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtField;
+import javassist.CtMethod;
+import javassist.Modifier;
+import javassist.NotFoundException;
+import javassist.bytecode.AccessFlag;
+import javassist.bytecode.Bytecode;
+import javassist.bytecode.ClassFile;
+import javassist.bytecode.ConstPool;
+import javassist.bytecode.Descriptor;
+import javassist.bytecode.FieldInfo;
+import javassist.bytecode.MethodInfo;
+import javassist.bytecode.Opcode;
+import javassist.compiler.ast.ASTList;
+import javassist.compiler.ast.ASTree;
+import javassist.compiler.ast.ArrayInit;
+import javassist.compiler.ast.CallExpr;
+import javassist.compiler.ast.Declarator;
+import javassist.compiler.ast.Expr;
+import javassist.compiler.ast.Keyword;
+import javassist.compiler.ast.Member;
+import javassist.compiler.ast.MethodDecl;
+import javassist.compiler.ast.NewExpr;
+import javassist.compiler.ast.Pair;
+import javassist.compiler.ast.Stmnt;
+import javassist.compiler.ast.Symbol;
/* Code generator methods depending on javassist.* classes.
*/
@@ -46,8 +71,7 @@ public class MemberCodeGen extends CodeGen {
ClassFile cf = thisClass.getClassFile2();
if (cf == null)
return ClassFile.MAJOR_VERSION; // JDK 1.3
- else
- return cf.getMajorVersion();
+ return cf.getMajorVersion();
}
/**
@@ -64,6 +88,7 @@ public class MemberCodeGen extends CodeGen {
/**
* Returns the JVM-internal representation of this class name.
*/
+ @Override
protected String getThisName() {
return MemberResolver.javaToJvmName(thisClass.getName());
}
@@ -71,11 +96,13 @@ public class MemberCodeGen extends CodeGen {
/**
* Returns the JVM-internal representation of this super class name.
*/
+ @Override
protected String getSuperName() throws CompileError {
return MemberResolver.javaToJvmName(
MemberResolver.getSuperclass(thisClass).getName());
}
+ @Override
protected void insertDefaultSuperCall() throws CompileError {
bytecode.addAload(0);
bytecode.addInvokespecial(MemberResolver.getSuperclass(thisClass),
@@ -83,13 +110,13 @@ public class MemberCodeGen extends CodeGen {
}
static class JsrHook extends ReturnHook {
- ArrayList jsrList;
+ List<int[]> jsrList;
CodeGen cgen;
int var;
JsrHook(CodeGen gen) {
super(gen);
- jsrList = new ArrayList();
+ jsrList = new ArrayList<int[]>();
cgen = gen;
var = -1;
}
@@ -109,6 +136,7 @@ public class MemberCodeGen extends CodeGen {
b.addIndex(0);
}
+ @Override
protected boolean doit(Bytecode b, int opcode) {
switch (opcode) {
case Opcode.RETURN :
@@ -157,6 +185,7 @@ public class MemberCodeGen extends CodeGen {
var = retTarget[1];
}
+ @Override
protected boolean doit(Bytecode b, int opcode) {
switch (opcode) {
case Opcode.RETURN :
@@ -186,6 +215,7 @@ public class MemberCodeGen extends CodeGen {
}
}
+ @Override
protected void atTryStmnt(Stmnt st) throws CompileError {
Bytecode bc = bytecode;
Stmnt body = (Stmnt)st.getLeft();
@@ -194,7 +224,7 @@ public class MemberCodeGen extends CodeGen {
ASTList catchList = (ASTList)st.getRight().getLeft();
Stmnt finallyBlock = (Stmnt)st.getRight().getRight().getLeft();
- ArrayList gotoList = new ArrayList();
+ List<Integer> gotoList = new ArrayList<Integer>();
JsrHook jsrHook = null;
if (finallyBlock != null)
@@ -209,7 +239,7 @@ public class MemberCodeGen extends CodeGen {
boolean tryNotReturn = !hasReturned;
if (tryNotReturn) {
bc.addOpcode(Opcode.GOTO);
- gotoList.add(Integer.valueOf(bc.currentPc()));
+ gotoList.add(bc.currentPc());
bc.addIndex(0); // correct later
}
@@ -235,7 +265,7 @@ public class MemberCodeGen extends CodeGen {
if (!hasReturned) {
bc.addOpcode(Opcode.GOTO);
- gotoList.add(Integer.valueOf(bc.currentPc()));
+ gotoList.add(bc.currentPc());
bc.addIndex(0); // correct later
tryNotReturn = true;
}
@@ -270,13 +300,11 @@ public class MemberCodeGen extends CodeGen {
/**
* Adds a finally clause for earch return statement.
*/
- private void addFinally(ArrayList returnList, Stmnt finallyBlock)
+ private void addFinally(List<int[]> returnList, Stmnt finallyBlock)
throws CompileError
{
Bytecode bc = bytecode;
- int n = returnList.size();
- for (int i = 0; i < n; ++i) {
- final int[] ret = (int[])returnList.get(i);
+ for (final int[] ret:returnList) {
int pc = ret[0];
bc.write16bit(pc, bc.currentPc() - pc + 1);
ReturnHook hook = new JsrHook2(this, ret);
@@ -289,6 +317,7 @@ public class MemberCodeGen extends CodeGen {
}
}
+ @Override
public void atNewExpr(NewExpr expr) throws CompileError {
if (expr.isArray())
atNewArrayExpr(expr);
@@ -408,11 +437,13 @@ public class MemberCodeGen extends CodeGen {
throw new CompileError("bad new expression");
}
+ @Override
protected void atArrayVariableAssign(ArrayInit init, int varType,
int varArray, String varClass) throws CompileError {
atNewArrayExpr2(varType, null, varClass, init);
}
+ @Override
public void atArrayInit(ArrayInit init) throws CompileError {
throw new CompileError("array initializer is not supported");
}
@@ -446,6 +477,7 @@ public class MemberCodeGen extends CodeGen {
bytecode.addMultiNewarray(desc, count);
}
+ @Override
public void atCallExpr(CallExpr expr) throws CompileError {
String mname = null;
CtClass targetClass = null;
@@ -472,8 +504,7 @@ public class MemberCodeGen extends CodeGen {
targetClass = thisClass;
if (inStaticMethod)
throw new CompileError("a constructor cannot be static");
- else
- bytecode.addAload(0); // this
+ bytecode.addAload(0); // this
if (((Keyword)method).get() == SUPER)
targetClass = MemberResolver.getSuperclass(targetClass);
@@ -563,6 +594,7 @@ public class MemberCodeGen extends CodeGen {
isStatic = true;
}
+ @SuppressWarnings("unused")
int stack = bytecode.getStackDepth();
// generate code for evaluating arguments.
@@ -784,6 +816,7 @@ public class MemberCodeGen extends CodeGen {
}
}
+ @Override
protected void atFieldAssign(Expr expr, int op, ASTree left,
ASTree right, boolean doDup) throws CompileError
{
@@ -842,7 +875,7 @@ public class MemberCodeGen extends CodeGen {
bytecode.add(PUTFIELD);
bytecode.growStack(is2byte ? -3 : -2);
}
-
+
bytecode.addIndex(fi);
}
else {
@@ -858,10 +891,12 @@ public class MemberCodeGen extends CodeGen {
/* overwritten in JvstCodeGen.
*/
+ @Override
public void atMember(Member mem) throws CompileError {
atFieldRead(mem);
}
+ @Override
protected void atFieldRead(ASTree expr) throws CompileError
{
CtField f = fieldAccess(expr, true);
@@ -904,20 +939,18 @@ public class MemberCodeGen extends CodeGen {
minfo.getDescriptor());
return 0;
}
+ int fi = addFieldrefInfo(f, finfo);
+ if (isStatic) {
+ bytecode.add(GETSTATIC);
+ bytecode.growStack(is2byte ? 2 : 1);
+ }
else {
- int fi = addFieldrefInfo(f, finfo);
- if (isStatic) {
- bytecode.add(GETSTATIC);
- bytecode.growStack(is2byte ? 2 : 1);
- }
- else {
- bytecode.add(GETFIELD);
- bytecode.growStack(is2byte ? 1 : 0);
- }
-
- bytecode.addIndex(fi);
- return fi;
+ bytecode.add(GETFIELD);
+ bytecode.growStack(is2byte ? 1 : 0);
}
+
+ bytecode.addIndex(fi);
+ return fi;
}
/**
@@ -929,18 +962,15 @@ public class MemberCodeGen extends CodeGen {
throws CompileError
{
if (AccessFlag.isPrivate(finfo.getAccessFlags())
- && f.getDeclaringClass() != thisClass) {
- CtClass declClass = f.getDeclaringClass();
+ && f.getDeclaringClass() != thisClass) {
+ CtClass declClass = f.getDeclaringClass();
if (isEnclosing(declClass, thisClass)) {
AccessorMaker maker = declClass.getAccessorMaker();
if (maker != null)
return maker;
- else
- throw new CompileError("fatal error. bug?");
}
- else
- throw new CompileError("Field " + f.getName() + " in "
- + declClass.getName() + " is private.");
+ throw new CompileError("Field " + f.getName() + " in "
+ + declClass.getName() + " is private.");
}
return null; // accessible field
@@ -983,6 +1013,7 @@ public class MemberCodeGen extends CodeGen {
return cp.addFieldrefInfo(ci, name, type);
}
+ @Override
protected void atClassObject2(String cname) throws CompileError {
if (getMajorVersion() < ClassFile.JAVA_5)
super.atClassObject2(cname);
@@ -990,6 +1021,7 @@ public class MemberCodeGen extends CodeGen {
bytecode.addLdc(bytecode.getConstPool().addClassInfo(cname));
}
+ @Override
protected void atFieldPlusPlus(int token, boolean isPost,
ASTree oprand, Expr expr, boolean doDup)
throws CompileError
@@ -1130,16 +1162,14 @@ public class MemberCodeGen extends CodeGen {
ASTList list = md.getThrows();
if (list == null)
return null;
- else {
- int i = 0;
- clist = new CtClass[list.length()];
- while (list != null) {
- clist[i++] = resolver.lookupClassByName((ASTList)list.head());
- list = list.tail();
- }
-
- return clist;
+ int i = 0;
+ clist = new CtClass[list.length()];
+ while (list != null) {
+ clist[i++] = resolver.lookupClassByName((ASTList)list.head());
+ list = list.tail();
}
+
+ return clist;
}
/* Converts a class name into a JVM-internal representation.
@@ -1147,6 +1177,7 @@ public class MemberCodeGen extends CodeGen {
* It may also expand a simple class name to java.lang.*.
* For example, this converts Object into java/lang/Object.
*/
+ @Override
protected String resolveClassName(ASTList name) throws CompileError {
return resolver.resolveClassName(name);
}
@@ -1154,6 +1185,7 @@ public class MemberCodeGen extends CodeGen {
/* Expands a simple class name to java.lang.*.
* For example, this converts Object into java/lang/Object.
*/
+ @Override
protected String resolveClassName(String jvmName) throws CompileError {
return resolver.resolveJvmClassName(jvmName);
}
diff --git a/src/main/javassist/compiler/MemberResolver.java b/src/main/javassist/compiler/MemberResolver.java
index a1073a76..00dac6c1 100644
--- a/src/main/javassist/compiler/MemberResolver.java
+++ b/src/main/javassist/compiler/MemberResolver.java
@@ -16,15 +16,28 @@
package javassist.compiler;
-import java.util.Hashtable;
+import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
-import java.util.WeakHashMap;
-import java.util.List;
+import java.util.Hashtable;
import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
-import javassist.*;
-import javassist.bytecode.*;
-import javassist.compiler.ast.*;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtField;
+import javassist.Modifier;
+import javassist.NotFoundException;
+import javassist.bytecode.AccessFlag;
+import javassist.bytecode.ClassFile;
+import javassist.bytecode.Descriptor;
+import javassist.bytecode.MethodInfo;
+import javassist.compiler.ast.ASTList;
+import javassist.compiler.ast.ASTree;
+import javassist.compiler.ast.Declarator;
+import javassist.compiler.ast.Keyword;
+import javassist.compiler.ast.Symbol;
/* Code generator methods depending on javassist.* classes.
*/
@@ -77,8 +90,7 @@ public class MemberResolver implements TokenId {
Method r = new Method(clazz, current, res);
if (res == YES)
return r;
- else
- maybe = r;
+ maybe = r;
}
}
@@ -86,8 +98,7 @@ public class MemberResolver implements TokenId {
argClassNames, maybe != null);
if (m != null)
return m;
- else
- return maybe;
+ return maybe;
}
private Method lookupMethod(CtClass clazz, String methodName,
@@ -100,10 +111,8 @@ public class MemberResolver implements TokenId {
// If the class is an array type, the class file is null.
// If so, search the super class java.lang.Object for clone() etc.
if (cf != null) {
- List list = cf.getMethods();
- int n = list.size();
- for (int i = 0; i < n; ++i) {
- MethodInfo minfo = (MethodInfo)list.get(i);
+ List<MethodInfo> list = cf.getMethods();
+ for (MethodInfo minfo:list) {
if (minfo.getName().equals(methodName)
&& (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0) {
int res = compareSignature(minfo.getDescriptor(),
@@ -143,9 +152,8 @@ public class MemberResolver implements TokenId {
try {
CtClass[] ifs = clazz.getInterfaces();
- int size = ifs.length;
- for (int i = 0; i < size; ++i) {
- Method r = lookupMethod(ifs[i], methodName,
+ for (CtClass intf:ifs) {
+ Method r = lookupMethod(intf, methodName,
argTypes, argDims, argClassNames,
onlyExact);
if (r != null)
@@ -396,13 +404,13 @@ public class MemberResolver implements TokenId {
public CtClass lookupClass(String name, boolean notCheckInner)
throws CompileError
{
- Hashtable cache = getInvalidNames();
- Object found = cache.get(name);
+ Map<String,String> cache = getInvalidNames();
+ String found = cache.get(name);
if (found == INVALID)
throw new CompileError("no such class: " + name);
else if (found != null)
try {
- return classPool.get((String)found);
+ return classPool.get(found);
}
catch (NotFoundException e) {}
@@ -419,23 +427,24 @@ public class MemberResolver implements TokenId {
}
private static final String INVALID = "<invalid>";
- private static WeakHashMap invalidNamesMap = new WeakHashMap();
- private Hashtable invalidNames = null;
+ private static Map<ClassPool, Reference<Map<String,String>>> invalidNamesMap =
+ new WeakHashMap<ClassPool, Reference<Map<String,String>>>();
+ private Map<String,String> invalidNames = null;
// for unit tests
public static int getInvalidMapSize() { return invalidNamesMap.size(); }
- private Hashtable getInvalidNames() {
- Hashtable ht = invalidNames;
+ private Map<String,String> getInvalidNames() {
+ Map<String,String> ht = invalidNames;
if (ht == null) {
synchronized (MemberResolver.class) {
- WeakReference ref = (WeakReference)invalidNamesMap.get(classPool);
+ Reference<Map<String,String>> ref = invalidNamesMap.get(classPool);
if (ref != null)
- ht = (Hashtable)ref.get();
+ ht = ref.get();
if (ht == null) {
- ht = new Hashtable();
- invalidNamesMap.put(classPool, new WeakReference(ht));
+ ht = new Hashtable<String,String>();
+ invalidNamesMap.put(classPool, new WeakReference<Map<String,String>>(ht));
}
}
@@ -449,10 +458,10 @@ public class MemberResolver implements TokenId {
throws CompileError
{
if (orgName.indexOf('.') < 0) {
- Iterator it = classPool.getImportedPackages();
+ Iterator<String> it = classPool.getImportedPackages();
while (it.hasNext()) {
- String pac = (String)it.next();
- String fqName = pac + '.' + orgName;
+ String pac = it.next();
+ String fqName = pac.replaceAll("\\.$","") + "." + orgName;
try {
return classPool.get(fqName);
}
@@ -482,11 +491,9 @@ public class MemberResolver implements TokenId {
int i = classname.lastIndexOf('.');
if (notCheckInner || i < 0)
throw e;
- else {
- StringBuffer sbuf = new StringBuffer(classname);
- sbuf.setCharAt(i, '$');
- classname = sbuf.toString();
- }
+ StringBuffer sbuf = new StringBuffer(classname);
+ sbuf.setCharAt(i, '$');
+ classname = sbuf.toString();
}
} while (cc == null);
return cc;
@@ -500,8 +507,7 @@ public class MemberResolver implements TokenId {
public String resolveClassName(ASTList name) throws CompileError {
if (name == null)
return null;
- else
- return javaToJvmName(lookupClassByName(name).getName());
+ return javaToJvmName(lookupClassByName(name).getName());
}
/* Expands a simple class name to java.lang.*.
@@ -510,8 +516,7 @@ public class MemberResolver implements TokenId {
public String resolveJvmClassName(String jvmName) throws CompileError {
if (jvmName == null)
return null;
- else
- return javaToJvmName(lookupClassByJvmName(jvmName).getName());
+ return javaToJvmName(lookupClassByJvmName(jvmName).getName());
}
public static CtClass getSuperclass(CtClass c) throws CompileError {
diff --git a/src/main/javassist/compiler/NoFieldException.java b/src/main/javassist/compiler/NoFieldException.java
index 7f84ad23..dd878590 100644
--- a/src/main/javassist/compiler/NoFieldException.java
+++ b/src/main/javassist/compiler/NoFieldException.java
@@ -19,6 +19,8 @@ package javassist.compiler;
import javassist.compiler.ast.ASTree;
public class NoFieldException extends CompileError {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
private String fieldName;
private ASTree expr;
diff --git a/src/main/javassist/compiler/Parser.java b/src/main/javassist/compiler/Parser.java
index 2a1d5d63..c67d49ec 100644
--- a/src/main/javassist/compiler/Parser.java
+++ b/src/main/javassist/compiler/Parser.java
@@ -16,7 +16,29 @@
package javassist.compiler;
-import javassist.compiler.ast.*;
+import javassist.compiler.ast.ASTList;
+import javassist.compiler.ast.ASTree;
+import javassist.compiler.ast.ArrayInit;
+import javassist.compiler.ast.AssignExpr;
+import javassist.compiler.ast.BinExpr;
+import javassist.compiler.ast.CallExpr;
+import javassist.compiler.ast.CastExpr;
+import javassist.compiler.ast.CondExpr;
+import javassist.compiler.ast.Declarator;
+import javassist.compiler.ast.DoubleConst;
+import javassist.compiler.ast.Expr;
+import javassist.compiler.ast.FieldDecl;
+import javassist.compiler.ast.InstanceOfExpr;
+import javassist.compiler.ast.IntConst;
+import javassist.compiler.ast.Keyword;
+import javassist.compiler.ast.Member;
+import javassist.compiler.ast.MethodDecl;
+import javassist.compiler.ast.NewExpr;
+import javassist.compiler.ast.Pair;
+import javassist.compiler.ast.Stmnt;
+import javassist.compiler.ast.StringL;
+import javassist.compiler.ast.Symbol;
+import javassist.compiler.ast.Variable;
public final class Parser implements TokenId {
private Lex lex;
@@ -34,8 +56,7 @@ public final class Parser implements TokenId {
ASTList mem = parseMember1(tbl);
if (mem instanceof MethodDecl)
return parseMethod2(tbl, (MethodDecl)mem);
- else
- return mem;
+ return mem;
}
/* A method body is not parsed.
@@ -63,8 +84,7 @@ public final class Parser implements TokenId {
d.setVariable(new Symbol(name));
if (isConstructor || lex.lookAhead() == '(')
return parseMethod1(tbl, isConstructor, mods, d);
- else
- return parseField(tbl, mods, d);
+ return parseField(tbl, mods, d);
}
/* field.declaration
@@ -188,11 +208,9 @@ public final class Parser implements TokenId {
int dim = parseArrayDimension();
return new Declarator(t, dim);
}
- else {
- ASTList name = parseClassType(tbl);
- int dim = parseArrayDimension();
- return new Declarator(name, dim);
- }
+ ASTList name = parseClassType(tbl);
+ int dim = parseArrayDimension();
+ return new Declarator(name, dim);
}
private static boolean isBuiltinType(int t) {
@@ -294,8 +312,7 @@ public final class Parser implements TokenId {
lex.get(); // '}'
if (body == null)
return new Stmnt(BLOCK); // empty block
- else
- return body;
+ return body;
}
/* if.statement : IF "(" expression ")" statement
@@ -654,8 +671,7 @@ public final class Parser implements TokenId {
private ASTree parseInitializer(SymbolTable tbl) throws CompileError {
if (lex.lookAhead() == '{')
return parseArrayInitializer(tbl);
- else
- return parseExpression(tbl);
+ return parseExpression(tbl);
}
/* array.initializer :
@@ -726,8 +742,7 @@ public final class Parser implements TokenId {
ASTree elseExpr = parseExpression(tbl);
return new CondExpr(cond, thenExpr, elseExpr);
}
- else
- return cond;
+ return cond;
}
/* logical.or.expr 10 (operator precedence)
@@ -778,8 +793,7 @@ public final class Parser implements TokenId {
int p = getOpPrecedence(t);
if (p == 0)
return expr;
- else
- expr = binaryExpr2(tbl, expr, p);
+ expr = binaryExpr2(tbl, expr, p);
}
}
@@ -792,11 +806,9 @@ public final class Parser implements TokenId {
int dim = parseArrayDimension();
return new InstanceOfExpr(t, dim, expr);
}
- else {
- ASTList name = parseClassType(tbl);
- int dim = parseArrayDimension();
- return new InstanceOfExpr(name, dim, expr);
- }
+ ASTList name = parseClassType(tbl);
+ int dim = parseArrayDimension();
+ return new InstanceOfExpr(name, dim, expr);
}
private ASTree binaryExpr2(SymbolTable tbl, ASTree expr, int prec)
@@ -922,6 +934,7 @@ public final class Parser implements TokenId {
}
private boolean nextIsBuiltinCast() {
+ @SuppressWarnings("unused")
int t;
int i = 2;
while ((t = lex.lookAhead(i++)) == '[')
@@ -949,6 +962,7 @@ public final class Parser implements TokenId {
}
private int nextIsClassType(int i) {
+ @SuppressWarnings("unused")
int t;
while (lex.lookAhead(++i) == '.')
if (lex.lookAhead(++i) != Identifier)
@@ -1117,43 +1131,41 @@ public final class Parser implements TokenId {
String cname = CodeGen.toJvmTypeName(builtinType, dim);
return Expr.make('.', new Symbol(cname), new Member("class"));
}
- else {
- String cname;
- switch(builtinType) {
- case BOOLEAN :
- cname = "java.lang.Boolean";
- break;
- case BYTE :
- cname = "java.lang.Byte";
- break;
- case CHAR :
- cname = "java.lang.Character";
- break;
- case SHORT :
- cname = "java.lang.Short";
- break;
- case INT :
- cname = "java.lang.Integer";
- break;
- case LONG :
- cname = "java.lang.Long";
- break;
- case FLOAT :
- cname = "java.lang.Float";
- break;
- case DOUBLE :
- cname = "java.lang.Double";
- break;
- case VOID :
- cname = "java.lang.Void";
- break;
- default :
- throw new CompileError("invalid builtin type: "
- + builtinType);
- }
-
- return Expr.make(MEMBER, new Symbol(cname), new Member("TYPE"));
+ String cname;
+ switch(builtinType) {
+ case BOOLEAN :
+ cname = "java.lang.Boolean";
+ break;
+ case BYTE :
+ cname = "java.lang.Byte";
+ break;
+ case CHAR :
+ cname = "java.lang.Character";
+ break;
+ case SHORT :
+ cname = "java.lang.Short";
+ break;
+ case INT :
+ cname = "java.lang.Integer";
+ break;
+ case LONG :
+ cname = "java.lang.Long";
+ break;
+ case FLOAT :
+ cname = "java.lang.Float";
+ break;
+ case DOUBLE :
+ cname = "java.lang.Double";
+ break;
+ case VOID :
+ cname = "java.lang.Void";
+ break;
+ default :
+ throw new CompileError("invalid builtin type: "
+ + builtinType);
}
+
+ return Expr.make(MEMBER, new Symbol(cname), new Member("TYPE"));
}
/* method.call : method.expr "(" argument.list ")"
@@ -1236,8 +1248,7 @@ public final class Parser implements TokenId {
decl = tbl.lookup(name);
if (decl == null)
return new Member(name); // this or static member
- else
- return new Variable(name, decl); // local variable
+ return new Variable(name, decl); // local variable
case StringL :
return new StringL(lex.getString());
case NEW :
@@ -1246,8 +1257,7 @@ public final class Parser implements TokenId {
expr = parseExpression(tbl);
if (lex.get() == ')')
return expr;
- else
- throw new CompileError(") is missing", lex);
+ throw new CompileError(") is missing", lex);
default :
if (isBuiltinType(t) || t == VOID) {
int dim = parseArrayDimension();
@@ -1311,13 +1321,11 @@ public final class Parser implements TokenId {
lex.get();
return null;
}
- else {
- ASTree index = parseExpression(tbl);
- if (lex.get() != ']')
- throw new CompileError("] is missing", lex);
+ ASTree index = parseExpression(tbl);
+ if (lex.get() != ']')
+ throw new CompileError("] is missing", lex);
- return index;
- }
+ return index;
}
/* argument.list : "(" [ expression [ "," expression ]* ] ")"
diff --git a/src/main/javassist/compiler/SymbolTable.java b/src/main/javassist/compiler/SymbolTable.java
index a8e0dd72..e23f8ac7 100644
--- a/src/main/javassist/compiler/SymbolTable.java
+++ b/src/main/javassist/compiler/SymbolTable.java
@@ -17,9 +17,12 @@
package javassist.compiler;
import java.util.HashMap;
+
import javassist.compiler.ast.Declarator;
-public final class SymbolTable extends HashMap {
+public final class SymbolTable extends HashMap<String,Declarator> {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
private SymbolTable parent;
public SymbolTable() { this(null); }
@@ -32,11 +35,10 @@ public final class SymbolTable extends HashMap {
public SymbolTable getParent() { return parent; }
public Declarator lookup(String name) {
- Declarator found = (Declarator)get(name);
+ Declarator found = get(name);
if (found == null && parent != null)
return parent.lookup(name);
- else
- return found;
+ return found;
}
public void append(String name, Declarator value) {
diff --git a/src/main/javassist/compiler/SyntaxError.java b/src/main/javassist/compiler/SyntaxError.java
index fdf357c8..ed759bb0 100644
--- a/src/main/javassist/compiler/SyntaxError.java
+++ b/src/main/javassist/compiler/SyntaxError.java
@@ -17,6 +17,9 @@
package javassist.compiler;
public class SyntaxError extends CompileError {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
public SyntaxError(Lex lexer) {
super("syntax error near \"" + lexer.getTextAround() + "\"", lexer);
}
diff --git a/src/main/javassist/compiler/TypeChecker.java b/src/main/javassist/compiler/TypeChecker.java
index bd62f806..9e01d0a1 100644
--- a/src/main/javassist/compiler/TypeChecker.java
+++ b/src/main/javassist/compiler/TypeChecker.java
@@ -16,13 +16,34 @@
package javassist.compiler;
+import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtField;
-import javassist.ClassPool;
import javassist.Modifier;
import javassist.NotFoundException;
-import javassist.compiler.ast.*;
-import javassist.bytecode.*;
+import javassist.bytecode.FieldInfo;
+import javassist.bytecode.MethodInfo;
+import javassist.bytecode.Opcode;
+import javassist.compiler.ast.ASTList;
+import javassist.compiler.ast.ASTree;
+import javassist.compiler.ast.ArrayInit;
+import javassist.compiler.ast.AssignExpr;
+import javassist.compiler.ast.BinExpr;
+import javassist.compiler.ast.CallExpr;
+import javassist.compiler.ast.CastExpr;
+import javassist.compiler.ast.CondExpr;
+import javassist.compiler.ast.Declarator;
+import javassist.compiler.ast.DoubleConst;
+import javassist.compiler.ast.Expr;
+import javassist.compiler.ast.InstanceOfExpr;
+import javassist.compiler.ast.IntConst;
+import javassist.compiler.ast.Keyword;
+import javassist.compiler.ast.Member;
+import javassist.compiler.ast.NewExpr;
+import javassist.compiler.ast.StringL;
+import javassist.compiler.ast.Symbol;
+import javassist.compiler.ast.Variable;
+import javassist.compiler.ast.Visitor;
public class TypeChecker extends Visitor implements Opcode, TokenId {
static final String javaLangObject = "java.lang.Object";
@@ -139,6 +160,7 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
return resolver.resolveJvmClassName(jvmName);
}
+ @Override
public void atNewExpr(NewExpr expr) throws CompileError {
if (expr.isArray())
atNewArrayExpr(expr);
@@ -177,6 +199,7 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
}
}
+ @Override
public void atArrayInit(ArrayInit init) throws CompileError {
ASTList list = init;
while (list != null) {
@@ -190,6 +213,7 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
protected void atMultiNewArray(int type, ASTList classname, ASTList size)
throws CompileError
{
+ @SuppressWarnings("unused")
int count, dim;
dim = size.length();
for (count = 0; size != null; size = size.tail()) {
@@ -209,6 +233,7 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
className = null;
}
+ @Override
public void atAssignExpr(AssignExpr expr) throws CompileError {
// =, %=, &=, *=, /=, +=, -=, ^=, |=, <<=, >>=, >>>=
int op = expr.getOperator();
@@ -279,11 +304,13 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
className = cname;
}
+ @Override
public void atCondExpr(CondExpr expr) throws CompileError {
booleanExpr(expr.condExpr());
expr.thenExpr().accept(this);
int type1 = exprType;
int dim1 = arrayDim;
+ @SuppressWarnings("unused")
String cname1 = className;
expr.elseExpr().accept(this);
@@ -302,6 +329,7 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
* (if the original is not '+') and sets the new expression to the
* left-hand-side expression and null to the right-hand-side expression.
*/
+ @Override
public void atBinExpr(BinExpr expr) throws CompileError {
int token = expr.getOperator();
int k = CodeGen.lookupBinOp(token);
@@ -384,10 +412,8 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
className = "java/lang/StringBuffer";
return makeAppendCall(makeAppendCall(e, left), right);
}
- else {
- computeBinExprType(expr, '+', type1);
- return null;
- }
+ computeBinExprType(expr, '+', type1);
+ return null;
}
private boolean isConstant(BinExpr expr, int op, ASTree left,
@@ -406,13 +432,11 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
if (newExpr == null)
return false; // not a constant expression
- else {
- expr.setOperator('+');
- expr.setOprand1(newExpr);
- expr.setOprand2(null);
- newExpr.accept(this); // for setting exprType, arrayDim, ...
- return true;
- }
+ expr.setOperator('+');
+ expr.setOprand1(newExpr);
+ expr.setOprand2(null);
+ newExpr.accept(this); // for setting exprType, arrayDim, ...
+ return true;
}
/* CodeGen.atSwitchStmnt() also calls stripPlusExpr().
@@ -542,6 +566,7 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
exprType = type1;
}
+ @Override
public void atCastExpr(CastExpr expr) throws CompileError {
String cname = resolveClassName(expr.getClassName());
expr.getOprand().accept(this);
@@ -550,12 +575,14 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
className = cname;
}
+ @Override
public void atInstanceOfExpr(InstanceOfExpr expr) throws CompileError {
expr.getOprand().accept(this);
exprType = BOOLEAN;
arrayDim = 0;
}
+ @Override
public void atExpr(Expr expr) throws CompileError {
// array access, member access,
// (unary) +, (unary) -, ++, --, !, ~
@@ -572,14 +599,14 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
// length might be a class or package name.
atFieldRead(expr);
}
- else if (member.equals("class"))
+ else if (member.equals("class"))
atClassObject(expr); // .class
else
atFieldRead(expr);
}
else if (token == MEMBER) { // field read
String member = ((Symbol)expr.oprand2()).get();
- if (member.equals("class"))
+ if (member.equals("class"))
atClassObject(expr); // .class
else
atFieldRead(expr);
@@ -629,6 +656,7 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
return true;
}
+ @Override
public void atCallExpr(CallExpr expr) throws CompileError {
String mname = null;
CtClass targetClass = null;
@@ -739,7 +767,7 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
mname, types, dims, cnames);
if (found == null) {
String clazz = targetClass.getName();
- String signature = argTypesToString(types, dims, cnames);
+ String signature = argTypesToString(types, dims, cnames);
String msg;
if (mname.equals(MethodInfo.nameInit))
msg = "cannot find constructor " + clazz + signature;
@@ -896,7 +924,7 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
* often inconvenient, this compiler allows it. The following
* code is for that.
*/
- ASTree oprnd1 = e.oprand1();
+ ASTree oprnd1 = e.oprand1();
if (oprnd1 instanceof Symbol)
return fieldAccess2(e, ((Symbol)oprnd1).get());
@@ -984,10 +1012,12 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
exprType = INT;
}
+ @Override
public void atMember(Member mem) throws CompileError {
atFieldRead(mem);
}
+ @Override
public void atVariable(Variable v) throws CompileError {
Declarator d = v.getDeclarator();
exprType = d.getType();
@@ -995,6 +1025,7 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
className = d.getClassName();
}
+ @Override
public void atKeyword(Keyword k) throws CompileError {
arrayDim = 0;
int token = k.get();
@@ -1012,19 +1043,21 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
if (token == THIS)
className = getThisName();
else
- className = getSuperName();
+ className = getSuperName();
break;
default :
fatal();
}
}
+ @Override
public void atStringL(StringL s) throws CompileError {
exprType = CLASS;
arrayDim = 0;
className = jvmJavaLangString;
}
+ @Override
public void atIntConst(IntConst i) throws CompileError {
arrayDim = 0;
int type = i.getType();
@@ -1034,6 +1067,7 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
exprType = LONG;
}
+ @Override
public void atDoubleConst(DoubleConst d) throws CompileError {
arrayDim = 0;
if (d.getType() == DoubleConstant)
diff --git a/src/main/javassist/compiler/ast/ASTList.java b/src/main/javassist/compiler/ast/ASTList.java
index cf398966..67fbd97a 100644
--- a/src/main/javassist/compiler/ast/ASTList.java
+++ b/src/main/javassist/compiler/ast/ASTList.java
@@ -23,6 +23,8 @@ import javassist.compiler.CompileError;
* The right subtree must be an ASTList object or null.
*/
public class ASTList extends ASTree {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
private ASTree left;
private ASTList right;
@@ -40,12 +42,16 @@ public class ASTList extends ASTree {
return new ASTList(e1, new ASTList(e2, new ASTList(e3)));
}
+ @Override
public ASTree getLeft() { return left; }
+ @Override
public ASTree getRight() { return right; }
+ @Override
public void setLeft(ASTree _left) { left = _left; }
+ @Override
public void setRight(ASTree _right) {
right = (ASTList)_right;
}
@@ -68,8 +74,10 @@ public class ASTList extends ASTree {
right = _tail;
}
+ @Override
public void accept(Visitor v) throws CompileError { v.atASTList(this); }
+ @Override
public String toString() {
StringBuffer sbuf = new StringBuffer();
sbuf.append("(<");
@@ -148,13 +156,11 @@ public class ASTList extends ASTree {
public static ASTList concat(ASTList a, ASTList b) {
if (a == null)
return b;
- else {
- ASTList list = a;
- while (list.right != null)
- list = list.right;
+ ASTList list = a;
+ while (list.right != null)
+ list = list.right;
- list.right = b;
- return a;
- }
+ list.right = b;
+ return a;
}
}
diff --git a/src/main/javassist/compiler/ast/ASTree.java b/src/main/javassist/compiler/ast/ASTree.java
index aaad0732..7fd05fd4 100644
--- a/src/main/javassist/compiler/ast/ASTree.java
+++ b/src/main/javassist/compiler/ast/ASTree.java
@@ -17,6 +17,7 @@
package javassist.compiler.ast;
import java.io.Serializable;
+
import javassist.compiler.CompileError;
/**
@@ -25,6 +26,9 @@ import javassist.compiler.CompileError;
* and <code>getRight()</code> returns null.
*/
public abstract class ASTree implements Serializable {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
public ASTree getLeft() { return null; }
public ASTree getRight() { return null; }
@@ -40,6 +44,7 @@ public abstract class ASTree implements Serializable {
*/
public abstract void accept(Visitor v) throws CompileError;
+ @Override
public String toString() {
StringBuffer sbuf = new StringBuffer();
sbuf.append('<');
diff --git a/src/main/javassist/compiler/ast/ArrayInit.java b/src/main/javassist/compiler/ast/ArrayInit.java
index 26838fca..f992f426 100644
--- a/src/main/javassist/compiler/ast/ArrayInit.java
+++ b/src/main/javassist/compiler/ast/ArrayInit.java
@@ -22,11 +22,16 @@ import javassist.compiler.CompileError;
* Array initializer such as <code>{ 1, 2, 3 }</code>.
*/
public class ArrayInit extends ASTList {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
public ArrayInit(ASTree firstElement) {
super(firstElement);
}
+ @Override
public void accept(Visitor v) throws CompileError { v.atArrayInit(this); }
+ @Override
public String getTag() { return "array"; }
}
diff --git a/src/main/javassist/compiler/ast/AssignExpr.java b/src/main/javassist/compiler/ast/AssignExpr.java
index 060a5bd3..a5e1857d 100644
--- a/src/main/javassist/compiler/ast/AssignExpr.java
+++ b/src/main/javassist/compiler/ast/AssignExpr.java
@@ -26,6 +26,9 @@ public class AssignExpr extends Expr {
* =, %=, &=, *=, +=, -=, /=, ^=, |=, <<=, >>=, >>>=
*/
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
private AssignExpr(int op, ASTree _head, ASTList _tail) {
super(op, _head, _tail);
}
@@ -35,6 +38,7 @@ public class AssignExpr extends Expr {
return new AssignExpr(op, oprand1, new ASTList(oprand2));
}
+ @Override
public void accept(Visitor v) throws CompileError {
v.atAssignExpr(this);
}
diff --git a/src/main/javassist/compiler/ast/BinExpr.java b/src/main/javassist/compiler/ast/BinExpr.java
index 3b9f8ea2..9630ada9 100644
--- a/src/main/javassist/compiler/ast/BinExpr.java
+++ b/src/main/javassist/compiler/ast/BinExpr.java
@@ -30,6 +30,9 @@ public class BinExpr extends Expr {
* <<, >>, >>>, +, -, *, /, %
*/
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
private BinExpr(int op, ASTree _head, ASTList _tail) {
super(op, _head, _tail);
}
@@ -38,5 +41,6 @@ public class BinExpr extends Expr {
return new BinExpr(op, oprand1, new ASTList(oprand2));
}
+ @Override
public void accept(Visitor v) throws CompileError { v.atBinExpr(this); }
}
diff --git a/src/main/javassist/compiler/ast/CallExpr.java b/src/main/javassist/compiler/ast/CallExpr.java
index 5e3dd434..395915ed 100644
--- a/src/main/javassist/compiler/ast/CallExpr.java
+++ b/src/main/javassist/compiler/ast/CallExpr.java
@@ -17,13 +17,15 @@
package javassist.compiler.ast;
import javassist.compiler.CompileError;
-import javassist.compiler.TokenId;
import javassist.compiler.MemberResolver;
+import javassist.compiler.TokenId;
/**
* Method call expression.
*/
public class CallExpr extends Expr {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
private MemberResolver.Method method; // cached result of lookupMethod()
private CallExpr(ASTree _head, ASTList _tail) {
@@ -43,5 +45,6 @@ public class CallExpr extends Expr {
return new CallExpr(target, new ASTList(args));
}
+ @Override
public void accept(Visitor v) throws CompileError { v.atCallExpr(this); }
}
diff --git a/src/main/javassist/compiler/ast/CastExpr.java b/src/main/javassist/compiler/ast/CastExpr.java
index 7d4f4d80..903e5bbd 100644
--- a/src/main/javassist/compiler/ast/CastExpr.java
+++ b/src/main/javassist/compiler/ast/CastExpr.java
@@ -16,13 +16,15 @@
package javassist.compiler.ast;
-import javassist.compiler.TokenId;
import javassist.compiler.CompileError;
+import javassist.compiler.TokenId;
/**
* Cast expression.
*/
public class CastExpr extends ASTList implements TokenId {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
protected int castType;
protected int arrayDim;
@@ -50,7 +52,9 @@ public class CastExpr extends ASTList implements TokenId {
public void setOprand(ASTree t) { getRight().setLeft(t); }
+ @Override
public String getTag() { return "cast:" + castType + ":" + arrayDim; }
+ @Override
public void accept(Visitor v) throws CompileError { v.atCastExpr(this); }
}
diff --git a/src/main/javassist/compiler/ast/CondExpr.java b/src/main/javassist/compiler/ast/CondExpr.java
index 8645736f..46435012 100644
--- a/src/main/javassist/compiler/ast/CondExpr.java
+++ b/src/main/javassist/compiler/ast/CondExpr.java
@@ -22,6 +22,9 @@ import javassist.compiler.CompileError;
* Conditional expression.
*/
public class CondExpr extends ASTList {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
public CondExpr(ASTree cond, ASTree thenp, ASTree elsep) {
super(cond, new ASTList(thenp, new ASTList(elsep)));
}
@@ -38,7 +41,9 @@ public class CondExpr extends ASTList {
public void setElse(ASTree t) { tail().tail().setHead(t); }
+ @Override
public String getTag() { return "?:"; }
+ @Override
public void accept(Visitor v) throws CompileError { v.atCondExpr(this); }
}
diff --git a/src/main/javassist/compiler/ast/Declarator.java b/src/main/javassist/compiler/ast/Declarator.java
index 5f14ac57..24170db0 100644
--- a/src/main/javassist/compiler/ast/Declarator.java
+++ b/src/main/javassist/compiler/ast/Declarator.java
@@ -16,13 +16,15 @@
package javassist.compiler.ast;
-import javassist.compiler.TokenId;
import javassist.compiler.CompileError;
+import javassist.compiler.TokenId;
/**
* Variable declarator.
*/
public class Declarator extends ASTList implements TokenId {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
protected int varType;
protected int arrayDim;
protected int localVar;
@@ -86,16 +88,17 @@ public class Declarator extends ASTList implements TokenId {
ASTList t = tail();
if (t != null)
return t.head();
- else
- return null;
+ return null;
}
public void setLocalVar(int n) { localVar = n; }
public int getLocalVar() { return localVar; }
+ @Override
public String getTag() { return "decl"; }
+ @Override
public void accept(Visitor v) throws CompileError {
v.atDeclarator(this);
}
diff --git a/src/main/javassist/compiler/ast/DoubleConst.java b/src/main/javassist/compiler/ast/DoubleConst.java
index 23ff0b65..f8d0afde 100644
--- a/src/main/javassist/compiler/ast/DoubleConst.java
+++ b/src/main/javassist/compiler/ast/DoubleConst.java
@@ -23,6 +23,8 @@ import javassist.compiler.TokenId;
* Double constant.
*/
public class DoubleConst extends ASTree {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
protected double value;
protected int type;
@@ -36,8 +38,10 @@ public class DoubleConst extends ASTree {
*/
public int getType() { return type; }
+ @Override
public String toString() { return Double.toString(value); }
+ @Override
public void accept(Visitor v) throws CompileError {
v.atDoubleConst(this);
}
@@ -63,7 +67,7 @@ public class DoubleConst extends ASTree {
}
private DoubleConst compute0(int op, IntConst right) {
- return compute(op, this.value, (double)right.value, this.type);
+ return compute(op, this.value, right.value, this.type);
}
private static DoubleConst compute(int op, double value1, double value2,
diff --git a/src/main/javassist/compiler/ast/Expr.java b/src/main/javassist/compiler/ast/Expr.java
index bc798bbc..ed5cb60b 100644
--- a/src/main/javassist/compiler/ast/Expr.java
+++ b/src/main/javassist/compiler/ast/Expr.java
@@ -16,8 +16,8 @@
package javassist.compiler.ast;
-import javassist.compiler.TokenId;
import javassist.compiler.CompileError;
+import javassist.compiler.TokenId;
/**
* Expression.
@@ -29,6 +29,8 @@ public class Expr extends ASTList implements TokenId {
* Otherwise, the object should be an instance of a subclass.
*/
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
protected int operatorId;
Expr(int op, ASTree _head, ASTList _tail) {
@@ -65,6 +67,7 @@ public class Expr extends ASTList implements TokenId {
getRight().setLeft(expr);
}
+ @Override
public void accept(Visitor v) throws CompileError { v.atExpr(this); }
public String getName() {
@@ -79,6 +82,7 @@ public class Expr extends ASTList implements TokenId {
return String.valueOf(id);
}
+ @Override
protected String getTag() {
return "op:" + getName();
}
diff --git a/src/main/javassist/compiler/ast/FieldDecl.java b/src/main/javassist/compiler/ast/FieldDecl.java
index 82d4856c..e2a066e9 100644
--- a/src/main/javassist/compiler/ast/FieldDecl.java
+++ b/src/main/javassist/compiler/ast/FieldDecl.java
@@ -19,6 +19,9 @@ package javassist.compiler.ast;
import javassist.compiler.CompileError;
public class FieldDecl extends ASTList {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
public FieldDecl(ASTree _head, ASTList _tail) {
super(_head, _tail);
}
@@ -27,8 +30,9 @@ public class FieldDecl extends ASTList {
public Declarator getDeclarator() { return (Declarator)tail().head(); }
- public ASTree getInit() { return (ASTree)sublist(2).head(); }
+ public ASTree getInit() { return sublist(2).head(); }
+ @Override
public void accept(Visitor v) throws CompileError {
v.atFieldDecl(this);
}
diff --git a/src/main/javassist/compiler/ast/InstanceOfExpr.java b/src/main/javassist/compiler/ast/InstanceOfExpr.java
index cddf0317..ddf07bd2 100644
--- a/src/main/javassist/compiler/ast/InstanceOfExpr.java
+++ b/src/main/javassist/compiler/ast/InstanceOfExpr.java
@@ -22,6 +22,9 @@ import javassist.compiler.CompileError;
* Instanceof expression.
*/
public class InstanceOfExpr extends CastExpr {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
public InstanceOfExpr(ASTList className, int dim, ASTree expr) {
super(className, dim, expr);
}
@@ -30,10 +33,12 @@ public class InstanceOfExpr extends CastExpr {
super(type, dim, expr);
}
+ @Override
public String getTag() {
return "instanceof:" + castType + ":" + arrayDim;
}
+ @Override
public void accept(Visitor v) throws CompileError {
v.atInstanceOfExpr(this);
}
diff --git a/src/main/javassist/compiler/ast/IntConst.java b/src/main/javassist/compiler/ast/IntConst.java
index 90feeb58..7040b0c9 100644
--- a/src/main/javassist/compiler/ast/IntConst.java
+++ b/src/main/javassist/compiler/ast/IntConst.java
@@ -23,6 +23,8 @@ import javassist.compiler.TokenId;
* Integer constant.
*/
public class IntConst extends ASTree {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
protected long value;
protected int type;
@@ -36,8 +38,10 @@ public class IntConst extends ASTree {
*/
public int getType() { return type; }
+ @Override
public String toString() { return Long.toString(value); }
+ @Override
public void accept(Visitor v) throws CompileError {
v.atIntConst(this);
}
@@ -111,7 +115,7 @@ public class IntConst extends ASTree {
}
private DoubleConst compute0(int op, DoubleConst right) {
- double value1 = (double)this.value;
+ double value1 = this.value;
double value2 = right.value;
double newValue;
switch (op) {
diff --git a/src/main/javassist/compiler/ast/Keyword.java b/src/main/javassist/compiler/ast/Keyword.java
index 8127dc1e..b509375c 100644
--- a/src/main/javassist/compiler/ast/Keyword.java
+++ b/src/main/javassist/compiler/ast/Keyword.java
@@ -22,6 +22,8 @@ import javassist.compiler.CompileError;
* Keyword.
*/
public class Keyword extends ASTree {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
protected int tokenId;
public Keyword(int token) {
@@ -30,7 +32,9 @@ public class Keyword extends ASTree {
public int get() { return tokenId; }
+ @Override
public String toString() { return "id:" + tokenId; }
+ @Override
public void accept(Visitor v) throws CompileError { v.atKeyword(this); }
}
diff --git a/src/main/javassist/compiler/ast/Member.java b/src/main/javassist/compiler/ast/Member.java
index f77de616..192c9ef3 100644
--- a/src/main/javassist/compiler/ast/Member.java
+++ b/src/main/javassist/compiler/ast/Member.java
@@ -16,13 +16,15 @@
package javassist.compiler.ast;
-import javassist.compiler.CompileError;
import javassist.CtField;
+import javassist.compiler.CompileError;
/**
* Member name.
*/
public class Member extends Symbol {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
// cache maintained by fieldAccess() in TypeChecker.
// this is used to obtain the value of a static final field.
private CtField field;
@@ -36,5 +38,6 @@ public class Member extends Symbol {
public CtField getField() { return field; }
+ @Override
public void accept(Visitor v) throws CompileError { v.atMember(this); }
}
diff --git a/src/main/javassist/compiler/ast/MethodDecl.java b/src/main/javassist/compiler/ast/MethodDecl.java
index 0a7d828f..d96e3d4d 100644
--- a/src/main/javassist/compiler/ast/MethodDecl.java
+++ b/src/main/javassist/compiler/ast/MethodDecl.java
@@ -19,6 +19,8 @@ package javassist.compiler.ast;
import javassist.compiler.CompileError;
public class MethodDecl extends ASTList {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
public static final String initName = "<init>";
public MethodDecl(ASTree _head, ASTList _tail) {
@@ -40,6 +42,7 @@ public class MethodDecl extends ASTList {
public Stmnt getBody() { return (Stmnt)sublist(4).head(); }
+ @Override
public void accept(Visitor v) throws CompileError {
v.atMethodDecl(this);
}
diff --git a/src/main/javassist/compiler/ast/NewExpr.java b/src/main/javassist/compiler/ast/NewExpr.java
index b1413f60..44b264c0 100644
--- a/src/main/javassist/compiler/ast/NewExpr.java
+++ b/src/main/javassist/compiler/ast/NewExpr.java
@@ -16,13 +16,15 @@
package javassist.compiler.ast;
-import javassist.compiler.TokenId;
import javassist.compiler.CompileError;
+import javassist.compiler.TokenId;
/**
* New Expression.
*/
public class NewExpr extends ASTList implements TokenId {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
protected boolean newArray;
protected int arrayType;
@@ -66,12 +68,13 @@ public class NewExpr extends ASTList implements TokenId {
ASTree t = getRight().getRight();
if (t == null)
return null;
- else
- return (ArrayInit)t.getLeft();
+ return (ArrayInit)t.getLeft();
}
+ @Override
public void accept(Visitor v) throws CompileError { v.atNewExpr(this); }
+ @Override
protected String getTag() {
return newArray ? "new[]" : "new";
}
diff --git a/src/main/javassist/compiler/ast/Pair.java b/src/main/javassist/compiler/ast/Pair.java
index b050dd28..840c1145 100644
--- a/src/main/javassist/compiler/ast/Pair.java
+++ b/src/main/javassist/compiler/ast/Pair.java
@@ -23,6 +23,8 @@ import javassist.compiler.CompileError;
* overriding abstract methods in ASTree.
*/
public class Pair extends ASTree {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
protected ASTree left, right;
public Pair(ASTree _left, ASTree _right) {
@@ -30,8 +32,10 @@ public class Pair extends ASTree {
right = _right;
}
+ @Override
public void accept(Visitor v) throws CompileError { v.atPair(this); }
+ @Override
public String toString() {
StringBuffer sbuf = new StringBuffer();
sbuf.append("(<Pair> ");
@@ -42,11 +46,15 @@ public class Pair extends ASTree {
return sbuf.toString();
}
+ @Override
public ASTree getLeft() { return left; }
+ @Override
public ASTree getRight() { return right; }
+ @Override
public void setLeft(ASTree _left) { left = _left; }
+ @Override
public void setRight(ASTree _right) { right = _right; }
}
diff --git a/src/main/javassist/compiler/ast/Stmnt.java b/src/main/javassist/compiler/ast/Stmnt.java
index 251f66c3..c5aa5df3 100644
--- a/src/main/javassist/compiler/ast/Stmnt.java
+++ b/src/main/javassist/compiler/ast/Stmnt.java
@@ -16,13 +16,15 @@
package javassist.compiler.ast;
-import javassist.compiler.TokenId;
import javassist.compiler.CompileError;
+import javassist.compiler.TokenId;
/**
* Statement.
*/
public class Stmnt extends ASTList implements TokenId {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
protected int operatorId;
public Stmnt(int op, ASTree _head, ASTList _tail) {
@@ -47,14 +49,15 @@ public class Stmnt extends ASTList implements TokenId {
return new Stmnt(op, op1, new ASTList(op2, new ASTList(op3)));
}
+ @Override
public void accept(Visitor v) throws CompileError { v.atStmnt(this); }
public int getOperator() { return operatorId; }
+ @Override
protected String getTag() {
if (operatorId < 128)
return "stmnt:" + (char)operatorId;
- else
- return "stmnt:" + operatorId;
+ return "stmnt:" + operatorId;
}
}
diff --git a/src/main/javassist/compiler/ast/StringL.java b/src/main/javassist/compiler/ast/StringL.java
index f52186e5..7c7e00c3 100644
--- a/src/main/javassist/compiler/ast/StringL.java
+++ b/src/main/javassist/compiler/ast/StringL.java
@@ -22,6 +22,8 @@ import javassist.compiler.CompileError;
* String literal.
*/
public class StringL extends ASTree {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
protected String text;
public StringL(String t) {
@@ -30,7 +32,9 @@ public class StringL extends ASTree {
public String get() { return text; }
+ @Override
public String toString() { return "\"" + text + "\""; }
+ @Override
public void accept(Visitor v) throws CompileError { v.atStringL(this); }
}
diff --git a/src/main/javassist/compiler/ast/Symbol.java b/src/main/javassist/compiler/ast/Symbol.java
index f71d0f91..2b66207a 100644
--- a/src/main/javassist/compiler/ast/Symbol.java
+++ b/src/main/javassist/compiler/ast/Symbol.java
@@ -22,6 +22,8 @@ import javassist.compiler.CompileError;
* Identifier.
*/
public class Symbol extends ASTree {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
protected String identifier;
public Symbol(String sym) {
@@ -30,7 +32,9 @@ public class Symbol extends ASTree {
public String get() { return identifier; }
+ @Override
public String toString() { return identifier; }
+ @Override
public void accept(Visitor v) throws CompileError { v.atSymbol(this); }
}
diff --git a/src/main/javassist/compiler/ast/Variable.java b/src/main/javassist/compiler/ast/Variable.java
index 88a31daa..c9224a7a 100644
--- a/src/main/javassist/compiler/ast/Variable.java
+++ b/src/main/javassist/compiler/ast/Variable.java
@@ -22,6 +22,8 @@ import javassist.compiler.CompileError;
* Variable.
*/
public class Variable extends Symbol {
+ /** default serialVersionUID */
+ private static final long serialVersionUID = 1L;
protected Declarator declarator;
public Variable(String sym, Declarator d) {
@@ -31,9 +33,11 @@ public class Variable extends Symbol {
public Declarator getDeclarator() { return declarator; }
+ @Override
public String toString() {
return identifier + ":" + declarator.getType();
}
+ @Override
public void accept(Visitor v) throws CompileError { v.atVariable(this); }
}