@@ -173,38 +173,7 @@ private static boolean allFake(Set<CGNode> nodes, CallGraph callGraph) {
173
173
}
174
174
175
175
public static Set <Entrypoint > findBenchmarkEntryPoints (IClassHierarchy classHierarchy ) {
176
- final Set <Entrypoint > result = new HashSet <>();
177
-
178
- for (IClass klass : classHierarchy )
179
- if (!(isJDKClass (klass ) || isLibraryClass (klass ))) {
180
- boolean isBenchmarkClass = false ;
181
- // iterate over all declared methods
182
- for (com .ibm .wala .classLoader .IMethod method : klass .getDeclaredMethods ()) {
183
- // if method has an annotation
184
- if (!(method instanceof ShrikeCTMethod ))
185
- throw new IllegalArgumentException ("@EntryPoint only works for byte code." );
186
-
187
- for (Annotation annotation : ((ShrikeCTMethod ) method ).getAnnotations ()) {
188
- TypeName annotationName = annotation .getType ().getName ();
189
-
190
- if (isBenchmark (annotationName ) || isBenchmarkSetup (annotationName )) {
191
- addEntryPoint (result , method , classHierarchy );
192
- isBenchmarkClass = true ;
193
- break ;
194
- }
195
- }
196
- }
197
-
198
- if (isBenchmarkClass ) {
199
- // add static initializer.
200
- addEntryPoint (result , klass .getClassInitializer (), classHierarchy );
201
-
202
- // add default ctor.
203
- addEntryPoint (result , klass .getMethod (MethodReference .initSelector ), classHierarchy );
204
- }
205
- }
206
-
207
- return result ;
176
+ return findEntryPoints (classHierarchy , tn -> isBenchmark (tn ) || isBenchmarkSetup (tn ));
208
177
}
209
178
210
179
private static MethodInvocation findCorrespondingMethodInvocation (CompilationUnit unit ,
@@ -265,6 +234,55 @@ public static Set<Entrypoint> findEntryPoints(IClassHierarchy classHierarchy) {
265
234
return result ;
266
235
}
267
236
237
+ /**
238
+ * Find entry points in the given {@link IClassHierarchy} whose annotations
239
+ * satisfy the given {@link Predicate} over annotation {@link TypeName}s.
240
+ * Processing is done on the class declaring the entry point method.
241
+ *
242
+ * @param classHierarchy
243
+ * The {@link IClassHierarchy} to search through.
244
+ * @param predicate
245
+ * The {@link Predicate} to test annotation {@link TypeName}s
246
+ * against.
247
+ * @return A {@link Set} of {@link Entrypoint}s corresponding to methods
248
+ * annotated with annotations satisfying the given predicate over type
249
+ * names.
250
+ */
251
+ public static Set <Entrypoint > findEntryPoints (IClassHierarchy classHierarchy , Predicate <TypeName > predicate ) {
252
+ final Set <Entrypoint > result = new HashSet <>();
253
+
254
+ for (IClass klass : classHierarchy )
255
+ if (!(isJDKClass (klass ) || isLibraryClass (klass ))) {
256
+ boolean isAnnotationClass = false ;
257
+ // iterate over all declared methods
258
+ for (com .ibm .wala .classLoader .IMethod method : klass .getDeclaredMethods ()) {
259
+ // if method has an annotation
260
+ if (!(method instanceof ShrikeCTMethod ))
261
+ throw new IllegalArgumentException ("@EntryPoint only works for byte code." );
262
+
263
+ for (Annotation annotation : ((ShrikeCTMethod ) method ).getAnnotations ()) {
264
+ TypeName annotationName = annotation .getType ().getName ();
265
+
266
+ if (predicate .test (annotationName )) {
267
+ addEntryPoint (result , method , classHierarchy );
268
+ isAnnotationClass = true ;
269
+ break ;
270
+ }
271
+ }
272
+ }
273
+
274
+ if (isAnnotationClass ) {
275
+ // add static initializer.
276
+ addEntryPoint (result , klass .getClassInitializer (), classHierarchy );
277
+
278
+ // add default ctor.
279
+ addEntryPoint (result , klass .getMethod (MethodReference .initSelector ), classHierarchy );
280
+ }
281
+ }
282
+
283
+ return result ;
284
+ }
285
+
268
286
/**
269
287
* Find entry points from a {@link Set} of method signatures. No further
270
288
* processing is done of the class declaring the method.
0 commit comments