/**
   * Writes the given word to the given writer, after having adapted it, based on the renamed class
   * names.
   */
  private void writeUpdatedWord(Writer writer, String word) throws IOException {
    if (word.length() > 0) {
      String newWord = word;

      boolean containsDots = word.indexOf('.') >= 0;

      // Replace dots by forward slashes.
      String className =
          containsDots ? word.replace('.', ClassConstants.INTERNAL_PACKAGE_SEPARATOR) : word;

      // Find the class corrsponding to the word.
      Clazz clazz = classPool.getClass(className);
      if (clazz != null) {
        // Update the word if necessary.
        String newClassName = clazz.getName();
        if (!className.equals(newClassName)) {
          // Replace forward slashes by dots.
          newWord =
              containsDots
                  ? newClassName.replace(ClassConstants.INTERNAL_PACKAGE_SEPARATOR, '.')
                  : newClassName;
        }
      }

      writer.write(newWord);
    }
  }
Example #2
0
  public void read(DataEntry dataEntry) throws IOException {
    try {
      // Get the input stream.
      InputStream inputStream = dataEntry.getInputStream();

      // Wrap it into a data input stream.
      DataInputStream dataInputStream = new DataInputStream(inputStream);

      // Create a Clazz representation.
      Clazz clazz;
      if (isLibrary) {
        clazz = new LibraryClass();
        clazz.accept(
            new LibraryClassReader(
                dataInputStream, skipNonPublicLibraryClasses, skipNonPublicLibraryClassMembers));
      } else {
        clazz = new ProgramClass();
        clazz.accept(new ProgramClassReader(dataInputStream));
      }

      // Apply the visitor, if we have a real class.
      String className = clazz.getName();
      if (className != null) {
        if (!dataEntry
                .getName()
                .replace(File.pathSeparatorChar, ClassConstants.PACKAGE_SEPARATOR)
                .equals(className + ClassConstants.CLASS_FILE_EXTENSION)
            && warningPrinter != null) {
          warningPrinter.print(
              className,
              "Warning: class ["
                  + dataEntry.getName()
                  + "] unexpectedly contains class ["
                  + ClassUtil.externalClassName(className)
                  + "]");
        }

        clazz.accept(classVisitor);
      }

      dataEntry.closeInputStream();
    } catch (Exception ex) {
      throw (IOException)
          new IOException(
                  "Can't process class [" + dataEntry.getName() + "] (" + ex.getMessage() + ")")
              .initCause(ex);
    }
  }