22
33import com .google .common .base .Function ;
44import com .google .common .base .Objects ;
5+ import com .google .common .base .Preconditions ;
56import com .google .common .base .Predicate ;
6- import com .google .common .collect .*;
7- import nl .rug .jbi .jsm .bcel .*;
7+ import com .google .common .collect .FluentIterable ;
8+ import com .google .common .collect .Iterables ;
9+ import com .google .common .collect .Lists ;
10+ import com .google .common .collect .Maps ;
811import nl .rug .jbi .jsm .core .calculator .*;
912import nl .rug .jbi .jsm .core .event .Subscribe ;
1013import nl .rug .jbi .jsm .core .event .UsingProducer ;
1518import java .lang .reflect .InvocationTargetException ;
1619import java .lang .reflect .Method ;
1720import java .lang .reflect .Modifier ;
18- import java .util .*;
21+ import java .util .Collections ;
22+ import java .util .List ;
23+ import java .util .Map ;
24+ import java .util .Set ;
1925
2026import static com .google .common .base .Preconditions .checkArgument ;
2127import static com .google .common .base .Preconditions .checkNotNull ;
3137public class Pipeline {
3238 private final static Logger logger = LogManager .getLogger (Pipeline .class );
3339
34- //This set contains all types of data that get produces for the first CLASS frame.
35- private final static Set <Class > BASE_DATA_CLASSES = Sets .newTreeSet (new Comparator <Class >() {
36- @ Override
37- public int compare (Class o1 , Class o2 ) {
38- return o1 .getName ().compareTo (o2 .getName ());
39- }
40- });
41-
42- static {
43- //Register the basic types produced by the BCELClassVisitor
44- registerNewBaseData (JavaClassDefinition .class );
45- registerNewBaseData (MethodDefinition .class );
46- registerNewBaseData (FieldDefinition .class );
47- registerNewBaseData (ExceptionHandlerDefinition .class );
48- registerNewBaseData (FieldAccessInstr .class );
49- registerNewBaseData (InvokeMethodInstr .class );
50- registerNewBaseData (TypeUseInstruction .class );
51- registerNewBaseData (LocalVariableDefinition .class );
52- }
53-
5440 private final Map <MetricScope , HandlerMap > handlerMaps = Maps .newEnumMap (MetricScope .class );
5541 private final Map <MetricScope , PipelineFrame > frameMap = Maps .newEnumMap (MetricScope .class );
5642 private final Map <Class <? extends ProducerMetric >, ProducerMetric > registeredProducers = Maps .newHashMap ();
5743
58- public Pipeline () {
44+ /**
45+ * Creates a new pipeline-frame execution plan.
46+ *
47+ * @param defaultDataClasses The set of data available in the first frame of the class scope.
48+ */
49+ public Pipeline (final Set <Class > defaultDataClasses ) {
50+ Preconditions .checkNotNull (defaultDataClasses , "The set of default data classes cannot be NULL." );
51+ Preconditions .checkArgument (Iterables .all (defaultDataClasses , new Predicate <Class >() {
52+ @ Override
53+ public boolean apply (Class aClass ) {
54+ return aClass != null ;
55+ }
56+ }), "The set of default data classes cannot contain NULL." );
57+
5958 this .handlerMaps .put (MetricScope .CLASS , new HandlerMap ());
6059 this .handlerMaps .put (MetricScope .PACKAGE , new HandlerMap ());
6160 this .handlerMaps .put (MetricScope .COLLECTION , new HandlerMap ());
6261
63- this .frameMap .put (MetricScope .CLASS , new PipelineFrame (MetricScope .CLASS , BASE_DATA_CLASSES ));
62+ this .frameMap .put (MetricScope .CLASS , new PipelineFrame (MetricScope .CLASS , defaultDataClasses ));
6463 this .frameMap .put (MetricScope .PACKAGE , new PipelineFrame (MetricScope .PACKAGE ));
6564 this .frameMap .put (MetricScope .COLLECTION , new PipelineFrame (MetricScope .COLLECTION ));
6665 }
@@ -71,9 +70,11 @@ public Pipeline() {
7170 * class are created to prevent exceptions related to unknown data-types.
7271 *
7372 * @param dataType The data-type to register within the initial CLASS frame.
73+ * @deprecated Definition moved to class visitor factory, since the set is tied to it.
7474 */
75+ @ Deprecated
7576 public static void registerNewBaseData (final Class dataType ) {
76- Pipeline . BASE_DATA_CLASSES . add ( dataType );
77+ //NOOP
7778 }
7879
7980 private Pair <Class , HandlerExecutor > processMethod (final Method listener , final BaseMetric metric )
0 commit comments