|
Java example source code file (Analyzer.java)
The Analyzer.java Java example source code/* * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.tools.jdeps; import com.sun.tools.classfile.Dependency.Location; import com.sun.tools.jdeps.PlatformClassPath.JDKArchive; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; /** * Dependency Analyzer. */ public class Analyzer { /** * Type of the dependency analysis. Appropriate level of data * will be stored. */ public enum Type { SUMMARY, PACKAGE, CLASS, VERBOSE }; private final Type type; private final Map<Archive, ArchiveDeps> results = new HashMap<>(); private final Map<Location, Archive> map = new HashMap<>(); private final Archive NOT_FOUND = new Archive(JdepsTask.getMessage("artifact.not.found")); /** * Constructs an Analyzer instance. * * @param type Type of the dependency analysis */ public Analyzer(Type type) { this.type = type; } /** * Performs the dependency analysis on the given archives. */ public void run(List<Archive> archives) { // build a map from Location to Archive for (Archive archive: archives) { for (Location l: archive.getClasses()) { if (!map.containsKey(l)) { map.put(l, archive); } else { // duplicated class warning? } } } // traverse and analyze all dependencies for (Archive archive : archives) { ArchiveDeps deps; if (type == Type.CLASS || type == Type.VERBOSE) { deps = new ClassVisitor(archive); } else { deps = new PackageVisitor(archive); } archive.visitDependences(deps); results.put(archive, deps); } } public boolean hasDependences(Archive archive) { if (results.containsKey(archive)) { return results.get(archive).deps.size() > 0; } return false; } public interface Visitor { /** * Visits the source archive to its destination archive of * a recorded dependency. */ void visitArchiveDependence(Archive origin, Archive target, Profile profile); /** * Visits a recorded dependency from origin to target which can be * a fully-qualified classname, a package name, a profile or * archive name depending on the Analyzer's type. */ void visitDependence(String origin, Archive source, String target, Archive archive, Profile profile); } public void visitArchiveDependences(Archive source, Visitor v) { ArchiveDeps r = results.get(source); for (ArchiveDeps.Dep d: r.requireArchives()) { v.visitArchiveDependence(r.archive, d.archive, d.profile); } } public void visitDependences(Archive source, Visitor v) { ArchiveDeps r = results.get(source); for (Map.Entry<String, SortedSet Other Java examples (source code examples)Here is a short list of links related to this Java Analyzer.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.