Example #1
0
  /*
   * 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;
  }
Example #2
0
 /*
  * Is invoked by CtClassType.setName() and methods in this class.
  * 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);
   if (clazz == null) {
     if (!childFirstLookup && parent != null) {
       try {
         clazz = parent.get0(classname, true);
       } catch (NotFoundException e) {
       }
       if (clazz != null)
         throw new RuntimeException(classname + " is in a parent ClassPool.  Use the parent.");
     }
   } else if (clazz.isFrozen())
     throw new RuntimeException(classname + ": frozen class (cannot edit)");
 }
Example #3
0
  /**
   * @param useCache false if the cached CtClass must be ignored.
   * @param searchParent false if the parent class pool is not searched.
   * @return null if the class could not be found.
   */
  protected synchronized CtClass get0(String classname, boolean useCache) throws NotFoundException {
    CtClass clazz = null;
    if (useCache) {
      clazz = getCached(classname);
      if (clazz != null) return clazz;
    }

    if (!childFirstLookup && parent != null) {
      clazz = parent.get0(classname, useCache);
      if (clazz != null) return clazz;
    }

    clazz = createCtClass(classname, useCache);
    if (clazz != null) {
      // clazz.getName() != classname if classname is "[L<name>;".
      if (useCache) cacheCtClass(clazz.getName(), clazz, false);

      return clazz;
    }

    if (childFirstLookup && parent != null) clazz = parent.get0(classname, useCache);

    return clazz;
  }