author | mikael |
Tue, 22 Dec 2015 20:47:40 -0800 | |
changeset 35023 | ee10ca0129b2 |
parent 30846 | 2b3f379840f0 |
child 34752 | 9c262a013456 |
permissions | -rw-r--r-- |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
1 |
/* |
22448
a85fbad9d687
8029230: Update copyright year to match last edit in jdk8 langtools repository for 2013
ksrini
parents:
17284
diff
changeset
|
2 |
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
4 |
* |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
10 |
* |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
15 |
* accompanied this code). |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
16 |
* |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
20 |
* |
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
24 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
25 |
package com.sun.tools.classfile; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
26 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
27 |
import java.util.Deque; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
28 |
import java.util.HashMap; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
29 |
import java.util.HashSet; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
30 |
import java.util.LinkedList; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
31 |
import java.util.List; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
32 |
import java.util.Map; |
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
25874
diff
changeset
|
33 |
import java.util.Objects; |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
34 |
import java.util.Set; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
35 |
import java.util.regex.Pattern; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
36 |
|
14258 | 37 |
import com.sun.tools.classfile.Dependency.Filter; |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
38 |
import com.sun.tools.classfile.Dependency.Finder; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
39 |
import com.sun.tools.classfile.Dependency.Location; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
40 |
import com.sun.tools.classfile.Type.ArrayType; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
41 |
import com.sun.tools.classfile.Type.ClassSigType; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
42 |
import com.sun.tools.classfile.Type.ClassType; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
43 |
import com.sun.tools.classfile.Type.MethodType; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
44 |
import com.sun.tools.classfile.Type.SimpleType; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
45 |
import com.sun.tools.classfile.Type.TypeParamType; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
46 |
import com.sun.tools.classfile.Type.WildcardType; |
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
25874
diff
changeset
|
47 |
|
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
48 |
import static com.sun.tools.classfile.ConstantPool.*; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
49 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
50 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
51 |
* A framework for determining {@link Dependency dependencies} between class files. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
52 |
* |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
53 |
* A {@link Dependency.Finder finder} is used to identify the dependencies of |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
54 |
* individual classes. Some finders may return subtypes of {@code Dependency} to |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
55 |
* further characterize the type of dependency, such as a dependency on a |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
56 |
* method within a class. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
57 |
* |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
58 |
* A {@link Dependency.Filter filter} may be used to restrict the set of |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
59 |
* dependencies found by a finder. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
60 |
* |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
61 |
* Dependencies that are found may be passed to a {@link Dependencies.Recorder |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
62 |
* recorder} so that the dependencies can be stored in a custom data structure. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
63 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
64 |
public class Dependencies { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
65 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
66 |
* Thrown when a class file cannot be found. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
67 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
68 |
public static class ClassFileNotFoundException extends Exception { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
69 |
private static final long serialVersionUID = 3632265927794475048L; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
70 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
71 |
public ClassFileNotFoundException(String className) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
72 |
super(className); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
73 |
this.className = className; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
74 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
75 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
76 |
public ClassFileNotFoundException(String className, Throwable cause) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
77 |
this(className); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
78 |
initCause(cause); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
79 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
80 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
81 |
public final String className; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
82 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
83 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
84 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
85 |
* Thrown when an exception is found processing a class file. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
86 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
87 |
public static class ClassFileError extends Error { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
88 |
private static final long serialVersionUID = 4111110813961313203L; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
89 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
90 |
public ClassFileError(Throwable cause) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
91 |
initCause(cause); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
92 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
93 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
94 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
95 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
96 |
* Service provider interface to locate and read class files. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
97 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
98 |
public interface ClassFileReader { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
99 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
100 |
* Get the ClassFile object for a specified class. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
101 |
* @param className the name of the class to be returned. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
102 |
* @return the ClassFile for the given class |
14259 | 103 |
* @throws Dependencies.ClassFileNotFoundException if the classfile cannot be |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
104 |
* found |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
105 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
106 |
public ClassFile getClassFile(String className) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
107 |
throws ClassFileNotFoundException; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
108 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
109 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
110 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
111 |
* Service provide interface to handle results. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
112 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
113 |
public interface Recorder { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
114 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
115 |
* Record a dependency that has been found. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
116 |
* @param d |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
117 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
118 |
public void addDependency(Dependency d); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
119 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
120 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
121 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
122 |
* Get the default finder used to locate the dependencies for a class. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
123 |
* @return the default finder |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
124 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
125 |
public static Finder getDefaultFinder() { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
126 |
return new APIDependencyFinder(AccessFlags.ACC_PRIVATE); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
127 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
128 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
129 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
130 |
* Get a finder used to locate the API dependencies for a class. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
131 |
* These include the superclass, superinterfaces, and classes referenced in |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
132 |
* the declarations of fields and methods. The fields and methods that |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
133 |
* are checked can be limited according to a specified access. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
134 |
* The access parameter must be one of {@link AccessFlags#ACC_PUBLIC ACC_PUBLIC}, |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
135 |
* {@link AccessFlags#ACC_PRIVATE ACC_PRIVATE}, |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
136 |
* {@link AccessFlags#ACC_PROTECTED ACC_PROTECTED}, or 0 for |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
137 |
* package private access. Members with greater than or equal accessibility |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
138 |
* to that specified will be searched for dependencies. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
139 |
* @param access the access of members to be checked |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
140 |
* @return an API finder |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
141 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
142 |
public static Finder getAPIFinder(int access) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
143 |
return new APIDependencyFinder(access); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
144 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
145 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
146 |
/** |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
147 |
* Get a finder to do class dependency analysis. |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
148 |
* |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
149 |
* @return a Class dependency finder |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
150 |
*/ |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
151 |
public static Finder getClassDependencyFinder() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
152 |
return new ClassDependencyFinder(); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
153 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
154 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
155 |
/** |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
156 |
* Get the finder used to locate the dependencies for a class. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
157 |
* @return the finder |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
158 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
159 |
public Finder getFinder() { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
160 |
if (finder == null) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
161 |
finder = getDefaultFinder(); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
162 |
return finder; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
163 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
164 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
165 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
166 |
* Set the finder used to locate the dependencies for a class. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
167 |
* @param f the finder |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
168 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
169 |
public void setFinder(Finder f) { |
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
25874
diff
changeset
|
170 |
finder = Objects.requireNonNull(f); |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
171 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
172 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
173 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
174 |
* Get the default filter used to determine included when searching |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
175 |
* the transitive closure of all the dependencies. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
176 |
* Unless overridden, the default filter accepts all dependencies. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
177 |
* @return the default filter. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
178 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
179 |
public static Filter getDefaultFilter() { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
180 |
return DefaultFilter.instance(); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
181 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
182 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
183 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
184 |
* Get a filter which uses a regular expression on the target's class name |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
185 |
* to determine if a dependency is of interest. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
186 |
* @param pattern the pattern used to match the target's class name |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
187 |
* @return a filter for matching the target class name with a regular expression |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
188 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
189 |
public static Filter getRegexFilter(Pattern pattern) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
190 |
return new TargetRegexFilter(pattern); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
191 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
192 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
193 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
194 |
* Get a filter which checks the package of a target's class name |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
195 |
* to determine if a dependency is of interest. The filter checks if the |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
196 |
* package of the target's class matches any of a set of given package |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
197 |
* names. The match may optionally match subpackages of the given names as well. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
198 |
* @param packageNames the package names used to match the target's class name |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
199 |
* @param matchSubpackages whether or not to match subpackages as well |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
200 |
* @return a filter for checking the target package name against a list of package names |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
201 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
202 |
public static Filter getPackageFilter(Set<String> packageNames, boolean matchSubpackages) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
203 |
return new TargetPackageFilter(packageNames, matchSubpackages); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
204 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
205 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
206 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
207 |
* Get the filter used to determine the dependencies included when searching |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
208 |
* the transitive closure of all the dependencies. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
209 |
* Unless overridden, the default filter accepts all dependencies. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
210 |
* @return the filter |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
211 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
212 |
public Filter getFilter() { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
213 |
if (filter == null) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
214 |
filter = getDefaultFilter(); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
215 |
return filter; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
216 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
217 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
218 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
219 |
* Set the filter used to determine the dependencies included when searching |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
220 |
* the transitive closure of all the dependencies. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
221 |
* @param f the filter |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
222 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
223 |
public void setFilter(Filter f) { |
29291
076c277565f7
8073550: java* tools: replace obj.getClass hacks with Assert.checkNonNull or Objects.requireNonNull
mcimadamore
parents:
25874
diff
changeset
|
224 |
filter = Objects.requireNonNull(f); |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
225 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
226 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
227 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
228 |
* Find the dependencies of a class, using the current |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
229 |
* {@link Dependencies#getFinder finder} and |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
230 |
* {@link Dependencies#getFilter filter}. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
231 |
* The search may optionally include the transitive closure of all the |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
232 |
* filtered dependencies, by also searching in the classes named in those |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
233 |
* dependencies. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
234 |
* @param classFinder a finder to locate class files |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
235 |
* @param rootClassNames the names of the root classes from which to begin |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
236 |
* searching |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
237 |
* @param transitiveClosure whether or not to also search those classes |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
238 |
* named in any filtered dependencies that are found. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
239 |
* @return the set of dependencies that were found |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
240 |
* @throws ClassFileNotFoundException if a required class file cannot be found |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
241 |
* @throws ClassFileError if an error occurs while processing a class file, |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
242 |
* such as an error in the internal class file structure. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
243 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
244 |
public Set<Dependency> findAllDependencies( |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
245 |
ClassFileReader classFinder, Set<String> rootClassNames, |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
246 |
boolean transitiveClosure) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
247 |
throws ClassFileNotFoundException { |
22163 | 248 |
final Set<Dependency> results = new HashSet<>(); |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
249 |
Recorder r = new Recorder() { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
250 |
public void addDependency(Dependency d) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
251 |
results.add(d); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
252 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
253 |
}; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
254 |
findAllDependencies(classFinder, rootClassNames, transitiveClosure, r); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
255 |
return results; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
256 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
257 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
258 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
259 |
* Find the dependencies of a class, using the current |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
260 |
* {@link Dependencies#getFinder finder} and |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
261 |
* {@link Dependencies#getFilter filter}. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
262 |
* The search may optionally include the transitive closure of all the |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
263 |
* filtered dependencies, by also searching in the classes named in those |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
264 |
* dependencies. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
265 |
* @param classFinder a finder to locate class files |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
266 |
* @param rootClassNames the names of the root classes from which to begin |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
267 |
* searching |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
268 |
* @param transitiveClosure whether or not to also search those classes |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
269 |
* named in any filtered dependencies that are found. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
270 |
* @param recorder a recorder for handling the results |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
271 |
* @throws ClassFileNotFoundException if a required class file cannot be found |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
272 |
* @throws ClassFileError if an error occurs while processing a class file, |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
273 |
* such as an error in the internal class file structure. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
274 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
275 |
public void findAllDependencies( |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
276 |
ClassFileReader classFinder, Set<String> rootClassNames, |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
277 |
boolean transitiveClosure, Recorder recorder) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
278 |
throws ClassFileNotFoundException { |
22163 | 279 |
Set<String> doneClasses = new HashSet<>(); |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
280 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
281 |
getFinder(); // ensure initialized |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
282 |
getFilter(); // ensure initialized |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
283 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
284 |
// Work queue of names of classfiles to be searched. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
285 |
// Entries will be unique, and for classes that do not yet have |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
286 |
// dependencies in the results map. |
22163 | 287 |
Deque<String> deque = new LinkedList<>(rootClassNames); |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
288 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
289 |
String className; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
290 |
while ((className = deque.poll()) != null) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
291 |
assert (!doneClasses.contains(className)); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
292 |
doneClasses.add(className); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
293 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
294 |
ClassFile cf = classFinder.getClassFile(className); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
295 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
296 |
// The following code just applies the filter to the dependencies |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
297 |
// followed for the transitive closure. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
298 |
for (Dependency d: finder.findDependencies(cf)) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
299 |
recorder.addDependency(d); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
300 |
if (transitiveClosure && filter.accepts(d)) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
301 |
String cn = d.getTarget().getClassName(); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
302 |
if (!doneClasses.contains(cn)) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
303 |
deque.add(cn); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
304 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
305 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
306 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
307 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
308 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
309 |
private Filter filter; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
310 |
private Finder finder; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
311 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
312 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
313 |
* A location identifying a class. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
314 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
315 |
static class SimpleLocation implements Location { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
316 |
public SimpleLocation(String name) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
317 |
this.name = name; |
17284
7cae365bf8d5
8013531: Provide a utility class in com.sun.tools.classfile to find field/method references
mchung
parents:
15030
diff
changeset
|
318 |
this.className = name.replace('/', '.'); |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
319 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
320 |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
321 |
public String getName() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
322 |
return name; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
323 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
324 |
|
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
325 |
public String getClassName() { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
326 |
return className; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
327 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
328 |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
329 |
public String getPackageName() { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
330 |
int i = name.lastIndexOf('/'); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
331 |
return (i > 0) ? name.substring(0, i).replace('/', '.') : ""; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
332 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
333 |
|
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
334 |
@Override |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
335 |
public boolean equals(Object other) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
336 |
if (this == other) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
337 |
return true; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
338 |
if (!(other instanceof SimpleLocation)) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
339 |
return false; |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
340 |
return (name.equals(((SimpleLocation) other).name)); |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
341 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
342 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
343 |
@Override |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
344 |
public int hashCode() { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
345 |
return name.hashCode(); |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
346 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
347 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
348 |
@Override |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
349 |
public String toString() { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
350 |
return name; |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
351 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
352 |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
353 |
private String name; |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
354 |
private String className; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
355 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
356 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
357 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
358 |
* A dependency of one class on another. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
359 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
360 |
static class SimpleDependency implements Dependency { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
361 |
public SimpleDependency(Location origin, Location target) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
362 |
this.origin = origin; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
363 |
this.target = target; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
364 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
365 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
366 |
public Location getOrigin() { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
367 |
return origin; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
368 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
369 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
370 |
public Location getTarget() { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
371 |
return target; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
372 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
373 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
374 |
@Override |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
375 |
public boolean equals(Object other) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
376 |
if (this == other) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
377 |
return true; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
378 |
if (!(other instanceof SimpleDependency)) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
379 |
return false; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
380 |
SimpleDependency o = (SimpleDependency) other; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
381 |
return (origin.equals(o.origin) && target.equals(o.target)); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
382 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
383 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
384 |
@Override |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
385 |
public int hashCode() { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
386 |
return origin.hashCode() * 31 + target.hashCode(); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
387 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
388 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
389 |
@Override |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
390 |
public String toString() { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
391 |
return origin + ":" + target; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
392 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
393 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
394 |
private Location origin; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
395 |
private Location target; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
396 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
397 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
398 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
399 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
400 |
* This class accepts all dependencies. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
401 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
402 |
static class DefaultFilter implements Filter { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
403 |
private static DefaultFilter instance; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
404 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
405 |
static DefaultFilter instance() { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
406 |
if (instance == null) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
407 |
instance = new DefaultFilter(); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
408 |
return instance; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
409 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
410 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
411 |
public boolean accepts(Dependency dependency) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
412 |
return true; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
413 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
414 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
415 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
416 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
417 |
* This class accepts those dependencies whose target's class name matches a |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
418 |
* regular expression. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
419 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
420 |
static class TargetRegexFilter implements Filter { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
421 |
TargetRegexFilter(Pattern pattern) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
422 |
this.pattern = pattern; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
423 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
424 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
425 |
public boolean accepts(Dependency dependency) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
426 |
return pattern.matcher(dependency.getTarget().getClassName()).matches(); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
427 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
428 |
|
4550
af96bc3bdfb9
6910317: [classfile] typo and other issues in Dependency classes
jjg
parents:
4549
diff
changeset
|
429 |
private final Pattern pattern; |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
430 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
431 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
432 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
433 |
* This class accepts those dependencies whose class name is in a given |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
434 |
* package. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
435 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
436 |
static class TargetPackageFilter implements Filter { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
437 |
TargetPackageFilter(Set<String> packageNames, boolean matchSubpackages) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
438 |
for (String pn: packageNames) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
439 |
if (pn.length() == 0) // implies null check as well |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
440 |
throw new IllegalArgumentException(); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
441 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
442 |
this.packageNames = packageNames; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
443 |
this.matchSubpackages = matchSubpackages; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
444 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
445 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
446 |
public boolean accepts(Dependency dependency) { |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
447 |
String pn = dependency.getTarget().getPackageName(); |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
448 |
if (packageNames.contains(pn)) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
449 |
return true; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
450 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
451 |
if (matchSubpackages) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
452 |
for (String n: packageNames) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
453 |
if (pn.startsWith(n + ".")) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
454 |
return true; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
455 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
456 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
457 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
458 |
return false; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
459 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
460 |
|
4550
af96bc3bdfb9
6910317: [classfile] typo and other issues in Dependency classes
jjg
parents:
4549
diff
changeset
|
461 |
private final Set<String> packageNames; |
af96bc3bdfb9
6910317: [classfile] typo and other issues in Dependency classes
jjg
parents:
4549
diff
changeset
|
462 |
private final boolean matchSubpackages; |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
463 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
464 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
465 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
466 |
* This class identifies class names directly or indirectly in the constant pool. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
467 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
468 |
static class ClassDependencyFinder extends BasicDependencyFinder { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
469 |
public Iterable<? extends Dependency> findDependencies(ClassFile classfile) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
470 |
Visitor v = new Visitor(classfile); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
471 |
for (CPInfo cpInfo: classfile.constant_pool.entries()) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
472 |
v.scan(cpInfo); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
473 |
} |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
474 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
475 |
v.addClass(classfile.super_class); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
476 |
v.addClasses(classfile.interfaces); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
477 |
v.scan(classfile.attributes); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
478 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
479 |
for (Field f : classfile.fields) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
480 |
v.scan(f.descriptor, f.attributes); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
481 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
482 |
for (Method m : classfile.methods) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
483 |
v.scan(m.descriptor, m.attributes); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
484 |
Exceptions_attribute e = |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
485 |
(Exceptions_attribute)m.attributes.get(Attribute.Exceptions); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
486 |
if (e != null) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
487 |
v.addClasses(e.exception_index_table); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
488 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
489 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
490 |
} catch (ConstantPoolException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
491 |
throw new ClassFileError(e); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
492 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
493 |
|
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
494 |
return v.deps; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
495 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
496 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
497 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
498 |
/** |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
499 |
* This class identifies class names in the signatures of classes, fields, |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
500 |
* and methods in a class. |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
501 |
*/ |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
502 |
static class APIDependencyFinder extends BasicDependencyFinder { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
503 |
APIDependencyFinder(int access) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
504 |
switch (access) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
505 |
case AccessFlags.ACC_PUBLIC: |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
506 |
case AccessFlags.ACC_PROTECTED: |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
507 |
case AccessFlags.ACC_PRIVATE: |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
508 |
case 0: |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
509 |
showAccess = access; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
510 |
break; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
511 |
default: |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
512 |
throw new IllegalArgumentException("invalid access 0x" |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
513 |
+ Integer.toHexString(access)); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
514 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
515 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
516 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
517 |
public Iterable<? extends Dependency> findDependencies(ClassFile classfile) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
518 |
try { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
519 |
Visitor v = new Visitor(classfile); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
520 |
v.addClass(classfile.super_class); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
521 |
v.addClasses(classfile.interfaces); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
522 |
// inner classes? |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
523 |
for (Field f : classfile.fields) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
524 |
if (checkAccess(f.access_flags)) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
525 |
v.scan(f.descriptor, f.attributes); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
526 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
527 |
for (Method m : classfile.methods) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
528 |
if (checkAccess(m.access_flags)) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
529 |
v.scan(m.descriptor, m.attributes); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
530 |
Exceptions_attribute e = |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
531 |
(Exceptions_attribute) m.attributes.get(Attribute.Exceptions); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
532 |
if (e != null) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
533 |
v.addClasses(e.exception_index_table); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
534 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
535 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
536 |
return v.deps; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
537 |
} catch (ConstantPoolException e) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
538 |
throw new ClassFileError(e); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
539 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
540 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
541 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
542 |
boolean checkAccess(AccessFlags flags) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
543 |
// code copied from javap.Options.checkAccess |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
544 |
boolean isPublic = flags.is(AccessFlags.ACC_PUBLIC); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
545 |
boolean isProtected = flags.is(AccessFlags.ACC_PROTECTED); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
546 |
boolean isPrivate = flags.is(AccessFlags.ACC_PRIVATE); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
547 |
boolean isPackage = !(isPublic || isProtected || isPrivate); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
548 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
549 |
if ((showAccess == AccessFlags.ACC_PUBLIC) && (isProtected || isPrivate || isPackage)) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
550 |
return false; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
551 |
else if ((showAccess == AccessFlags.ACC_PROTECTED) && (isPrivate || isPackage)) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
552 |
return false; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
553 |
else if ((showAccess == 0) && (isPrivate)) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
554 |
return false; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
555 |
else |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
556 |
return true; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
557 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
558 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
559 |
private int showAccess; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
560 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
561 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
562 |
static abstract class BasicDependencyFinder implements Finder { |
22163 | 563 |
private Map<String,Location> locations = new HashMap<>(); |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
564 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
565 |
Location getLocation(String className) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
566 |
Location l = locations.get(className); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
567 |
if (l == null) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
568 |
locations.put(className, l = new SimpleLocation(className)); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
569 |
return l; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
570 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
571 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
572 |
class Visitor implements ConstantPool.Visitor<Void,Void>, Type.Visitor<Void, Void> { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
573 |
private ConstantPool constant_pool; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
574 |
private Location origin; |
4550
af96bc3bdfb9
6910317: [classfile] typo and other issues in Dependency classes
jjg
parents:
4549
diff
changeset
|
575 |
Set<Dependency> deps; |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
576 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
577 |
Visitor(ClassFile classFile) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
578 |
try { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
579 |
constant_pool = classFile.constant_pool; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
580 |
origin = getLocation(classFile.getName()); |
22163 | 581 |
deps = new HashSet<>(); |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
582 |
} catch (ConstantPoolException e) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
583 |
throw new ClassFileError(e); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
584 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
585 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
586 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
587 |
void scan(Descriptor d, Attributes attrs) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
588 |
try { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
589 |
scan(new Signature(d.index).getType(constant_pool)); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
590 |
scan(attrs); |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
591 |
} catch (ConstantPoolException e) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
592 |
throw new ClassFileError(e); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
593 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
594 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
595 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
596 |
void scan(CPInfo cpInfo) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
597 |
cpInfo.accept(this, null); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
598 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
599 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
600 |
void scan(Type t) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
601 |
t.accept(this, null); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
602 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
603 |
|
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
604 |
void scan(Attributes attrs) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
605 |
try { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
606 |
Signature_attribute sa = (Signature_attribute)attrs.get(Attribute.Signature); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
607 |
if (sa != null) |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
608 |
scan(sa.getParsedSignature().getType(constant_pool)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
609 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
610 |
scan((RuntimeVisibleAnnotations_attribute) |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
611 |
attrs.get(Attribute.RuntimeVisibleAnnotations)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
612 |
scan((RuntimeVisibleParameterAnnotations_attribute) |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
613 |
attrs.get(Attribute.RuntimeVisibleParameterAnnotations)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
614 |
} catch (ConstantPoolException e) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
615 |
throw new ClassFileError(e); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
616 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
617 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
618 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
619 |
private void scan(RuntimeAnnotations_attribute attr) throws ConstantPoolException { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
620 |
if (attr == null) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
621 |
return; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
622 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
623 |
for (int i = 0; i < attr.annotations.length; i++) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
624 |
int index = attr.annotations[i].type_index; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
625 |
scan(new Signature(index).getType(constant_pool)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
626 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
627 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
628 |
|
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
629 |
private void scan(RuntimeParameterAnnotations_attribute attr) throws ConstantPoolException { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
630 |
if (attr == null) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
631 |
return; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
632 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
633 |
for (int param = 0; param < attr.parameter_annotations.length; param++) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
634 |
for (int i = 0; i < attr.parameter_annotations[param].length; i++) { |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
635 |
int index = attr.parameter_annotations[param][i].type_index; |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
636 |
scan(new Signature(index).getType(constant_pool)); |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
637 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
638 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
639 |
} |
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
640 |
|
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
641 |
void addClass(int index) throws ConstantPoolException { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
642 |
if (index != 0) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
643 |
String name = constant_pool.getClassInfo(index).getBaseName(); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
644 |
if (name != null) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
645 |
addDependency(name); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
646 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
647 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
648 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
649 |
void addClasses(int[] indices) throws ConstantPoolException { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
650 |
for (int i: indices) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
651 |
addClass(i); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
652 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
653 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
654 |
private void addDependency(String name) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
655 |
deps.add(new SimpleDependency(origin, getLocation(name))); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
656 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
657 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
658 |
// ConstantPool.Visitor methods |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
659 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
660 |
public Void visitClass(CONSTANT_Class_info info, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
661 |
try { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
662 |
if (info.getName().startsWith("[")) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
663 |
new Signature(info.name_index).getType(constant_pool).accept(this, null); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
664 |
else |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
665 |
addDependency(info.getBaseName()); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
666 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
667 |
} catch (ConstantPoolException e) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
668 |
throw new ClassFileError(e); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
669 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
670 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
671 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
672 |
public Void visitDouble(CONSTANT_Double_info info, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
673 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
674 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
675 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
676 |
public Void visitFieldref(CONSTANT_Fieldref_info info, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
677 |
return visitRef(info, p); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
678 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
679 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
680 |
public Void visitFloat(CONSTANT_Float_info info, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
681 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
682 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
683 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
684 |
public Void visitInteger(CONSTANT_Integer_info info, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
685 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
686 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
687 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
688 |
public Void visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
689 |
return visitRef(info, p); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
690 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
691 |
|
8042 | 692 |
public Void visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Void p) { |
693 |
return null; |
|
694 |
} |
|
695 |
||
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
696 |
public Void visitLong(CONSTANT_Long_info info, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
697 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
698 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
699 |
|
8042 | 700 |
public Void visitMethodHandle(CONSTANT_MethodHandle_info info, Void p) { |
701 |
return null; |
|
702 |
} |
|
703 |
||
704 |
public Void visitMethodType(CONSTANT_MethodType_info info, Void p) { |
|
705 |
return null; |
|
706 |
} |
|
707 |
||
708 |
public Void visitMethodref(CONSTANT_Methodref_info info, Void p) { |
|
709 |
return visitRef(info, p); |
|
710 |
} |
|
711 |
||
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
712 |
public Void visitNameAndType(CONSTANT_NameAndType_info info, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
713 |
try { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
714 |
new Signature(info.type_index).getType(constant_pool).accept(this, null); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
715 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
716 |
} catch (ConstantPoolException e) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
717 |
throw new ClassFileError(e); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
718 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
719 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
720 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
721 |
public Void visitString(CONSTANT_String_info info, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
722 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
723 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
724 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
725 |
public Void visitUtf8(CONSTANT_Utf8_info info, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
726 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
727 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
728 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
729 |
private Void visitRef(CPRefInfo info, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
730 |
try { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
731 |
visitClass(info.getClassInfo(), p); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
732 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
733 |
} catch (ConstantPoolException e) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
734 |
throw new ClassFileError(e); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
735 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
736 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
737 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
738 |
// Type.Visitor methods |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
739 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
740 |
private void findDependencies(Type t) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
741 |
if (t != null) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
742 |
t.accept(this, null); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
743 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
744 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
745 |
private void findDependencies(List<? extends Type> ts) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
746 |
if (ts != null) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
747 |
for (Type t: ts) |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
748 |
t.accept(this, null); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
749 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
750 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
751 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
752 |
public Void visitSimpleType(SimpleType type, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
753 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
754 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
755 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
756 |
public Void visitArrayType(ArrayType type, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
757 |
findDependencies(type.elemType); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
758 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
759 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
760 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
761 |
public Void visitMethodType(MethodType type, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
762 |
findDependencies(type.paramTypes); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
763 |
findDependencies(type.returnType); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
764 |
findDependencies(type.throwsTypes); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
765 |
findDependencies(type.typeParamTypes); |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
766 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
767 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
768 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
769 |
public Void visitClassSigType(ClassSigType type, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
770 |
findDependencies(type.superclassType); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
771 |
findDependencies(type.superinterfaceTypes); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
772 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
773 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
774 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
775 |
public Void visitClassType(ClassType type, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
776 |
findDependencies(type.outerType); |
15030
2d8dec41f029
8003562: Provide a CLI tool to analyze class dependencies
mchung
parents:
14259
diff
changeset
|
777 |
addDependency(type.getBinaryName()); |
4549
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
778 |
findDependencies(type.typeArgs); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
779 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
780 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
781 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
782 |
public Void visitTypeParamType(TypeParamType type, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
783 |
findDependencies(type.classBound); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
784 |
findDependencies(type.interfaceBounds); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
785 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
786 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
787 |
|
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
788 |
public Void visitWildcardType(WildcardType type, Void p) { |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
789 |
findDependencies(type.boundType); |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
790 |
return null; |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
791 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
792 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
793 |
} |
5288a060c75e
6907575: [classfile] add support for classfile dependency analysis
jjg
parents:
diff
changeset
|
794 |
} |