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

Tue, 17 Sep 2013 14:17:13 -0700

author
jjg
date
Tue, 17 Sep 2013 14:17:13 -0700
changeset 2033
fdfbc5f0c4ed
parent 1577
88286a36bb34
child 2139
defadd528513
permissions
-rw-r--r--

8024538: -Xdoclint + -Xprefer:source + incremental compilation == FAIL
Reviewed-by: darcy

mchung@1472 1 /*
mchung@1472 2 * Copyright (c) 2012, 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@1472 28 import java.io.File;
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@1472 38 private final File file;
mchung@1472 39 private final String filename;
mchung@1472 40 private final ClassFileReader reader;
mchung@1577 41 private final Map<Location, Set<Location>> deps
mchung@1577 42 = new HashMap<Location, Set<Location>>();
mchung@1577 43
mchung@1472 44 public Archive(String name) {
mchung@1472 45 this.file = null;
mchung@1472 46 this.filename = name;
mchung@1472 47 this.reader = null;
mchung@1472 48 }
mchung@1472 49
mchung@1472 50 public Archive(File f, ClassFileReader reader) {
mchung@1472 51 this.file = f;
mchung@1472 52 this.filename = f.getName();
mchung@1472 53 this.reader = reader;
mchung@1472 54 }
mchung@1472 55
mchung@1472 56 public ClassFileReader reader() {
mchung@1472 57 return reader;
mchung@1472 58 }
mchung@1472 59
mchung@1472 60 public String getFileName() {
mchung@1472 61 return filename;
mchung@1472 62 }
mchung@1472 63
mchung@1577 64 public void addClass(Location origin) {
mchung@1577 65 Set<Location> set = deps.get(origin);
mchung@1577 66 if (set == null) {
mchung@1577 67 set = new HashSet<Location>();
mchung@1577 68 deps.put(origin, set);
mchung@1472 69 }
mchung@1472 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@1577 74 set = new HashSet<Location>();
mchung@1577 75 deps.put(origin, set);
mchung@1577 76 }
mchung@1577 77 set.add(target);
mchung@1472 78 }
mchung@1472 79
mchung@1577 80 public void visit(Visitor v) {
mchung@1577 81 for (Map.Entry<Location,Set<Location>> e: deps.entrySet()) {
mchung@1577 82 v.visit(e.getKey());
mchung@1577 83 for (Location target : e.getValue()) {
mchung@1577 84 v.visit(e.getKey(), target);
mchung@1472 85 }
mchung@1472 86 }
mchung@1472 87 }
mchung@1472 88
mchung@1472 89 public String toString() {
mchung@1472 90 return file != null ? file.getPath() : filename;
mchung@1472 91 }
mchung@1472 92
mchung@1577 93 interface Visitor {
mchung@1577 94 void visit(Location loc);
mchung@1577 95 void visit(Location origin, Location target);
mchung@1472 96 }
mchung@1472 97 }

mercurial