Beispiel #1
0
 /**
  * Creates a new public interface. If there already exists a class/interface with the same name,
  * the new interface overwrites that previous one.
  *
  * @param name a fully-qualified interface name.
  * @param superclass the super interface.
  * @throws RuntimeException if the existing interface is frozen.
  */
 public synchronized CtClass makeInterface(String name, CtClass superclass)
     throws RuntimeException {
   checkNotFrozen(name);
   CtClass clazz = new CtNewClass(name, this, true, superclass);
   cacheCtClass(name, clazz, true);
   return clazz;
 }
Beispiel #2
0
 /**
  * Creates a new public class. If there already exists a class/interface with the same name, the
  * new class overwrites that previous class.
  *
  * <p>If no constructor is explicitly added to the created new class, Javassist generates
  * constructors and adds it when the class file is generated. It generates a new constructor for
  * each constructor of the super class. The new constructor takes the same set of parameters and
  * invokes the corresponding constructor of the super class. All the received parameters are
  * passed to it.
  *
  * @param classname a fully-qualified class name.
  * @param superclass the super class.
  * @throws RuntimeException if the existing class is frozen.
  */
 public synchronized CtClass makeClass(String classname, CtClass superclass)
     throws RuntimeException {
   checkNotFrozen(classname);
   CtClass clazz = new CtNewClass(classname, this, false, superclass);
   cacheCtClass(classname, clazz, true);
   return clazz;
 }
Beispiel #3
0
  /*
   * This method is invoked by CtClassType.setName().  It removes a
   * CtClass object from the hash table and inserts it with the new
   * name.  Don't delegate to the parent.
   */
  synchronized void classNameChanged(String oldname, CtClass clazz) {
    CtClass c = (CtClass) getCached(oldname);
    if (c == clazz) // must check this equation.
    removeCached(oldname); // see getAndRename().

    String newName = clazz.getName();
    checkNotFrozen(newName);
    cacheCtClass(newName, clazz, false);
  }
Beispiel #4
0
  /**
   * Creates a new class (or interface) from the given class file. If there already exists a class
   * with the same name, the new class overwrites that previous class.
   *
   * <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 class file.
   * @param ifNotFrozen throws a RuntimeException if this parameter is true and there is a frozen
   *     class with the same name.
   * @see javassist.ByteArrayClassPath
   */
  public CtClass makeClass(InputStream classfile, boolean ifNotFrozen)
      throws IOException, RuntimeException {
    compress();
    classfile = new BufferedInputStream(classfile);
    CtClass clazz = new CtClassType(classfile, this);
    clazz.checkModify();
    String classname = clazz.getName();
    if (ifNotFrozen) checkNotFrozen(classname);

    cacheCtClass(classname, clazz, true);
    return clazz;
  }
Beispiel #5
0
 /**
  * Creates a new public nested class. This method is called by CtClassType.makeNestedClass().
  *
  * @param classname a fully-qualified class name.
  * @return the nested class.
  */
 synchronized CtClass makeNestedClass(String classname) {
   checkNotFrozen(classname);
   CtClass clazz = new CtNewNestedClass(classname, this, false, null);
   cacheCtClass(classname, clazz, true);
   return clazz;
 }