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

Tue, 24 Dec 2013 09:17:37 -0800

author
ksrini
date
Tue, 24 Dec 2013 09:17:37 -0800
changeset 2227
998b10c43157
parent 2172
aa91bc6e8480
child 2525
2eb010b6cb22
child 2538
1e39ae45d8ac
permissions
-rw-r--r--

8029230: Update copyright year to match last edit in jdk8 langtools repository for 2013
Reviewed-by: ksrini
Contributed-by: steve.sides@oracle.com

mchung@1472 1 /*
ksrini@2227 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
mchung@1472 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
mchung@1472 4 *
mchung@1472 5 * This code is free software; you can redistribute it and/or modify it
mchung@1472 6 * under the terms of the GNU General Public License version 2 only, as
mchung@1472 7 * published by the Free Software Foundation. Oracle designates this
mchung@1472 8 * particular file as subject to the "Classpath" exception as provided
mchung@1472 9 * by Oracle in the LICENSE file that accompanied this code.
mchung@1472 10 *
mchung@1472 11 * This code is distributed in the hope that it will be useful, but WITHOUT
mchung@1472 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
mchung@1472 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
mchung@1472 14 * version 2 for more details (a copy is included in the LICENSE file that
mchung@1472 15 * accompanied this code).
mchung@1472 16 *
mchung@1472 17 * You should have received a copy of the GNU General Public License version
mchung@1472 18 * 2 along with this work; if not, write to the Free Software Foundation,
mchung@1472 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
mchung@1472 20 *
mchung@1472 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
mchung@1472 22 * or visit www.oracle.com if you need additional information or have any
mchung@1472 23 * questions.
mchung@1472 24 */
mchung@1472 25 package com.sun.tools.jdeps;
mchung@1472 26
mchung@1472 27 import com.sun.tools.classfile.Dependency.Location;
mchung@2139 28 import java.nio.file.Path;
mchung@1472 29 import java.util.HashMap;
mchung@1472 30 import java.util.HashSet;
mchung@1472 31 import java.util.Map;
mchung@1472 32 import java.util.Set;
mchung@1472 33
mchung@1472 34 /**
mchung@1472 35 * Represents the source of the class files.
mchung@1472 36 */
mchung@1472 37 public class Archive {
mchung@2139 38 private final Path path;
mchung@1472 39 private final String filename;
mchung@1472 40 private final ClassFileReader reader;
mchung@2139 41 private final Map<Location, Set<Location>> deps = new HashMap<>();
mchung@1577 42
mchung@1472 43 public Archive(String name) {
mchung@2139 44 this.path = null;
mchung@1472 45 this.filename = name;
mchung@1472 46 this.reader = null;
mchung@1472 47 }
mchung@1472 48
mchung@2139 49 public Archive(Path p, ClassFileReader reader) {
mchung@2139 50 this.path = p;
mchung@2139 51 this.filename = path.getFileName().toString();
mchung@1472 52 this.reader = reader;
mchung@1472 53 }
mchung@1472 54
mchung@1472 55 public ClassFileReader reader() {
mchung@1472 56 return reader;
mchung@1472 57 }
mchung@1472 58
mchung@1472 59 public String getFileName() {
mchung@1472 60 return filename;
mchung@1472 61 }
mchung@1472 62
mchung@1577 63 public void addClass(Location origin) {
mchung@1577 64 Set<Location> set = deps.get(origin);
mchung@1577 65 if (set == null) {
mchung@2139 66 set = new HashSet<>();
mchung@1577 67 deps.put(origin, set);
mchung@1472 68 }
mchung@1472 69 }
mchung@2172 70
mchung@1577 71 public void addClass(Location origin, Location target) {
mchung@1577 72 Set<Location> set = deps.get(origin);
mchung@1577 73 if (set == null) {
mchung@2139 74 set = new HashSet<>();
mchung@1577 75 deps.put(origin, set);
mchung@1577 76 }
mchung@1577 77 set.add(target);
mchung@1472 78 }
mchung@1472 79
mchung@2172 80 public Set<Location> getClasses() {
mchung@2172 81 return deps.keySet();
mchung@2172 82 }
mchung@2172 83
mchung@2172 84 public void visitDependences(Visitor v) {
mchung@1577 85 for (Map.Entry<Location,Set<Location>> e: deps.entrySet()) {
mchung@1577 86 for (Location target : e.getValue()) {
mchung@1577 87 v.visit(e.getKey(), target);
mchung@1472 88 }
mchung@1472 89 }
mchung@1472 90 }
mchung@1472 91
mchung@2172 92 public String getPathName() {
mchung@2139 93 return path != null ? path.toString() : filename;
mchung@1472 94 }
mchung@1472 95
mchung@2172 96 public String toString() {
mchung@2172 97 return filename;
mchung@2172 98 }
mchung@2172 99
mchung@1577 100 interface Visitor {
mchung@1577 101 void visit(Location origin, Location target);
mchung@1472 102 }
mchung@1472 103 }

mercurial