Skip to content
Commits on Source (3)
.idea/
bin/
eclipse-output/
target/
runtest/
html/
lib/
tmp/
.DS_Store
.classpath
......
Java bytecode engineering toolkit
### [Javassist version 3](http://www.javassist.org)
Copyright (C) 1999- by Shigeru Chiba, All rights reserved.
Copyright (C) 1999-2018 by Shigeru Chiba, All rights reserved.
Javassist (JAVA programming ASSISTant) makes Java bytecode manipulation
simple. It is a class library for editing bytecodes in Java; it enables Java
......
......@@ -7,7 +7,7 @@
<h1>Javassist version 3</h1>
<h3>Copyright (C) 1999-2016 by Shigeru Chiba, All rights reserved.</h3>
<h3>Copyright (C) 1999-2018 by Shigeru Chiba, All rights reserved.</h3>
<p><br></p>
......@@ -281,6 +281,27 @@ see javassist.Dump.
<h2>Changes</h2>
<p>-version 3.23.1 on July 2, 2018
<ul>
<li>Github pull issue #171.</li>
</ul>
</p>
<p>-version 3.23 on June 21, 2018
<ul>
<li>Fix leaking file handlers in ClassPool and removed ClassPath.close(). Github issue #165.
</ul>
</p>
<p>-version 3.22 on October 10, 2017
<ul>
<li>Java 9 supports.
<li>JIRA JASSIST-261.
</ul>
</p>
<p>-version 3.21 on October 4, 2016
<ul>
<li>JIRA JASSIST-244, 245, 248, 250, 255, 256, 259, 262.
......
......@@ -6,7 +6,7 @@
<project name="javassist" default="jar" basedir=".">
<property name="dist-version" value="javassist-3.21.0-GA"/>
<property name="dist-version" value="javassist-3.23.1-GA"/>
<property environment="env"/>
<property name="target.jar" value="javassist.jar"/>
......@@ -16,8 +16,9 @@
<property name="build.dir" value="${basedir}/target"/>
<property name="build.classes.dir" value="${build.dir}/classes"/>
<property name="test.src.dir" value="${basedir}/src/test"/>
<property name="test.lib.dir" value="${test.src.dir}/resources"/>
<property name="test.build.dir" value="${build.dir}/test-classes"/>
<property name="test.run.dir" value="${basedir}/runtest"/>
<property name="test.run.dir" value="${build.dir}/runtest"/>
<property name="test.reports.dir" value = "${build.dir}/test-output"/>
<property name="run.dir" value="${build.classes.dir}"/>
......@@ -32,13 +33,16 @@
<path id="test.compile.classpath">
<pathelement location="${build.classes.dir}"/>
<pathelement location="${lib.dir}/junit.jar"/>
<pathelement location="${lib.dir}/hamcrest.jar"/>
</path>
<property name="test.compile.classpath" refid="test.compile.classpath"/>
<path id="test.classpath">
<pathelement location="${test.build.dir}"/>
<pathelement location="${test.lib.dir}"/>
<pathelement location="${lib.dir}/junit.jar"/>
<pathelement location="${lib.dir}/hamcrest.jar"/>
<pathelement location="${build.classes.dir}"/>
</path>
......@@ -98,12 +102,32 @@
</target>
<target name="runtest" depends="jar,test-compile">
<copy file="${test.lib.dir}/empty.jar"
tofile="${test.lib.dir}/emptyorig.jar"
preservelastmodified="true" />
<junit fork="true" printsummary="true" dir="${test.run.dir}">
<jvmarg value="-XX:-FailOverToOldVerifier"/>
<classpath refid="test.classpath"/>
<formatter type="xml" extension=".xml"/>
<test name="javassist.JvstTest" outfile="TestLog" />
</junit>
<move file="${test.lib.dir}/emptyorig.jar"
tofile="${test.lib.dir}/empty.jar" />
</target>
<target name="runtest9" depends="jar,test-compile">
<copy file="${test.lib.dir}/empty.jar"
tofile="${test.lib.dir}/emptyorig.jar"
preservelastmodified="true" />
<junit fork="true" printsummary="true" dir="${test.run.dir}">
<jvmarg line="--add-opens java.base/java.lang=ALL-UNNAMED" />
<jvmarg value="-XX:-FailOverToOldVerifier"/>
<classpath refid="test.classpath"/>
<formatter type="xml" extension=".xml"/>
<test name="javassist.JvstTest" outfile="TestLog" />
</junit>
<move file="${test.lib.dir}/emptyorig.jar"
tofile="${test.lib.dir}/empty.jar" />
</target>
<target name="sample" depends="compile">
......@@ -209,7 +233,6 @@ Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.</i>]]></bottom>
<target name="clean">
<delete dir="html"/>
<delete dir="${test.run.dir}" />
<delete dir="${build.dir}"/>
<delete file="${target.jar}"/>
<delete file="${dist-version}.zip"/>
......
......@@ -7,10 +7,13 @@
Javassist (JAVA programming ASSISTant) makes Java bytecode manipulation
simple. It is a class library for editing bytecodes in Java.
</description>
<version>3.21.0-GA</version>
<version>3.23.1-GA</version>
<name>Javassist</name>
<url>http://www.javassist.org/</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<organization>
<name>Shigeru Chiba, www.javassist.org</name>
</organization>
......@@ -137,6 +140,11 @@
<build>
<sourceDirectory>src/main/</sourceDirectory>
<testSourceDirectory>src/test/</testSourceDirectory>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......@@ -145,8 +153,8 @@
<configuration>
<source>1.6</source>
<target>1.6</target>
<testSource>1.8</testSource>
<testTarget>1.8</testTarget>
<testSource>1.9</testSource>
<testTarget>1.9</testTarget>
<testCompilerArgument>-parameters</testCompilerArgument>
</configuration>
</plugin>
......@@ -159,7 +167,10 @@
<include>javassist/JvstTest.java</include>
</includes>
<forkMode>once</forkMode>
<workingDirectory>runtest</workingDirectory>
<additionalClasspathElements>
<additionalClasspathElement>resources</additionalClasspathElement>
</additionalClasspathElements>
<workingDirectory>${project.build.directory}/runtest</workingDirectory>
</configuration>
</plugin>
<plugin>
......@@ -191,7 +202,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<version>3.0.0-M1</version>
<configuration>
<attach>true</attach>
</configuration>
......@@ -199,7 +210,7 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.5.3</version>
<version>3.3.0</version>
<executions>
<execution>
<id>bundle-manifest</id>
......@@ -269,9 +280,7 @@
<profile>
<id>default-tools</id>
<activation>
<os>
<family>!mac</family>
</os>
<jdk>[,1.8]</jdk>
</activation>
<dependencies>
<dependency>
......@@ -285,11 +294,9 @@
</dependencies>
</profile>
<profile>
<id>mac-tools</id>
<id>java9-tools</id>
<activation>
<os>
<family>mac</family>
</os>
<jdk>[1.9,]</jdk>
</activation>
<dependencies>
<dependency>
......@@ -298,7 +305,7 @@
<version>${java.version}</version>
<scope>system</scope>
<optional>true</optional>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
<systemPath>${java.home}/lib/jrt-fs.jar</systemPath>
</dependency>
</dependencies>
</profile>
......@@ -307,7 +314,13 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
......
Specification-Title: Javassist
Specification-Vendor: Shigeru Chiba, www.javassist.org
Specification-Version: 3.21.0-GA
Specification-Version: 3.23.1-GA
Main-Class: javassist.CtClass
......@@ -16,9 +16,10 @@
package javassist;
import java.io.*;
import java.net.URL;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
/**
* A <code>ByteArrayClassPath</code> contains bytes that is served as
......@@ -62,11 +63,7 @@ public class ByteArrayClassPath implements ClassPath {
this.classfile = classfile;
}
/**
* Closes this class path.
*/
public void close() {}
@Override
public String toString() {
return "byte[]:" + classname;
}
......@@ -74,16 +71,17 @@ public class ByteArrayClassPath implements ClassPath {
/**
* Opens the class file.
*/
@Override
public InputStream openClassfile(String classname) {
if(this.classname.equals(classname))
return new ByteArrayInputStream(classfile);
else
return null;
}
/**
* Obtains the URL.
*/
@Override
public URL find(String classname) {
if(this.classname.equals(classname)) {
String cname = classname.replace('.', '/') + ".class";
......
......@@ -22,13 +22,16 @@ import javassist.compiler.CompileError;
* Thrown when bytecode transformation has failed.
*/
public class CannotCompileException extends Exception {
/** default serialVersionUID */
private static final long serialVersionUID = 1L;
private Throwable myCause;
/**
* Gets the cause of this throwable.
* It is for JDK 1.3 compatibility.
*/
public Throwable getCause() {
@Override
public synchronized Throwable getCause() {
return (myCause == this ? null : myCause);
}
......@@ -36,6 +39,7 @@ public class CannotCompileException extends Exception {
* Initializes the cause of this throwable.
* It is for JDK 1.3 compatibility.
*/
@Override
public synchronized Throwable initCause(Throwable cause) {
myCause = cause;
return this;
......@@ -49,7 +53,6 @@ public class CannotCompileException extends Exception {
public String getReason() {
if (message != null)
return message;
else
return this.toString();
}
......
......@@ -38,12 +38,16 @@ import java.net.URL;
* <code>ClassClassPath</code> uses a class object representing
* the class including the code snippet above.
*
* <p>Class files in a named module are private to that module.
* This method cannot obtain class files in named modules.
* </p>
*
* @see ClassPool#insertClassPath(ClassPath)
* @see ClassPool#appendClassPath(ClassPath)
* @see LoaderClassPath
*/
public class ClassClassPath implements ClassPath {
private Class thisClass;
private Class<?> thisClass;
/** Creates a search path.
*
......@@ -51,7 +55,7 @@ public class ClassClassPath implements ClassPath {
* file. <code>getResourceAsStream()</code> is called on
* this object.
*/
public ClassClassPath(Class c) {
public ClassClassPath(Class<?> c) {
thisClass = c;
}
......@@ -70,9 +74,10 @@ public class ClassClassPath implements ClassPath {
/**
* Obtains a class file by <code>getResourceAsStream()</code>.
*/
public InputStream openClassfile(String classname) {
String jarname = "/" + classname.replace('.', '/') + ".class";
return thisClass.getResourceAsStream(jarname);
@Override
public InputStream openClassfile(String classname) throws NotFoundException {
String filename = '/' + classname.replace('.', '/') + ".class";
return thisClass.getResourceAsStream(filename);
}
/**
......@@ -80,17 +85,13 @@ public class ClassClassPath implements ClassPath {
*
* @return null if the class file could not be found.
*/
@Override
public URL find(String classname) {
String jarname = "/" + classname.replace('.', '/') + ".class";
return thisClass.getResource(jarname);
}
/**
* Does nothing.
*/
public void close() {
String filename = '/' + classname.replace('.', '/') + ".class";
return thisClass.getResource(filename);
}
@Override
public String toString() {
return thisClass.getName() + ".class";
}
......
......@@ -16,6 +16,8 @@
package javassist;
import java.util.HashMap;
import javassist.bytecode.Descriptor;
/**
......@@ -47,7 +49,9 @@ import javassist.bytecode.Descriptor;
* @see CtClass#replaceClassName(ClassMap)
* @see CtNewMethod#copy(CtMethod,String,CtClass,ClassMap)
*/
public class ClassMap extends java.util.HashMap {
public class ClassMap extends HashMap<String,String> {
/** default serialVersionUID */
private static final long serialVersionUID = 1L;
private ClassMap parent;
/**
......@@ -89,14 +93,16 @@ public class ClassMap extends java.util.HashMap {
* @param newname the substituted class name.
* @see #fix(String)
*/
public void put(String oldname, String newname) {
@Override
public String put(String oldname, String newname) {
if (oldname == newname)
return;
return oldname;
String oldname2 = toJvmName(oldname);
String s = (String)get(oldname2);
String s = get(oldname2);
if (s == null || !s.equals(oldname2))
super.put(oldname2, toJvmName(newname));
return super.put(oldname2, toJvmName(newname));
return s;
}
/**
......@@ -113,13 +119,13 @@ public class ClassMap extends java.util.HashMap {
return;
String oldname2 = toJvmName(oldname);
String s = (String)get(oldname2);
String s = get(oldname2);
if (s == null)
super.put(oldname2, toJvmName(newname));
}
protected final void put0(Object oldname, Object newname) {
super.put(oldname, newname);
protected final String put0(String oldname, String newname) {
return super.put(oldname, newname);
}
/**
......@@ -132,14 +138,13 @@ public class ClassMap extends java.util.HashMap {
* @see #toJvmName(String)
* @see #toJavaName(String)
*/
public Object get(Object jvmClassName) {
Object found = super.get(jvmClassName);
@Override
public String get(Object jvmClassName) {
String found = super.get(jvmClassName);
if (found == null && parent != null)
return parent.get(jvmClassName);
else
return found;
}
/**
* Prevents a mapping from the specified class name to another name.
*/
......
......@@ -58,11 +58,4 @@ public interface ClassPath {
* @return null if the specified class file could not be found.
*/
URL find(String classname);
/**
* This method is invoked when the <code>ClassPath</code> object is
* detached from the search path. It will be an empty method in most of
* classes.
*/
void close();
}
......@@ -21,19 +21,16 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.ProtectionDomain;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import javassist.bytecode.ClassFile;
import javassist.bytecode.Descriptor;
import javassist.util.proxy.DefinePackageHelper;
/**
* A container of <code>CtClass</code> objects.
......@@ -69,36 +66,8 @@ import javassist.bytecode.Descriptor;
* @see javassist.CtClass
* @see javassist.ClassPath
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public class ClassPool {
// used by toClass().
private static java.lang.reflect.Method defineClass1, defineClass2;
private static java.lang.reflect.Method definePackage;
static {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction(){
public Object run() throws Exception{
Class cl = Class.forName("java.lang.ClassLoader");
defineClass1 = cl.getDeclaredMethod("defineClass",
new Class[] { String.class, byte[].class,
int.class, int.class });
defineClass2 = cl.getDeclaredMethod("defineClass",
new Class[] { String.class, byte[].class,
int.class, int.class, ProtectionDomain.class });
definePackage = cl.getDeclaredMethod("definePackage",
new Class[] { String.class, String.class, String.class,
String.class, String.class, String.class,
String.class, java.net.URL.class });
return null;
}
});
}
catch (PrivilegedActionException pae) {
throw new RuntimeException("cannot initialize ClassPool", pae.getException());
}
}
/**
* Determines the search order.
......@@ -220,7 +189,8 @@ public class ClassPool {
* </pre>
*
* <p>If the default class pool cannot find any class files,
* try <code>ClassClassPath</code> and <code>LoaderClassPath</code>.
* try <code>ClassClassPath</code>, <code>ModuleClassPath</code>,
* or <code>LoaderClassPath</code>.
*
* @see ClassClassPath
* @see LoaderClassPath
......@@ -328,7 +298,7 @@ public class ClassPool {
* @see #importPackage(String)
* @since 3.1
*/
public Iterator getImportedPackages() {
public Iterator<String> getImportedPackages() {
return importedPackages.iterator();
}
......@@ -871,7 +841,7 @@ public class ClassPool {
*/
synchronized CtClass makeNestedClass(String classname) {
checkNotFrozen(classname);
CtClass clazz = new CtNewNestedClass(classname, this, false, null);
CtClass clazz = new CtNewClass(classname, this, false, null);
cacheCtClass(classname, clazz, true);
return clazz;
}
......@@ -1147,46 +1117,14 @@ public class ClassPool {
throws CannotCompileException
{
try {
byte[] b = ct.toBytecode();
java.lang.reflect.Method method;
Object[] args;
if (domain == null) {
method = defineClass1;
args = new Object[] { ct.getName(), b, new Integer(0),
new Integer(b.length)};
}
else {
method = defineClass2;
args = new Object[] { ct.getName(), b, new Integer(0),
new Integer(b.length), domain};
}
return (Class)toClass2(method, loader, args);
return javassist.util.proxy.DefineClassHelper.toClass(ct.getName(),
loader, domain, ct.toBytecode());
}
catch (RuntimeException e) {
throw e;
}
catch (java.lang.reflect.InvocationTargetException e) {
throw new CannotCompileException(e.getTargetException());
}
catch (Exception e) {
catch (IOException e) {
throw new CannotCompileException(e);
}
}
private static synchronized Object toClass2(Method method,
ClassLoader loader, Object[] args)
throws Exception
{
method.setAccessible(true);
try {
return method.invoke(loader, args);
}
finally {
method.setAccessible(false);
}
}
/**
* Defines a new package. If the package is already defined, this method
* performs nothing.
......@@ -1194,7 +1132,13 @@ public class ClassPool {
* <p>You do not necessarily need to
* call this method. If this method is called, then
* <code>getPackage()</code> on the <code>Class</code> object returned
* by <code>toClass()</code> will return a non-null object.
* by <code>toClass()</code> will return a non-null object.</p>
*
* <p>The jigsaw module introduced by Java 9 has broken this method.
* In Java 9 or later, the VM argument
* <code>--add-opens java.base/java.lang=ALL-UNNAMED</code>
* has to be given to the JVM so that this method can run.
* </p>
*
* @param loader the class loader passed to <code>toClass()</code> or
* the default one obtained by <code>getClassLoader()</code>.
......@@ -1203,31 +1147,12 @@ public class ClassPool {
* @see #toClass(CtClass)
* @see CtClass#toClass()
* @since 3.16
* @deprecated
*/
public void makePackage(ClassLoader loader, String name)
throws CannotCompileException
{
Object[] args = new Object[] {
name, null, null, null, null, null, null, null };
Throwable t;
try {
toClass2(definePackage, loader, args);
return;
}
catch (java.lang.reflect.InvocationTargetException e) {
t = e.getTargetException();
if (t == null)
t = e;
else if (t instanceof IllegalArgumentException) {
// if the package is already defined, an IllegalArgumentException
// is thrown.
return;
}
}
catch (Exception e) {
t = e;
DefinePackageHelper.definePackage(name, loader);
}
throw new CannotCompileException(t);
}
}
......@@ -16,11 +16,20 @@
package javassist;
import java.io.*;
import java.util.jar.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Hashtable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
final class ClassPathList {
ClassPathList next;
......@@ -39,6 +48,7 @@ final class DirClassPath implements ClassPath {
directory = dirName;
}
@Override
public InputStream openClassfile(String classname) {
try {
char sep = File.separatorChar;
......@@ -51,6 +61,7 @@ final class DirClassPath implements ClassPath {
return null;
}
@Override
public URL find(String classname) {
char sep = File.separatorChar;
String filename = directory + sep
......@@ -66,8 +77,7 @@ final class DirClassPath implements ClassPath {
return null;
}
public void close() {}
@Override
public String toString() {
return directory;
}
......@@ -78,6 +88,7 @@ final class JarDirClassPath implements ClassPath {
JarDirClassPath(String dirName) throws NotFoundException {
File[] files = new File(dirName).listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
name = name.toLowerCase();
return name.endsWith(".jar") || name.endsWith(".zip");
......@@ -91,6 +102,7 @@ final class JarDirClassPath implements ClassPath {
}
}
@Override
public InputStream openClassfile(String classname) throws NotFoundException {
if (jars != null)
for (int i = 0; i < jars.length; i++) {
......@@ -102,6 +114,7 @@ final class JarDirClassPath implements ClassPath {
return null; // not found
}
@Override
public URL find(String classname) {
if (jars != null)
for (int i = 0; i < jars.length; i++) {
......@@ -112,67 +125,63 @@ final class JarDirClassPath implements ClassPath {
return null; // not found
}
public void close() {
if (jars != null)
for (int i = 0; i < jars.length; i++)
jars[i].close();
}
}
final class JarClassPath implements ClassPath {
JarFile jarfile;
List<String> jarfileEntries;
String jarfileURL;
JarClassPath(String pathname) throws NotFoundException {
JarFile jarfile = null;
try {
jarfile = new JarFile(pathname);
jarfileEntries = new ArrayList<String>();
for (JarEntry je:Collections.list(jarfile.entries()))
if (je.getName().endsWith(".class"))
jarfileEntries.add(je.getName());
jarfileURL = new File(pathname).getCanonicalFile()
.toURI().toURL().toString();
return;
} catch (IOException e) {}
finally {
if (null != jarfile)
try {
jarfile.close();
} catch (IOException e) {}
}
catch (IOException e) {}
throw new NotFoundException(pathname);
}
@Override
public InputStream openClassfile(String classname)
throws NotFoundException
{
URL jarURL = find(classname);
if (null != jarURL)
try {
String jarname = classname.replace('.', '/') + ".class";
JarEntry je = jarfile.getJarEntry(jarname);
if (je != null)
return jarfile.getInputStream(je);
else
return null; // not found
return jarURL.openConnection().getInputStream();
}
catch (IOException e) {}
catch (IOException e) {
throw new NotFoundException("broken jar file?: "
+ jarfile.getName());
+ classname);
}
return null;
}
@Override
public URL find(String classname) {
String jarname = classname.replace('.', '/') + ".class";
JarEntry je = jarfile.getJarEntry(jarname);
if (je != null)
if (jarfileEntries.contains(jarname))
try {
return new URL("jar:" + jarfileURL + "!/" + jarname);
return new URL(String.format("jar:%s!/%s", jarfileURL, jarname));
}
catch (MalformedURLException e) {}
return null; // not found
}
public void close() {
try {
jarfile.close();
jarfile = null;
}
catch (IOException e) {}
}
@Override
public String toString() {
return jarfile == null ? "<null>" : jarfile.toString();
return jarfileURL == null ? "<null>" : jarfileURL.toString();
}
}
......@@ -183,6 +192,7 @@ final class ClassPoolTail {
pathList = null;
}
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append("[class path: ");
......@@ -229,12 +239,13 @@ final class ClassPoolTail {
else
list = list.next;
}
cp.close();
}
public ClassPath appendSystemPath() {
if (javassist.bytecode.ClassFile.MAJOR_VERSION < javassist.bytecode.ClassFile.JAVA_9)
return appendClassPath(new ClassClassPath());
ClassLoader cl = Thread.currentThread().getContextClassLoader();
return appendClassPath(new LoaderClassPath(cl));
}
public ClassPath insertClassPath(String pathname)
......@@ -335,7 +346,6 @@ final class ClassPoolTail {
if (error != null)
throw error;
else
return null; // not found
}
......
......@@ -16,8 +16,21 @@
package javassist;
import javassist.bytecode.*;
import javassist.convert.*;
import javassist.bytecode.BadBytecode;
import javassist.bytecode.CodeAttribute;
import javassist.bytecode.CodeIterator;
import javassist.bytecode.ConstPool;
import javassist.bytecode.MethodInfo;
import javassist.convert.TransformAccessArrayField;
import javassist.convert.TransformAfter;
import javassist.convert.TransformBefore;
import javassist.convert.TransformCall;
import javassist.convert.TransformFieldAccess;
import javassist.convert.TransformNew;
import javassist.convert.TransformNewClass;
import javassist.convert.TransformReadField;
import javassist.convert.TransformWriteField;
import javassist.convert.Transformer;
/**
* Simple translator of method bodies
......@@ -666,6 +679,7 @@ public class CodeConverter {
* Returns "arrayReadByteOrBoolean" as the name of the static method with the signature
* (Ljava/lang/Object;I)B to replace reading from a byte[].
*/
@Override
public String byteOrBooleanRead()
{
return "arrayReadByteOrBoolean";
......@@ -675,6 +689,7 @@ public class CodeConverter {
* Returns "arrayWriteByteOrBoolean" as the name of the static method with the signature
* (Ljava/lang/Object;IB)V to replace writing to a byte[].
*/
@Override
public String byteOrBooleanWrite()
{
return "arrayWriteByteOrBoolean";
......@@ -684,6 +699,7 @@ public class CodeConverter {
* Returns "arrayReadChar" as the name of the static method with the signature
* (Ljava/lang/Object;I)C to replace reading from a char[].
*/
@Override
public String charRead()
{
return "arrayReadChar";
......@@ -693,6 +709,7 @@ public class CodeConverter {
* Returns "arrayWriteChar" as the name of the static method with the signature
* (Ljava/lang/Object;IC)V to replace writing to a byte[].
*/
@Override
public String charWrite()
{
return "arrayWriteChar";
......@@ -702,6 +719,7 @@ public class CodeConverter {
* Returns "arrayReadDouble" as the name of the static method with the signature
* (Ljava/lang/Object;I)D to replace reading from a double[].
*/
@Override
public String doubleRead()
{
return "arrayReadDouble";
......@@ -711,6 +729,7 @@ public class CodeConverter {
* Returns "arrayWriteDouble" as the name of the static method with the signature
* (Ljava/lang/Object;ID)V to replace writing to a double[].
*/
@Override
public String doubleWrite()
{
return "arrayWriteDouble";
......@@ -720,6 +739,7 @@ public class CodeConverter {
* Returns "arrayReadFloat" as the name of the static method with the signature
* (Ljava/lang/Object;I)F to replace reading from a float[].
*/
@Override
public String floatRead()
{
return "arrayReadFloat";
......@@ -729,6 +749,7 @@ public class CodeConverter {
* Returns "arrayWriteFloat" as the name of the static method with the signature
* (Ljava/lang/Object;IF)V to replace writing to a float[].
*/
@Override
public String floatWrite()
{
return "arrayWriteFloat";
......@@ -738,6 +759,7 @@ public class CodeConverter {
* Returns "arrayReadInt" as the name of the static method with the signature
* (Ljava/lang/Object;I)I to replace reading from a int[].
*/
@Override
public String intRead()
{
return "arrayReadInt";
......@@ -747,6 +769,7 @@ public class CodeConverter {
* Returns "arrayWriteInt" as the name of the static method with the signature
* (Ljava/lang/Object;II)V to replace writing to a int[].
*/
@Override
public String intWrite()
{
return "arrayWriteInt";
......@@ -756,6 +779,7 @@ public class CodeConverter {
* Returns "arrayReadLong" as the name of the static method with the signature
* (Ljava/lang/Object;I)J to replace reading from a long[].
*/
@Override
public String longRead()
{
return "arrayReadLong";
......@@ -765,6 +789,7 @@ public class CodeConverter {
* Returns "arrayWriteLong" as the name of the static method with the signature
* (Ljava/lang/Object;IJ)V to replace writing to a long[].
*/
@Override
public String longWrite()
{
return "arrayWriteLong";
......@@ -774,6 +799,7 @@ public class CodeConverter {
* Returns "arrayReadObject" as the name of the static method with the signature
* (Ljava/lang/Object;I)Ljava/lang/Object; to replace reading from a Object[] (or any subclass of object).
*/
@Override
public String objectRead()
{
return "arrayReadObject";
......@@ -783,6 +809,7 @@ public class CodeConverter {
* Returns "arrayWriteObject" as the name of the static method with the signature
* (Ljava/lang/Object;ILjava/lang/Object;)V to replace writing to a Object[] (or any subclass of object).
*/
@Override
public String objectWrite()
{
return "arrayWriteObject";
......@@ -792,6 +819,7 @@ public class CodeConverter {
* Returns "arrayReadShort" as the name of the static method with the signature
* (Ljava/lang/Object;I)S to replace reading from a short[].
*/
@Override
public String shortRead()
{
return "arrayReadShort";
......@@ -801,6 +829,7 @@ public class CodeConverter {
* Returns "arrayWriteShort" as the name of the static method with the signature
* (Ljava/lang/Object;IS)V to replace writing to a short[].
*/
@Override
public String shortWrite()
{
return "arrayWriteShort";
......
......@@ -19,26 +19,34 @@ package javassist;
/**
* Array types.
*/
final class CtArray extends CtClass {
final class CtArray extends CtClass
{
protected ClassPool pool;
// the name of array type ends with "[]".
CtArray(String name, ClassPool cp) {
CtArray(String name, ClassPool cp)
{
super(name);
pool = cp;
}
public ClassPool getClassPool() {
@Override
public ClassPool getClassPool()
{
return pool;
}
public boolean isArray() {
@Override
public boolean isArray()
{
return true;
}
private CtClass[] interfaces = null;
public int getModifiers() {
@Override
public int getModifiers()
{
int mod = Modifier.FINAL;
try {
mod |= getComponentType().getModifiers()
......@@ -48,9 +56,11 @@ final class CtArray extends CtClass {
return mod;
}
public CtClass[] getInterfaces() throws NotFoundException {
@Override
public CtClass[] getInterfaces() throws NotFoundException
{
if (interfaces == null) {
Class[] intfs = Object[].class.getInterfaces();
Class<?>[] intfs = Object[].class.getInterfaces();
// java.lang.Cloneable and java.io.Serializable.
// If the JVM is CLDC, intfs is empty.
interfaces = new CtClass[intfs.length];
......@@ -61,7 +71,9 @@ final class CtArray extends CtClass {
return interfaces;
}
public boolean subtypeOf(CtClass clazz) throws NotFoundException {
@Override
public boolean subtypeOf(CtClass clazz) throws NotFoundException
{
if (super.subtypeOf(clazz))
return true;
......@@ -78,16 +90,22 @@ final class CtArray extends CtClass {
&& getComponentType().subtypeOf(clazz.getComponentType());
}
public CtClass getComponentType() throws NotFoundException {
@Override
public CtClass getComponentType() throws NotFoundException
{
String name = getName();
return pool.get(name.substring(0, name.length() - 2));
}
public CtClass getSuperclass() throws NotFoundException {
@Override
public CtClass getSuperclass() throws NotFoundException
{
return pool.get(javaLangObject);
}
public CtMethod[] getMethods() {
@Override
public CtMethod[] getMethods()
{
try {
return getSuperclass().getMethods();
}
......@@ -96,13 +114,16 @@ final class CtArray extends CtClass {
}
}
@Override
public CtMethod getMethod(String name, String desc)
throws NotFoundException
{
return getSuperclass().getMethod(name, desc);
}
public CtConstructor[] getConstructors() {
@Override
public CtConstructor[] getConstructors()
{
try {
return getSuperclass().getConstructors();
}
......
......@@ -16,9 +16,27 @@
package javassist;
import javassist.bytecode.*;
import javassist.compiler.Javac;
import javassist.bytecode.AccessFlag;
import javassist.bytecode.AnnotationsAttribute;
import javassist.bytecode.AttributeInfo;
import javassist.bytecode.BadBytecode;
import javassist.bytecode.Bytecode;
import javassist.bytecode.CodeAttribute;
import javassist.bytecode.CodeIterator;
import javassist.bytecode.ConstPool;
import javassist.bytecode.Descriptor;
import javassist.bytecode.ExceptionsAttribute;
import javassist.bytecode.LineNumberAttribute;
import javassist.bytecode.LocalVariableAttribute;
import javassist.bytecode.LocalVariableTypeAttribute;
import javassist.bytecode.MethodInfo;
import javassist.bytecode.Opcode;
import javassist.bytecode.ParameterAnnotationsAttribute;
import javassist.bytecode.SignatureAttribute;
import javassist.bytecode.StackMap;
import javassist.bytecode.StackMapTable;
import javassist.compiler.CompileError;
import javassist.compiler.Javac;
import javassist.expr.ExprEditor;
/**
......@@ -81,6 +99,7 @@ public abstract class CtBehavior extends CtMember {
}
}
@Override
protected void extendToString(StringBuffer buffer) {
buffer.append(' ');
buffer.append(getName());
......@@ -140,6 +159,7 @@ public abstract class CtBehavior extends CtMember {
* <code>javassist.Modifier</code>.
* @see Modifier
*/
@Override
public int getModifiers() {
return AccessFlag.toModifier(methodInfo.getAccessFlags());
}
......@@ -153,6 +173,7 @@ public abstract class CtBehavior extends CtMember {
*
* @see Modifier
*/
@Override
public void setModifiers(int mod) {
declaringClass.checkModify();
methodInfo.setAccessFlags(AccessFlag.of(mod));
......@@ -166,6 +187,7 @@ public abstract class CtBehavior extends CtMember {
* otherwise <code>false</code>.
* @since 3.21
*/
@Override
public boolean hasAnnotation(String typeName) {
MethodInfo mi = getMethodInfo2();
AnnotationsAttribute ainfo = (AnnotationsAttribute)
......@@ -188,7 +210,8 @@ public abstract class CtBehavior extends CtMember {
* @return the annotation if found, otherwise <code>null</code>.
* @since 3.11
*/
public Object getAnnotation(Class clz) throws ClassNotFoundException {
@Override
public Object getAnnotation(Class<?> clz) throws ClassNotFoundException {
MethodInfo mi = getMethodInfo2();
AnnotationsAttribute ainfo = (AnnotationsAttribute)
mi.getAttribute(AnnotationsAttribute.invisibleTag);
......@@ -206,6 +229,7 @@ public abstract class CtBehavior extends CtMember {
* @see #getAvailableAnnotations()
* @since 3.1
*/
@Override
public Object[] getAnnotations() throws ClassNotFoundException {
return getAnnotations(false);
}
......@@ -219,6 +243,7 @@ public abstract class CtBehavior extends CtMember {
* @see #getAnnotations()
* @since 3.3
*/
@Override
public Object[] getAvailableAnnotations(){
try{
return getAnnotations(true);
......@@ -324,6 +349,7 @@ public abstract class CtBehavior extends CtMember {
* @see javassist.bytecode.Descriptor
* @see #getGenericSignature()
*/
@Override
public String getSignature() {
return methodInfo.getDescriptor();
}
......@@ -335,6 +361,7 @@ public abstract class CtBehavior extends CtMember {
* @see SignatureAttribute#toMethodSignature(String)
* @since 3.17
*/
@Override
public String getGenericSignature() {
SignatureAttribute sa
= (SignatureAttribute)methodInfo.getAttribute(SignatureAttribute.tag);
......@@ -351,6 +378,7 @@ public abstract class CtBehavior extends CtMember {
* @see javassist.bytecode.SignatureAttribute.MethodSignature#encode()
* @since 3.17
*/
@Override
public void setGenericSignature(String sig) {
declaringClass.checkModify();
methodInfo.addAttribute(new SignatureAttribute(methodInfo.getConstPool(), sig));
......@@ -489,11 +517,12 @@ public abstract class CtBehavior extends CtMember {
*
* @param name attribute name
*/
public byte[] getAttribute(String name) {
@Override
public byte[] getAttribute(String name)
{
AttributeInfo ai = methodInfo.getAttribute(name);
if (ai == null)
return null;
else
return ai.get();
}
......@@ -507,7 +536,9 @@ public abstract class CtBehavior extends CtMember {
* @param name attribute name
* @param data attribute value
*/
public void setAttribute(String name, byte[] data) {
@Override
public void setAttribute(String name, byte[] data)
{
declaringClass.checkModify();
methodInfo.addAttribute(new AttributeInfo(methodInfo.getConstPool(),
name, data));
......@@ -530,7 +561,8 @@ public abstract class CtBehavior extends CtMember {
*
* @see javassist.runtime.Cflow
*/
public void useCflow(String name) throws CannotCompileException {
public void useCflow(String name) throws CannotCompileException
{
CtClass cc = declaringClass;
cc.checkModify();
ClassPool pool = cc.getClassPool();
......
......@@ -69,7 +69,7 @@ public abstract class CtClass {
/**
* The version number of this release.
*/
public static final String version = "3.21.0-GA";
public static final String version = "3.23.1-GA";
/**
* Prints the version number and the copyright notice.
......@@ -80,7 +80,7 @@ public abstract class CtClass {
*/
public static void main(String[] args) {
System.out.println("Javassist version " + CtClass.version);
System.out.println("Copyright (C) 1999-2016 Shigeru Chiba."
System.out.println("Copyright (C) 1999-2018 Shigeru Chiba."
+ " All Rights Reserved.");
}
......@@ -198,6 +198,7 @@ public abstract class CtClass {
/**
* Converts the object to a string.
*/
@Override
public String toString() {
StringBuffer buf = new StringBuffer(getClass().getName());
buf.append("@");
......@@ -361,7 +362,6 @@ public abstract class CtClass {
int index = qname.lastIndexOf('.');
if (index < 0)
return qname;
else
return qname.substring(index + 1);
}
......@@ -373,7 +373,6 @@ public abstract class CtClass {
int index = qname.lastIndexOf('.');
if (index < 0)
return null;
else
return qname.substring(0, index);
}
......@@ -517,26 +516,29 @@ public abstract class CtClass {
*
* @return a <code>Collection&lt;String&gt;</code> object.
*/
public synchronized Collection getRefClasses() {
public synchronized Collection<String> getRefClasses() {
ClassFile cf = getClassFile2();
if (cf != null) {
ClassMap cm = new ClassMap() {
public void put(String oldname, String newname) {
put0(oldname, newname);
}
public Object get(Object jvmClassName) {
/** default serialVersionUID */
private static final long serialVersionUID = 1L;
@Override
public String put(String oldname, String newname) {
return put0(oldname, newname);
}
@Override
public String get(Object jvmClassName) {
String n = toJavaName((String)jvmClassName);
put0(n, n);
return null;
}
@Override
public void fix(String name) {}
};
cf.getRefClasses(cm);
return cm.values();
}
else
return null;
}
......@@ -588,7 +590,7 @@ public abstract class CtClass {
* @return <code>true</code> if the annotation is found, otherwise <code>false</code>.
* @since 3.11
*/
public boolean hasAnnotation(Class annotationType) {
public boolean hasAnnotation(Class<?> annotationType) {
return hasAnnotation(annotationType.getName());
}
......@@ -614,7 +616,7 @@ public abstract class CtClass {
* @return the annotation if found, otherwise <code>null</code>.
* @since 3.11
*/
public Object getAnnotation(Class clz) throws ClassNotFoundException {
public Object getAnnotation(Class<?> clz) throws ClassNotFoundException {
return null;
}
......@@ -782,6 +784,7 @@ public abstract class CtClass {
* Use {@link #getEnclosingBehavior()}.
* @see #getEnclosingBehavior()
*/
@Deprecated
public final CtMethod getEnclosingMethod() throws NotFoundException {
CtBehavior b = getEnclosingBehavior();
if (b == null)
......@@ -1271,7 +1274,7 @@ public abstract class CtClass {
* @see #toClass(java.lang.ClassLoader,ProtectionDomain)
* @see ClassPool#toClass(CtClass)
*/
public Class toClass() throws CannotCompileException {
public Class<?> toClass() throws CannotCompileException {
return getClassPool().toClass(this);
}
......@@ -1306,7 +1309,7 @@ public abstract class CtClass {
* @see ClassPool#toClass(CtClass,java.lang.ClassLoader)
* @since 3.3
*/
public Class toClass(ClassLoader loader, ProtectionDomain domain)
public Class<?> toClass(ClassLoader loader, ProtectionDomain domain)
throws CannotCompileException
{
ClassPool cp = getClassPool();
......@@ -1325,7 +1328,8 @@ public abstract class CtClass {
*
* @deprecated Replaced by {@link #toClass(ClassLoader,ProtectionDomain)}
*/
public final Class toClass(ClassLoader loader)
@Deprecated
public final Class<?> toClass(ClassLoader loader)
throws CannotCompileException
{
return getClassPool().toClass(this, loader);
......@@ -1544,27 +1548,32 @@ public abstract class CtClass {
file = new FileOutputStream(filename);
}
@Override
public void write(int b) throws IOException {
init();
file.write(b);
}
@Override
public void write(byte[] b) throws IOException {
init();
file.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
init();
file.write(b, off, len);
}
@Override
public void flush() throws IOException {
init();
file.flush();
}
@Override
public void close() throws IOException {
init();
file.close();
......
This diff is collapsed.
......@@ -16,9 +16,17 @@
package javassist;
import javassist.bytecode.*;
import javassist.compiler.Javac;
import javassist.bytecode.BadBytecode;
import javassist.bytecode.Bytecode;
import javassist.bytecode.ClassFile;
import javassist.bytecode.CodeAttribute;
import javassist.bytecode.CodeIterator;
import javassist.bytecode.ConstPool;
import javassist.bytecode.Descriptor;
import javassist.bytecode.MethodInfo;
import javassist.bytecode.Opcode;
import javassist.compiler.CompileError;
import javassist.compiler.Javac;
/**
* An instance of CtConstructor represents a constructor.
......@@ -122,6 +130,7 @@ public final class CtConstructor extends CtBehavior {
*
* @since 3.5
*/
@Override
public String getLongName() {
return getDeclaringClass().getName()
+ (isConstructor() ? Descriptor.toString(getSignature())
......@@ -134,10 +143,10 @@ public final class CtConstructor extends CtBehavior {
* constructor. If this object represents a class initializer,
* then this method returns <code>"&lt;clinit&gt;"</code>.
*/
@Override
public String getName() {
if (methodInfo.isStaticInitializer())
return MethodInfo.nameClinit;
else
return declaringClass.getSimpleName();
}
......@@ -148,6 +157,7 @@ public final class CtConstructor extends CtBehavior {
* calling <code>super()</code> (the no-argument constructor of
* the super class).
*/
@Override
public boolean isEmpty() {
CodeAttribute ca = getMethodInfo2().getCodeAttribute();
if (ca == null)
......@@ -207,6 +217,7 @@ public final class CtConstructor extends CtBehavior {
* constructor body does nothing except calling
* <code>super()</code>.
*/
@Override
public void setBody(String src) throws CannotCompileException {
if (src == null)
if (isClassInitializer())
......@@ -280,6 +291,7 @@ public final class CtConstructor extends CtBehavior {
/* This method is called by addCatch() in CtBehavior.
* super() and this() must not be in a try statement.
*/
@Override
int getStartPosOfBody(CodeAttribute ca) throws CannotCompileException {
CodeIterator ci = ca.iterator();
try {
......
......@@ -16,13 +16,23 @@
package javassist;
import javassist.bytecode.*;
import java.util.List;
import javassist.bytecode.AccessFlag;
import javassist.bytecode.AnnotationsAttribute;
import javassist.bytecode.AttributeInfo;
import javassist.bytecode.Bytecode;
import javassist.bytecode.ClassFile;
import javassist.bytecode.ConstPool;
import javassist.bytecode.Descriptor;
import javassist.bytecode.FieldInfo;
import javassist.bytecode.SignatureAttribute;
import javassist.compiler.CompileError;
import javassist.compiler.Javac;
import javassist.compiler.SymbolTable;
import javassist.compiler.CompileError;
import javassist.compiler.ast.ASTree;
import javassist.compiler.ast.IntConst;
import javassist.compiler.ast.DoubleConst;
import javassist.compiler.ast.IntConst;
import javassist.compiler.ast.StringL;
/**
......@@ -83,16 +93,13 @@ public class CtField extends CtMember {
{
this(src.fieldInfo.getDescriptor(), src.fieldInfo.getName(),
declaring);
java.util.ListIterator iterator
= src.fieldInfo.getAttributes().listIterator();
FieldInfo fi = fieldInfo;
fi.setAccessFlags(src.fieldInfo.getAccessFlags());
ConstPool cp = fi.getConstPool();
while (iterator.hasNext()) {
AttributeInfo ainfo = (AttributeInfo)iterator.next();
List<AttributeInfo> attributes = src.fieldInfo.getAttributes();
for (AttributeInfo ainfo : attributes)
fi.addAttribute(ainfo.copy(cp, null));
}
}
private CtField(String typeDesc, String name, CtClass clazz)
throws CannotCompileException
......@@ -114,11 +121,13 @@ public class CtField extends CtMember {
/**
* Returns a String representation of the object.
*/
@Override
public String toString() {
return getDeclaringClass().getName() + "." + getName()
+ ":" + fieldInfo.getDescriptor();
}
@Override
protected void extendToString(StringBuffer buffer) {
buffer.append(' ');
buffer.append(getName());
......@@ -126,17 +135,14 @@ public class CtField extends CtMember {
buffer.append(fieldInfo.getDescriptor());
}
/* Javac.CtFieldWithInit overrides.
*/
/* Javac.CtFieldWithInit overrides. */
protected ASTree getInitAST() { return null; }
/* Called by CtClassType.addField().
*/
/* Called by CtClassType.addField(). */
Initializer getInit() {
ASTree tree = getInitAST();
if (tree == null)
return null;
else
return Initializer.byExpr(tree);
}
......@@ -202,6 +208,7 @@ public class CtField extends CtMember {
/**
* Returns the class declaring the field.
*/
@Override
public CtClass getDeclaringClass() {
// this is redundant but for javadoc.
return super.getDeclaringClass();
......@@ -210,6 +217,7 @@ public class CtField extends CtMember {
/**
* Returns the name of the field.
*/
@Override
public String getName() {
return fieldInfo.getName();
}
......@@ -227,6 +235,7 @@ public class CtField extends CtMember {
*
* @see Modifier
*/
@Override
public int getModifiers() {
return AccessFlag.toModifier(fieldInfo.getAccessFlags());
}
......@@ -236,6 +245,7 @@ public class CtField extends CtMember {
*
* @see Modifier
*/
@Override
public void setModifiers(int mod) {
declaringClass.checkModify();
fieldInfo.setAccessFlags(AccessFlag.of(mod));
......@@ -248,6 +258,7 @@ public class CtField extends CtMember {
* @return <code>true</code> if the annotation is found, otherwise <code>false</code>.
* @since 3.21
*/
@Override
public boolean hasAnnotation(String typeName) {
FieldInfo fi = getFieldInfo2();
AnnotationsAttribute ainfo = (AnnotationsAttribute)
......@@ -269,7 +280,8 @@ public class CtField extends CtMember {
* @return the annotation if found, otherwise <code>null</code>.
* @since 3.11
*/
public Object getAnnotation(Class clz) throws ClassNotFoundException {
@Override
public Object getAnnotation(Class<?> clz) throws ClassNotFoundException {
FieldInfo fi = getFieldInfo2();
AnnotationsAttribute ainfo = (AnnotationsAttribute)
fi.getAttribute(AnnotationsAttribute.invisibleTag);
......@@ -286,6 +298,7 @@ public class CtField extends CtMember {
* @see #getAvailableAnnotations()
* @since 3.1
*/
@Override
public Object[] getAnnotations() throws ClassNotFoundException {
return getAnnotations(false);
}
......@@ -299,6 +312,7 @@ public class CtField extends CtMember {
* @see #getAnnotations()
* @since 3.3
*/
@Override
public Object[] getAvailableAnnotations(){
try {
return getAnnotations(true);
......@@ -332,6 +346,7 @@ public class CtField extends CtMember {
* @see javassist.bytecode.Descriptor
* @see #getGenericSignature()
*/
@Override
public String getSignature() {
return fieldInfo.getDescriptor();
}
......@@ -343,6 +358,7 @@ public class CtField extends CtMember {
* @see SignatureAttribute#toFieldSignature(String)
* @since 3.17
*/
@Override
public String getGenericSignature() {
SignatureAttribute sa
= (SignatureAttribute)fieldInfo.getAttribute(SignatureAttribute.tag);
......@@ -359,6 +375,7 @@ public class CtField extends CtMember {
* @see javassist.bytecode.SignatureAttribute.ObjectType#encode()
* @since 3.17
*/
@Override
public void setGenericSignature(String sig) {
declaringClass.checkModify();
fieldInfo.addAttribute(new SignatureAttribute(fieldInfo.getConstPool(), sig));
......@@ -416,18 +433,17 @@ public class CtField extends CtMember {
ConstPool cp = fieldInfo.getConstPool();
switch (cp.getTag(index)) {
case ConstPool.CONST_Long :
return new Long(cp.getLongInfo(index));
return Long.valueOf(cp.getLongInfo(index));
case ConstPool.CONST_Float :
return new Float(cp.getFloatInfo(index));
return Float.valueOf(cp.getFloatInfo(index));
case ConstPool.CONST_Double :
return new Double(cp.getDoubleInfo(index));
return Double.valueOf(cp.getDoubleInfo(index));
case ConstPool.CONST_Integer :
int value = cp.getIntegerInfo(index);
// "Z" means boolean type.
if ("Z".equals(fieldInfo.getDescriptor()))
return new Boolean(value != 0);
else
return new Integer(value);
return Boolean.valueOf(value != 0);
return Integer.valueOf(value);
case ConstPool.CONST_String :
return cp.getStringInfo(index);
default :
......@@ -447,11 +463,11 @@ public class CtField extends CtMember {
*
* @param name attribute name
*/
@Override
public byte[] getAttribute(String name) {
AttributeInfo ai = fieldInfo.getAttribute(name);
if (ai == null)
return null;
else
return ai.get();
}
......@@ -465,6 +481,7 @@ public class CtField extends CtMember {
* @param name attribute name
* @param data attribute value
*/
@Override
public void setAttribute(String name, byte[] data) {
declaringClass.checkModify();
fieldInfo.addAttribute(new AttributeInfo(fieldInfo.getConstPool(),
......@@ -854,6 +871,7 @@ public class CtField extends CtMember {
static abstract class CodeInitializer0 extends Initializer {
abstract void compileExpr(Javac drv) throws CompileError;
@Override
int compile(CtClass type, String name, Bytecode code,
CtClass[] parameters, Javac drv)
throws CannotCompileException
......@@ -869,6 +887,7 @@ public class CtField extends CtMember {
}
}
@Override
int compileIfStatic(CtClass type, String name, Bytecode code,
Javac drv) throws CannotCompileException
{
......@@ -887,9 +906,9 @@ public class CtField extends CtMember {
if (tree instanceof IntConst) {
long value = ((IntConst)tree).get();
if (type == CtClass.doubleType)
return cp.addDoubleInfo((double)value);
return cp.addDoubleInfo(value);
else if (type == CtClass.floatType)
return cp.addFloatInfo((float)value);
return cp.addFloatInfo(value);
else if (type == CtClass.longType)
return cp.addLongInfo(value);
else if (type != CtClass.voidType)
......@@ -916,10 +935,12 @@ public class CtField extends CtMember {
CodeInitializer(String expr) { expression = expr; }
@Override
void compileExpr(Javac drv) throws CompileError {
drv.compileExpr(expression);
}
@Override
int getConstantValue(ConstPool cp, CtClass type) {
try {
ASTree t = Javac.parseExpr(expression, new SymbolTable());
......@@ -936,10 +957,12 @@ public class CtField extends CtMember {
PtreeInitializer(ASTree expr) { expression = expr; }
@Override
void compileExpr(Javac drv) throws CompileError {
drv.compileExpr(expression);
}
@Override
int getConstantValue(ConstPool cp, CtClass type) {
return getConstantValue2(cp, type, expression);
}
......@@ -954,6 +977,7 @@ public class CtField extends CtMember {
ParamInitializer() {}
@Override
int compile(CtClass type, String name, Bytecode code,
CtClass[] parameters, Javac drv)
throws CannotCompileException
......@@ -965,7 +989,6 @@ public class CtField extends CtMember {
code.addPutfield(Bytecode.THIS, name, Descriptor.of(type));
return s; // stack size
}
else
return 0; // do not initialize
}
......@@ -998,6 +1021,7 @@ public class CtField extends CtMember {
return k;
}
@Override
int compileIfStatic(CtClass type, String name, Bytecode code,
Javac drv) throws CannotCompileException
{
......@@ -1019,6 +1043,7 @@ public class CtField extends CtMember {
* Produces codes in which a new object is created and assigned to
* the field as the initial value.
*/
@Override
int compile(CtClass type, String name, Bytecode code,
CtClass[] parameters, Javac drv)
throws CannotCompileException
......@@ -1053,16 +1078,17 @@ public class CtField extends CtMember {
return "(Ljava/lang/Object;[Ljava/lang/Object;)V";
else
return "(Ljava/lang/Object;)V";
else
if (withConstructorParams)
return desc3;
else
return "(Ljava/lang/Object;[Ljava/lang/String;)V";
}
/**
* Produces codes for a static field.
*/
@Override
int compileIfStatic(CtClass type, String name, Bytecode code,
Javac drv) throws CannotCompileException
{
......@@ -1115,6 +1141,7 @@ public class CtField extends CtMember {
* Produces codes in which a new object is created and assigned to
* the field as the initial value.
*/
@Override
int compile(CtClass type, String name, Bytecode code,
CtClass[] parameters, Javac drv)
throws CannotCompileException
......@@ -1149,16 +1176,17 @@ public class CtField extends CtMember {
return "(Ljava/lang/Object;[Ljava/lang/Object;)";
else
return "(Ljava/lang/Object;)";
else
if (withConstructorParams)
return desc3;
else
return "(Ljava/lang/Object;[Ljava/lang/String;)";
}
/**
* Produces codes for a static field.
*/
@Override
int compileIfStatic(CtClass type, String name, Bytecode code,
Javac drv) throws CannotCompileException
{
......@@ -1184,12 +1212,14 @@ public class CtField extends CtMember {
IntInitializer(int v) { value = v; }
@Override
void check(String desc) throws CannotCompileException {
char c = desc.charAt(0);
if (c != 'I' && c != 'S' && c != 'B' && c != 'C' && c != 'Z')
throw new CannotCompileException("type mismatch");
}
@Override
int compile(CtClass type, String name, Bytecode code,
CtClass[] parameters, Javac drv)
throws CannotCompileException
......@@ -1200,6 +1230,7 @@ public class CtField extends CtMember {
return 2; // stack size
}
@Override
int compileIfStatic(CtClass type, String name, Bytecode code,
Javac drv) throws CannotCompileException
{
......@@ -1208,6 +1239,7 @@ public class CtField extends CtMember {
return 1; // stack size
}
@Override
int getConstantValue(ConstPool cp, CtClass type) {
return cp.addIntegerInfo(value);
}
......@@ -1218,11 +1250,13 @@ public class CtField extends CtMember {
LongInitializer(long v) { value = v; }
@Override
void check(String desc) throws CannotCompileException {
if (!desc.equals("J"))
throw new CannotCompileException("type mismatch");
}
@Override
int compile(CtClass type, String name, Bytecode code,
CtClass[] parameters, Javac drv)
throws CannotCompileException
......@@ -1233,6 +1267,7 @@ public class CtField extends CtMember {
return 3; // stack size
}
@Override
int compileIfStatic(CtClass type, String name, Bytecode code,
Javac drv) throws CannotCompileException
{
......@@ -1241,10 +1276,10 @@ public class CtField extends CtMember {
return 2; // stack size
}
@Override
int getConstantValue(ConstPool cp, CtClass type) {
if (type == CtClass.longType)
return cp.addLongInfo(value);
else
return 0;
}
}
......@@ -1254,11 +1289,13 @@ public class CtField extends CtMember {
FloatInitializer(float v) { value = v; }
@Override
void check(String desc) throws CannotCompileException {
if (!desc.equals("F"))
throw new CannotCompileException("type mismatch");
}
@Override
int compile(CtClass type, String name, Bytecode code,
CtClass[] parameters, Javac drv)
throws CannotCompileException
......@@ -1269,6 +1306,7 @@ public class CtField extends CtMember {
return 3; // stack size
}
@Override
int compileIfStatic(CtClass type, String name, Bytecode code,
Javac drv) throws CannotCompileException
{
......@@ -1277,10 +1315,10 @@ public class CtField extends CtMember {
return 2; // stack size
}
@Override
int getConstantValue(ConstPool cp, CtClass type) {
if (type == CtClass.floatType)
return cp.addFloatInfo(value);
else
return 0;
}
}
......@@ -1290,11 +1328,13 @@ public class CtField extends CtMember {
DoubleInitializer(double v) { value = v; }
@Override
void check(String desc) throws CannotCompileException {
if (!desc.equals("D"))
throw new CannotCompileException("type mismatch");
}
@Override
int compile(CtClass type, String name, Bytecode code,
CtClass[] parameters, Javac drv)
throws CannotCompileException
......@@ -1305,6 +1345,7 @@ public class CtField extends CtMember {
return 3; // stack size
}
@Override
int compileIfStatic(CtClass type, String name, Bytecode code,
Javac drv) throws CannotCompileException
{
......@@ -1313,10 +1354,10 @@ public class CtField extends CtMember {
return 2; // stack size
}
@Override
int getConstantValue(ConstPool cp, CtClass type) {
if (type == CtClass.doubleType)
return cp.addDoubleInfo(value);
else
return 0;
}
}
......@@ -1326,6 +1367,7 @@ public class CtField extends CtMember {
StringInitializer(String v) { value = v; }
@Override
int compile(CtClass type, String name, Bytecode code,
CtClass[] parameters, Javac drv)
throws CannotCompileException
......@@ -1336,6 +1378,7 @@ public class CtField extends CtMember {
return 2; // stack size
}
@Override
int compileIfStatic(CtClass type, String name, Bytecode code,
Javac drv) throws CannotCompileException
{
......@@ -1344,10 +1387,10 @@ public class CtField extends CtMember {
return 1; // stack size
}
@Override
int getConstantValue(ConstPool cp, CtClass type) {
if (type.getName().equals(javaLangString))
return cp.addStringInfo(value);
else
return 0;
}
}
......@@ -1366,6 +1409,7 @@ public class CtField extends CtMember {
code.addAnewarray(type, size);
}
@Override
int compile(CtClass type, String name, Bytecode code,
CtClass[] parameters, Javac drv)
throws CannotCompileException
......@@ -1376,6 +1420,7 @@ public class CtField extends CtMember {
return 2; // stack size
}
@Override
int compileIfStatic(CtClass type, String name, Bytecode code,
Javac drv) throws CannotCompileException
{
......@@ -1391,11 +1436,13 @@ public class CtField extends CtMember {
MultiArrayInitializer(CtClass t, int[] d) { type = t; dim = d; }
@Override
void check(String desc) throws CannotCompileException {
if (desc.charAt(0) != '[')
throw new CannotCompileException("type mismatch");
}
@Override
int compile(CtClass type, String name, Bytecode code,
CtClass[] parameters, Javac drv)
throws CannotCompileException
......@@ -1406,6 +1453,7 @@ public class CtField extends CtMember {
return s + 1; // stack size
}
@Override
int compileIfStatic(CtClass type, String name, Bytecode code,
Javac drv) throws CannotCompileException
{
......