Browse Source

implemented ClassPool.makeClassIfNew()


git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@457 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
tags/rel_3_17_1_ga
chiba 15 years ago
parent
commit
1144f6066c
4 changed files with 57 additions and 2 deletions
  1. 1
    0
      Readme.html
  2. 1
    1
      src/main/META-INF/MANIFEST.MF
  3. 54
    0
      src/main/javassist/ClassPool.java
  4. 1
    1
      src/main/javassist/CtClass.java

+ 1
- 0
Readme.html View File

@@ -283,6 +283,7 @@ see javassist.Dump.

<p>-version 3.9
<ul>
<li>ClassPool.makeClassIfNew(InputStream) was implemented.
<li>CtNewMethod.wrapped(..) and CtNewConstructor.wrapped(..)
implicitly append a method like _added_m$0.
This method now has a synthetic attribute.

+ 1
- 1
src/main/META-INF/MANIFEST.MF View File

@@ -2,7 +2,7 @@ Manifest-Version: 1.1
Specification-Title: Javassist
Created-By: Shigeru Chiba, Tokyo Institute of Technology
Specification-Vendor: Shigeru Chiba, Tokyo Institute of Technology
Specification-Version: 3.8.1.GA
Specification-Version: 3.9.0.GA
Main-Class: javassist.CtClass

Name: javassist/

+ 54
- 0
src/main/javassist/ClassPool.java View File

@@ -547,6 +547,8 @@ public class ClassPool {
* This method throws an exception if the class is already frozen or
* if this class pool cannot edit the class since it is in a parent
* class pool.
*
* @see checkNotExists(String)
*/
void checkNotFrozen(String classname) throws RuntimeException {
CtClass clazz = getCached(classname);
@@ -567,6 +569,25 @@ public class ClassPool {
+ ": frozen class (cannot edit)");
}

/*
* This method returns null if this or its parent class pool does
* not contain a CtClass object with the class name.
*
* @see checkNotFrozen(String)
*/
CtClass checkNotExists(String classname) {
CtClass clazz = getCached(classname);
if (clazz == null)
if (!childFirstLookup && parent != null) {
try {
clazz = parent.get0(classname, true);
}
catch (NotFoundException e) {}
}

return clazz;
}

/* for CtClassType.getClassFile2(). Don't delegate to the parent.
*/
InputStream openClassfile(String classname) throws NotFoundException {
@@ -628,6 +649,7 @@ public class ClassPool {
* @param classfile class file.
* @throws RuntimeException if there is a frozen class with the
* the same name.
* @see #makeClassIfNew(InputStream)
* @see javassist.ByteArrayClassPath
*/
public CtClass makeClass(InputStream classfile)
@@ -665,6 +687,38 @@ public class ClassPool {
return clazz;
}

/**
* Creates a new class (or interface) from the given class file.
* If there already exists a class with the same name, this method
* returns the existing class; a new class is never created from
* the given class file.
*
* <p>This method is used for creating a <code>CtClass</code> object
* directly from a class file. The qualified class name is obtained
* from the class file; you do not have to explicitly give the name.
*
* @param classfile the class file.
* @see #makeClass(InputStream)
* @see javassist.ByteArrayClassPath
* @since 3.9
*/
public CtClass makeClassIfNew(InputStream classfile)
throws IOException, RuntimeException
{
compress();
classfile = new BufferedInputStream(classfile);
CtClass clazz = new CtClassType(classfile, this);
clazz.checkModify();
String classname = clazz.getName();
CtClass found = checkNotExists(classname);
if (found != null)
return found;
else {
cacheCtClass(classname, clazz, true);
return clazz;
}
}

/**
* Creates a new public class.
* If there already exists a class with the same name, the new class

+ 1
- 1
src/main/javassist/CtClass.java View File

@@ -52,7 +52,7 @@ public abstract class CtClass {
/**
* The version number of this release.
*/
public static final String version = "3.8.1.GA";
public static final String version = "3.9.0.GA";

/**
* Prints the version number and the copyright notice.

Loading…
Cancel
Save