Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/src/share/classes/com/sun/tools/jdeps/Archive.java
38899 views
/*1* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package com.sun.tools.jdeps;2526import com.sun.tools.classfile.Dependency.Location;2728import java.io.IOException;29import java.nio.file.Path;30import java.util.HashSet;31import java.util.Map;32import java.util.Set;33import java.util.concurrent.ConcurrentHashMap;3435/**36* Represents the source of the class files.37*/38public class Archive {39public static Archive getInstance(Path p) throws IOException {40return new Archive(p, ClassFileReader.newInstance(p));41}4243private final Path path;44private final String filename;45private final ClassFileReader reader;46protected Map<Location, Set<Location>> deps = new ConcurrentHashMap<>();4748protected Archive(String name) {49this.path = null;50this.filename = name;51this.reader = null;52}5354protected Archive(Path p, ClassFileReader reader) {55this.path = p;56this.filename = path.getFileName().toString();57this.reader = reader;58}5960public ClassFileReader reader() {61return reader;62}6364public String getName() {65return filename;66}6768public void addClass(Location origin) {69Set<Location> set = deps.get(origin);70if (set == null) {71set = new HashSet<>();72deps.put(origin, set);73}74}7576public void addClass(Location origin, Location target) {77Set<Location> set = deps.get(origin);78if (set == null) {79set = new HashSet<>();80deps.put(origin, set);81}82set.add(target);83}8485public Set<Location> getClasses() {86return deps.keySet();87}8889public void visitDependences(Visitor v) {90for (Map.Entry<Location,Set<Location>> e: deps.entrySet()) {91for (Location target : e.getValue()) {92v.visit(e.getKey(), target);93}94}95}9697public boolean isEmpty() {98return getClasses().isEmpty();99}100101public String getPathName() {102return path != null ? path.toString() : filename;103}104105public String toString() {106return filename;107}108109interface Visitor {110void visit(Location origin, Location target);111}112}113114115