コード例 #1
0
  /**
   * 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);
    }
  }
コード例 #2
0
ファイル: Coverage.java プロジェクト: bosschaert/bnd
  private static Map<MethodDef, List<MethodDef>> buildCatalog(Collection<Clazz> sources)
      throws Exception {
    final Map<MethodDef, List<MethodDef>> catalog =
        new TreeMap<MethodDef, List<MethodDef>>(
            new Comparator<MethodDef>() {
              public int compare(MethodDef a, MethodDef b) {
                return a.getName().compareTo(b.getName());
              }
            });
    for (final Clazz clazz : sources) {
      clazz.parseClassFileWithCollector(
          new ClassDataCollector() {

            @Override
            public boolean classStart(int access, TypeRef name) {
              return clazz.isPublic();
            }

            @Override
            public void method(MethodDef source) {
              if (source.isPublic() || source.isProtected())
                catalog.put(source, new ArrayList<MethodDef>());
            }
          });
    }
    return catalog;
  }
コード例 #3
0
ファイル: ClassReader.java プロジェクト: dweiss/proguard
  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);
    }
  }
コード例 #4
0
ファイル: ClassDataCollectors.java プロジェクト: JSlain/bnd
 public void with(Clazz clazz, ClassDataCollector cd) throws Exception {
   delegates.add(cd);
   try {
     clazz.parseClassFileWithCollector(this);
   } finally {
     delegates.remove(cd);
   }
 }
コード例 #5
0
ファイル: Coverage.java プロジェクト: bosschaert/bnd
  private static void crossRef(
      Collection<Clazz> source, final Map<MethodDef, List<MethodDef>> catalog) throws Exception {
    for (final Clazz clazz : source) {
      clazz.parseClassFileWithCollector(
          new ClassDataCollector() {
            //				MethodDef	source;

            @Override
            public void implementsInterfaces(TypeRef names[]) {
              MethodDef def = clazz.getMethodDef(0, "<implements>", "()V");
              // TODO
              for (TypeRef interfaceName : names) {
                for (Map.Entry<MethodDef, List<MethodDef>> entry : catalog.entrySet()) {
                  String catalogClass = entry.getKey().getContainingClass().getFQN();
                  List<MethodDef> references = entry.getValue();

                  if (catalogClass.equals(interfaceName.getFQN())) {
                    references.add(def);
                  }
                }
              }
            }

            // Method definitions
            @Override
            public void method(MethodDef source) {
              //					this.source = source;
            }

            // TODO need to use different reference method
            //				public void reference(MethodDef reference) {
            //					List<MethodDef> references = catalog.get(reference);
            //					if (references != null) {
            //						references.add(source);
            //					}
            //				}
          });
    }
  }
コード例 #6
0
ファイル: ClassDataCollectors.java プロジェクト: JSlain/bnd
 public void parse(Clazz clazz) throws Exception {
   clazz.parseClassFileWithCollector(this);
 }
コード例 #7
0
  public void load(ClazzInputStream cis, Clazz clazz) throws IOException, ClazzException {
    cis.readU4(); // attribute length

    signature = ((CONSTANT_Utf8_info) clazz.getConstant_pool()[cis.readU2()]).getString();
  }