mchung@1472: /* mchung@1472: * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. mchung@1472: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. mchung@1472: * mchung@1472: * This code is free software; you can redistribute it and/or modify it mchung@1472: * under the terms of the GNU General Public License version 2 only, as mchung@1472: * published by the Free Software Foundation. Oracle designates this mchung@1472: * particular file as subject to the "Classpath" exception as provided mchung@1472: * by Oracle in the LICENSE file that accompanied this code. mchung@1472: * mchung@1472: * This code is distributed in the hope that it will be useful, but WITHOUT mchung@1472: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or mchung@1472: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License mchung@1472: * version 2 for more details (a copy is included in the LICENSE file that mchung@1472: * accompanied this code). mchung@1472: * mchung@1472: * You should have received a copy of the GNU General Public License version mchung@1472: * 2 along with this work; if not, write to the Free Software Foundation, mchung@1472: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. mchung@1472: * mchung@1472: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA mchung@1472: * or visit www.oracle.com if you need additional information or have any mchung@1472: * questions. mchung@1472: */ mchung@1472: package com.sun.tools.jdeps; mchung@1472: mchung@1472: import com.sun.tools.classfile.Dependency.Location; mchung@1472: import java.io.File; mchung@1472: import java.util.HashMap; mchung@1472: import java.util.HashSet; mchung@1472: import java.util.Map; mchung@1472: import java.util.Set; mchung@1472: mchung@1472: /** mchung@1472: * Represents the source of the class files. mchung@1472: */ mchung@1472: public class Archive { mchung@1472: private final File file; mchung@1472: private final String filename; mchung@1472: private final ClassFileReader reader; mchung@1577: private final Map> deps mchung@1577: = new HashMap>(); mchung@1577: mchung@1472: public Archive(String name) { mchung@1472: this.file = null; mchung@1472: this.filename = name; mchung@1472: this.reader = null; mchung@1472: } mchung@1472: mchung@1472: public Archive(File f, ClassFileReader reader) { mchung@1472: this.file = f; mchung@1472: this.filename = f.getName(); mchung@1472: this.reader = reader; mchung@1472: } mchung@1472: mchung@1472: public ClassFileReader reader() { mchung@1472: return reader; mchung@1472: } mchung@1472: mchung@1472: public String getFileName() { mchung@1472: return filename; mchung@1472: } mchung@1472: mchung@1577: public void addClass(Location origin) { mchung@1577: Set set = deps.get(origin); mchung@1577: if (set == null) { mchung@1577: set = new HashSet(); mchung@1577: deps.put(origin, set); mchung@1472: } mchung@1472: } mchung@1577: public void addClass(Location origin, Location target) { mchung@1577: Set set = deps.get(origin); mchung@1577: if (set == null) { mchung@1577: set = new HashSet(); mchung@1577: deps.put(origin, set); mchung@1577: } mchung@1577: set.add(target); mchung@1472: } mchung@1472: mchung@1577: public void visit(Visitor v) { mchung@1577: for (Map.Entry> e: deps.entrySet()) { mchung@1577: v.visit(e.getKey()); mchung@1577: for (Location target : e.getValue()) { mchung@1577: v.visit(e.getKey(), target); mchung@1472: } mchung@1472: } mchung@1472: } mchung@1472: mchung@1472: public String toString() { mchung@1472: return file != null ? file.getPath() : filename; mchung@1472: } mchung@1472: mchung@1577: interface Visitor { mchung@1577: void visit(Location loc); mchung@1577: void visit(Location origin, Location target); mchung@1472: } mchung@1472: }