langtools/src/share/classes/com/sun/tools/classfile/Dependencies.java
changeset 22163 3651128c74eb
parent 17284 7cae365bf8d5
child 22449 1fd6d4bec7dd
equal deleted inserted replaced
22162:3b3e23e67329 22163:3651128c74eb
   243      */
   243      */
   244     public Set<Dependency> findAllDependencies(
   244     public Set<Dependency> findAllDependencies(
   245             ClassFileReader classFinder, Set<String> rootClassNames,
   245             ClassFileReader classFinder, Set<String> rootClassNames,
   246             boolean transitiveClosure)
   246             boolean transitiveClosure)
   247             throws ClassFileNotFoundException {
   247             throws ClassFileNotFoundException {
   248         final Set<Dependency> results = new HashSet<Dependency>();
   248         final Set<Dependency> results = new HashSet<>();
   249         Recorder r = new Recorder() {
   249         Recorder r = new Recorder() {
   250             public void addDependency(Dependency d) {
   250             public void addDependency(Dependency d) {
   251                 results.add(d);
   251                 results.add(d);
   252             }
   252             }
   253         };
   253         };
   274      */
   274      */
   275     public void findAllDependencies(
   275     public void findAllDependencies(
   276             ClassFileReader classFinder, Set<String> rootClassNames,
   276             ClassFileReader classFinder, Set<String> rootClassNames,
   277             boolean transitiveClosure, Recorder recorder)
   277             boolean transitiveClosure, Recorder recorder)
   278             throws ClassFileNotFoundException {
   278             throws ClassFileNotFoundException {
   279         Set<String> doneClasses = new HashSet<String>();
   279         Set<String> doneClasses = new HashSet<>();
   280 
   280 
   281         getFinder();  // ensure initialized
   281         getFinder();  // ensure initialized
   282         getFilter();  // ensure initialized
   282         getFilter();  // ensure initialized
   283 
   283 
   284         // Work queue of names of classfiles to be searched.
   284         // Work queue of names of classfiles to be searched.
   285         // Entries will be unique, and for classes that do not yet have
   285         // Entries will be unique, and for classes that do not yet have
   286         // dependencies in the results map.
   286         // dependencies in the results map.
   287         Deque<String> deque = new LinkedList<String>(rootClassNames);
   287         Deque<String> deque = new LinkedList<>(rootClassNames);
   288 
   288 
   289         String className;
   289         String className;
   290         while ((className = deque.poll()) != null) {
   290         while ((className = deque.poll()) != null) {
   291             assert (!doneClasses.contains(className));
   291             assert (!doneClasses.contains(className));
   292             doneClasses.add(className);
   292             doneClasses.add(className);
   558 
   558 
   559         private int showAccess;
   559         private int showAccess;
   560     }
   560     }
   561 
   561 
   562     static abstract class BasicDependencyFinder implements Finder {
   562     static abstract class BasicDependencyFinder implements Finder {
   563         private Map<String,Location> locations = new HashMap<String,Location>();
   563         private Map<String,Location> locations = new HashMap<>();
   564 
   564 
   565         Location getLocation(String className) {
   565         Location getLocation(String className) {
   566             Location l = locations.get(className);
   566             Location l = locations.get(className);
   567             if (l == null)
   567             if (l == null)
   568                 locations.put(className, l = new SimpleLocation(className));
   568                 locations.put(className, l = new SimpleLocation(className));
   576 
   576 
   577             Visitor(ClassFile classFile) {
   577             Visitor(ClassFile classFile) {
   578                 try {
   578                 try {
   579                     constant_pool = classFile.constant_pool;
   579                     constant_pool = classFile.constant_pool;
   580                     origin = getLocation(classFile.getName());
   580                     origin = getLocation(classFile.getName());
   581                     deps = new HashSet<Dependency>();
   581                     deps = new HashSet<>();
   582                 } catch (ConstantPoolException e) {
   582                 } catch (ConstantPoolException e) {
   583                     throw new ClassFileError(e);
   583                     throw new ClassFileError(e);
   584                 }
   584                 }
   585             }
   585             }
   586 
   586