src/share/classes/com/sun/tools/jdeps/Archive.java

changeset 2139
defadd528513
parent 1577
88286a36bb34
child 2172
aa91bc6e8480
equal deleted inserted replaced
2138:4d8af6fda907 2139:defadd528513
23 * questions. 23 * questions.
24 */ 24 */
25 package com.sun.tools.jdeps; 25 package com.sun.tools.jdeps;
26 26
27 import com.sun.tools.classfile.Dependency.Location; 27 import com.sun.tools.classfile.Dependency.Location;
28 import java.io.File; 28 import java.nio.file.Path;
29 import java.util.HashMap; 29 import java.util.HashMap;
30 import java.util.HashSet; 30 import java.util.HashSet;
31 import java.util.Map; 31 import java.util.Map;
32 import java.util.Set; 32 import java.util.Set;
33 33
34 /** 34 /**
35 * Represents the source of the class files. 35 * Represents the source of the class files.
36 */ 36 */
37 public class Archive { 37 public class Archive {
38 private final File file; 38 private final Path path;
39 private final String filename; 39 private final String filename;
40 private final ClassFileReader reader; 40 private final ClassFileReader reader;
41 private final Map<Location, Set<Location>> deps 41 private final Map<Location, Set<Location>> deps = new HashMap<>();
42 = new HashMap<Location, Set<Location>>();
43 42
44 public Archive(String name) { 43 public Archive(String name) {
45 this.file = null; 44 this.path = null;
46 this.filename = name; 45 this.filename = name;
47 this.reader = null; 46 this.reader = null;
48 } 47 }
49 48
50 public Archive(File f, ClassFileReader reader) { 49 public Archive(Path p, ClassFileReader reader) {
51 this.file = f; 50 this.path = p;
52 this.filename = f.getName(); 51 this.filename = path.getFileName().toString();
53 this.reader = reader; 52 this.reader = reader;
54 } 53 }
55 54
56 public ClassFileReader reader() { 55 public ClassFileReader reader() {
57 return reader; 56 return reader;
62 } 61 }
63 62
64 public void addClass(Location origin) { 63 public void addClass(Location origin) {
65 Set<Location> set = deps.get(origin); 64 Set<Location> set = deps.get(origin);
66 if (set == null) { 65 if (set == null) {
67 set = new HashSet<Location>(); 66 set = new HashSet<>();
68 deps.put(origin, set); 67 deps.put(origin, set);
69 } 68 }
70 } 69 }
71 public void addClass(Location origin, Location target) { 70 public void addClass(Location origin, Location target) {
72 Set<Location> set = deps.get(origin); 71 Set<Location> set = deps.get(origin);
73 if (set == null) { 72 if (set == null) {
74 set = new HashSet<Location>(); 73 set = new HashSet<>();
75 deps.put(origin, set); 74 deps.put(origin, set);
76 } 75 }
77 set.add(target); 76 set.add(target);
78 } 77 }
79 78
85 } 84 }
86 } 85 }
87 } 86 }
88 87
89 public String toString() { 88 public String toString() {
90 return file != null ? file.getPath() : filename; 89 return path != null ? path.toString() : filename;
91 } 90 }
92 91
93 interface Visitor { 92 interface Visitor {
94 void visit(Location loc); 93 void visit(Location loc);
95 void visit(Location origin, Location target); 94 void visit(Location origin, Location target);

mercurial