From 33ce6656c3b8c08be8d9b9d7fdc4b70e7f290ecc Mon Sep 17 00:00:00 2001 From: chiba Date: Tue, 29 May 2007 09:22:02 +0000 Subject: [PATCH] changed the compiler so that .class will be compiled into ldc. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@376 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- .../javassist/bytecode/stackmap/TypeData.java | 2 +- .../javassist/compiler/MemberCodeGen.java | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/javassist/bytecode/stackmap/TypeData.java b/src/main/javassist/bytecode/stackmap/TypeData.java index 6c073702..ee2f296a 100644 --- a/src/main/javassist/bytecode/stackmap/TypeData.java +++ b/src/main/javassist/bytecode/stackmap/TypeData.java @@ -113,7 +113,7 @@ public abstract class TypeData { } protected void setType(String s, ClassPool cp) throws BadBytecode { - throw new BadBytecode("conflict:" + name + " and " + s); + throw new BadBytecode("conflict: " + name + " and " + s); } public String toString() { return name; } diff --git a/src/main/javassist/compiler/MemberCodeGen.java b/src/main/javassist/compiler/MemberCodeGen.java index 225844f9..bd77b878 100644 --- a/src/main/javassist/compiler/MemberCodeGen.java +++ b/src/main/javassist/compiler/MemberCodeGen.java @@ -24,13 +24,13 @@ import java.util.ArrayList; /* Code generator methods depending on javassist.* classes. */ public class MemberCodeGen extends CodeGen { + public static final int JAVA1_VER = 45; public static final int JAVA5_VER = 49; public static final int JAVA6_VER = 50; protected MemberResolver resolver; protected CtClass thisClass; protected MethodInfo thisMethod; - protected int version; // the major version of a class file. protected boolean resultStatic; @@ -39,11 +39,18 @@ public class MemberCodeGen extends CodeGen { resolver = new MemberResolver(cp); thisClass = cc; thisMethod = null; - ClassFile cf = cc.getClassFile2(); + } + + /** + * Returns the major version of the class file + * targeted by this compilation. + */ + public int getMajorVersion() { + ClassFile cf = thisClass.getClassFile2(); if (cf == null) - version = 0; + return JAVA1_VER; else - version = cf.getMajorVersion(); + return cf.getMajorVersion(); } /** @@ -918,7 +925,10 @@ public class MemberCodeGen extends CodeGen { } protected void atClassObject2(String cname) throws CompileError { - super.atClassObject2(cname); + if (getMajorVersion() < JAVA5_VER) + super.atClassObject2(cname); + else + bytecode.addLdc(bytecode.getConstPool().addClassInfo(cname)); } protected void atFieldPlusPlus(int token, boolean isPost, -- 2.39.5